Author: jflesch
Date: 2008-01-26 12:28:57 +0000 (Sat, 26 Jan 2008)
New Revision: 17300
Modified:
trunk/apps/Thaw/src/thaw/core/Core.java
trunk/apps/Thaw/src/thaw/core/MainWindow.java
trunk/apps/Thaw/src/thaw/fcp/FCPClientHello.java
trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java
Log:
Fix reconnection process
Modified: trunk/apps/Thaw/src/thaw/core/Core.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Core.java 2008-01-26 11:58:33 UTC (rev
17299)
+++ trunk/apps/Thaw/src/thaw/core/Core.java 2008-01-26 12:28:57 UTC (rev
17300)
@@ -43,7 +43,7 @@
private String lookAndFeel = null;
public final static int MAX_CONNECT_TRIES = 3;
- public final static int TIME_BETWEEN_EACH_TRY = 5000;
+ public final static int TIME_BETWEEN_EACH_TRY = 20000;
private ReconnectionManager reconnectionManager = null;
@@ -286,49 +286,33 @@
if((connection != null) && connection.isConnected()) {
subDisconnect();
}
-
- if(connection == null) {
- connection = new
FCPConnection(config.getValue("nodeAddress"),
-
Integer.parseInt(config.getValue("nodePort")),
-
Integer.parseInt(config.getValue("maxUploadSpeed")),
-
Boolean.valueOf(config.getValue("multipleSockets")).booleanValue(),
-
Boolean.valueOf(config.getValue("sameComputer")).booleanValue(),
-
Boolean.valueOf(config.getValue("downloadLocally")).booleanValue());
- } else { /* connection is not recreate to avoid
troubles with possible observers etc */
+
+ if (connection != null)
connection.deleteObserver(this);
-
connection.setNodeAddress(config.getValue("nodeAddress"));
-
connection.setNodePort(Integer.parseInt(config.getValue("nodePort")));
-
connection.setMaxUploadSpeed(Integer.parseInt(config.getValue("maxUploadSpeed")));
-
connection.setDuplicationAllowed(Boolean.valueOf(config.getValue("multipleSockets")).booleanValue());
-
connection.setLocalSocket(Boolean.valueOf(config.getValue("sameComputer")).booleanValue());
-
connection.setAutoDownload(Boolean.valueOf(config.getValue("downloadLocally")).booleanValue());
- }
+ connection = new
FCPConnection(config.getValue("nodeAddress"),
+
Integer.parseInt(config.getValue("nodePort")),
+
Integer.parseInt(config.getValue("maxUploadSpeed")),
+
Boolean.valueOf(config.getValue("multipleSockets")).booleanValue(),
+
Boolean.valueOf(config.getValue("sameComputer")).booleanValue(),
+
Boolean.valueOf(config.getValue("downloadLocally")).booleanValue());
+
if(!connection.connect()) {
Logger.warning(this, "Unable to connect !");
ret = false;
}
+
+ if (queryManager != null)
+ queryManager.deleteObserver(this);
- if(queryManager == null) {
- queryManager = new FCPQueryManager(connection);
- queryManager.addObserver(this);
- }
+ queryManager = new FCPQueryManager(connection);
+ queryManager.addObserver(this);
- if(queueManager == null)
- queueManager = new FCPQueueManager(queryManager,
-
config.getValue("thawId"),
-
Integer.parseInt(config.getValue("maxSimultaneousDownloads")),
-
Integer.parseInt(config.getValue("maxSimultaneousInsertions")));
- else {
-
queueManager.setThawId(config.getValue("thawId"));
-
queueManager.setMaxDownloads(Integer.parseInt(config.getValue("maxSimultaneousDownloads")));
-
queueManager.setMaxInsertions(Integer.parseInt(config.getValue("maxSimultaneousInsertions")));
+ queueManager = new FCPQueueManager(queryManager,
+
config.getValue("thawId"),
+
Integer.parseInt(config.getValue("maxSimultaneousDownloads")),
+
Integer.parseInt(config.getValue("maxSimultaneousInsertions")));
- }
-
-
-
-
if(ret && connection.isConnected()) {
queryManager.startListening();
@@ -604,9 +588,11 @@
protected class ReconnectionManager implements ThawRunnable {
private boolean running = true;
+ private boolean initialWait = true;
- public ReconnectionManager() {
+ public ReconnectionManager(boolean initialWait) {
running = true;
+ this.initialWait = initialWait;
}
public void run() {
@@ -623,10 +609,13 @@
while(running) {
try {
-
Thread.sleep(Core.TIME_BETWEEN_EACH_TRY);
+ if (initialWait)
+
Thread.sleep(Core.TIME_BETWEEN_EACH_TRY);
} catch(final
java.lang.InterruptedException e) {
// brouzouf
}
+
+ initialWait = false;
Logger.notice(this, "Trying to
reconnect ...");
if(initConnection())
@@ -644,9 +633,9 @@
if (running) {
getPluginManager().loadAndRunPlugins();
}
-
+
reconnectionManager = null;
-
+
getMainWindow().connectionHasChanged();
}
}
@@ -660,10 +649,10 @@
/**
* use Thread => will also do all the work related to the plugins
*/
- public void reconnect() {
+ public void reconnect(boolean withInitialWait) {
synchronized(this) {
if (reconnectionManager == null) {
- reconnectionManager = new ReconnectionManager();
+ reconnectionManager = new
ReconnectionManager(withInitialWait);
final Thread th = new
ThawThread(reconnectionManager,
"Reconnection
manager", this);
th.start();
@@ -708,7 +697,7 @@
Logger.debug(this, "Move on the connection (?)");
if ((o == connection) && !connection.isConnected()) {
- reconnect();
+ reconnect(true);
}
if ((o == queryManager) && target instanceof FCPMessage) {
Modified: trunk/apps/Thaw/src/thaw/core/MainWindow.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/MainWindow.java 2008-01-26 11:58:33 UTC
(rev 17299)
+++ trunk/apps/Thaw/src/thaw/core/MainWindow.java 2008-01-26 12:28:57 UTC
(rev 17300)
@@ -440,7 +440,7 @@
*/
public void actionPerformed(final ActionEvent e) {
if(e.getSource() == connectButton) {
- core.reconnect();
+ core.reconnect(false);
}
if(e.getSource() == disconnectButton) {
@@ -470,7 +470,7 @@
return;
}
- core.reconnect();
+ core.reconnect(false);
}
if(e.getSource() == optionsFileMenuItem) {
Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientHello.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPClientHello.java 2008-01-26 11:58:33 UTC
(rev 17299)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPClientHello.java 2008-01-26 12:28:57 UTC
(rev 17300)
@@ -96,12 +96,14 @@
if(nodeName != null) {
Logger.info(this, "Hello "+nodeName+", I'm Thaw :)");
+ } else if (count >= (NODEHELLO_TIMEOUT*2)) {
+ Logger.warning(this, "Unable to connect, timeout ...");
+ return false;
} else {
- Logger.warning(this, "Unable to connect, ID is probably
already taken or there was a timeout");
+ Logger.warning(this, "ID already used !");
return false;
}
-
return true;
}
Modified: trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2008-01-26 11:58:33 UTC
(rev 17299)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2008-01-26 12:28:57 UTC
(rev 17300)
@@ -238,9 +238,9 @@
}
/**
- * Should be call by FCPBufferedStream. Not you.
+ * Should be call by FCPBufferedStream.
*/
- public synchronized boolean realRawWrite(final byte[] data) {
+ protected synchronized boolean realRawWrite(final byte[] data) {
if((out != null) && (socket != null) && socket.isConnected()) {
try {
lastWrite = System.currentTimeMillis();
@@ -255,6 +255,12 @@
}
} else {
Logger.notice(this, "Cannot write if disconnected !");
+ if (out == null)
+ Logger.notice(this, "^ no output stream
^");
+ if (socket == null)
+ Logger.notice(this, "^ no socket
^");
+ else if (!socket.isConnected())
+ Logger.notice(this, "^ socket but not connected
^");
return false;
}
@@ -320,6 +326,12 @@
}
} else {
Logger.notice(this, "Cannot write if disconnected !");
+ if (out == null)
+ Logger.notice(this, "^ no output stream
^");
+ if (socket == null)
+ Logger.notice(this, "^ no socket
^");
+ else if (!socket.isConnected())
+ Logger.notice(this, "^ socket but not connected
^");
if (checkLock)
removeFromWriterQueue();
return false;