Kaydet (Commit) 7a5d750c authored tarafından Liu Zhe's avatar Liu Zhe

Set connection retry count to 5, sleep interval to 2 seconds.

üst 4904b17b
...@@ -33,6 +33,8 @@ import java.util.Vector; ...@@ -33,6 +33,8 @@ import java.util.Vector;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.openoffice.test.common.SystemUtil;
/** /**
* Manage the communication with the automation server. * Manage the communication with the automation server.
* It's used to establish the connection, send and receive data package. * It's used to establish the connection, send and receive data package.
...@@ -56,9 +58,9 @@ public class CommunicationManager implements Runnable, Constant{ ...@@ -56,9 +58,9 @@ public class CommunicationManager implements Runnable, Constant{
private Socket socket = null; private Socket socket = null;
private int reconnectInterval = 4000; private double reconnectInterval = 2;
private int reconnectCount = 3; private int reconnectCount = 5;
private List<CommunicationListener> listeners = new Vector<CommunicationListener>(); private List<CommunicationListener> listeners = new Vector<CommunicationListener>();
...@@ -87,39 +89,6 @@ public class CommunicationManager implements Runnable, Constant{ ...@@ -87,39 +89,6 @@ public class CommunicationManager implements Runnable, Constant{
this.port = port; this.port = port;
} }
/**
* Get the max count retrying to connect the server
* @return
*/
public int getReconnectCount() {
return reconnectCount;
}
/**
* Set the max count retrying to connect the server
* @param reconnectCount
*/
public void setReconnectCount(int reconnectCount) {
this.reconnectCount = reconnectCount;
}
/**
* Get the interval between retrying to connect the server
* @return
*/
public int getReconnectInterval() {
return reconnectInterval;
}
/**
* Set the interval between retrying to connect the server
* @param reconnectInterval
*/
public void setReconnectInterval(int reconnectInterval) {
this.reconnectInterval = reconnectInterval;
}
/** /**
* Send a data package to server * Send a data package to server
* @param headerType the package header type * @param headerType the package header type
...@@ -255,14 +224,10 @@ public class CommunicationManager implements Runnable, Constant{ ...@@ -255,14 +224,10 @@ public class CommunicationManager implements Runnable, Constant{
logger.log(Level.FINEST, "Failed to connect! Tried " + i, e); logger.log(Level.FINEST, "Failed to connect! Tried " + i, e);
} }
try { SystemUtil.sleep(reconnectInterval);
Thread.sleep(2000);
} catch (InterruptedException e) {
//ignore
}
} }
throw new CommunicationException("Failed to connect automation server!"); throw new CommunicationException("Failed to connect to automation server on: " + host + ":" + port);
} }
......
...@@ -84,10 +84,13 @@ public class VclApp { ...@@ -84,10 +84,13 @@ public class VclApp {
public void start(boolean isCleanUserInstallation) { // Default to clean user installation public void start(boolean isCleanUserInstallation) { // Default to clean user installation
if (openOffice != null) { if (openOffice != null) {
if (isCleanUserInstallation) { if (isCleanUserInstallation) {
openOffice.kill();
openOffice.cleanUserInstallation(); openOffice.cleanUserInstallation();
openOffice.start();
SystemUtil.sleep(5);
} else {
openOffice.start();
} }
openOffice.start();
} }
communicationManager.start(); communicationManager.start();
......
...@@ -58,10 +58,22 @@ public class UnoApp { ...@@ -58,10 +58,22 @@ public class UnoApp {
private XDesktop desktop = null; private XDesktop desktop = null;
private double reconnectInterval = 2;
private int reconnectCount = 5;
public UnoApp() { public UnoApp() {
this.openOffice = OpenOffice.getDefault(); this.openOffice = OpenOffice.getDefault();
} }
public UnoApp(OpenOffice openOffice) {
this.openOffice = openOffice;
}
public UnoApp(String unoUrl) {
this.unoUrl = unoUrl;
}
/** /**
* Start OpenOffice and connect to it * Start OpenOffice and connect to it
*/ */
...@@ -71,7 +83,7 @@ public class UnoApp { ...@@ -71,7 +83,7 @@ public class UnoApp {
unoUrl = openOffice.getUnoUrl(); unoUrl = openOffice.getUnoUrl();
} }
for (int i = 0; i < 3; i++) { for (int i = 0; i < reconnectCount; i++) {
try { try {
XUnoUrlResolver resolver = UnoUrlResolver.create(Bootstrap.createInitialComponentContext(null)); XUnoUrlResolver resolver = UnoUrlResolver.create(Bootstrap.createInitialComponentContext(null));
componentContext = UnoRuntime.queryInterface(XComponentContext.class, resolver.resolve("uno:" + unoUrl + ";StarOffice.ComponentContext")); componentContext = UnoRuntime.queryInterface(XComponentContext.class, resolver.resolve("uno:" + unoUrl + ";StarOffice.ComponentContext"));
...@@ -83,10 +95,10 @@ public class UnoApp { ...@@ -83,10 +95,10 @@ public class UnoApp {
// e.printStackTrace(); // for debugging // e.printStackTrace(); // for debugging
} }
SystemUtil.sleep(2); SystemUtil.sleep(reconnectInterval);
} }
throw new RuntimeException("OpenOffice can't be connected!"); throw new RuntimeException("Failed to connect to uno url: " + unoUrl);
} }
private Timer timer = new Timer(true); private Timer timer = new Timer(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment