Author: jflesch
Date: 2006-07-25 17:23:42 +0000 (Tue, 25 Jul 2006)
New Revision: 9754

Modified:
   trunk/apps/Thaw/src/thaw/core/Core.java
   trunk/apps/Thaw/src/thaw/core/Logger.java
   trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java
   trunk/apps/Thaw/src/thaw/fcp/FCPQueueLoader.java
Log:
Auto-reconnect is implemented

Modified: trunk/apps/Thaw/src/thaw/core/Core.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Core.java     2006-07-25 16:48:20 UTC (rev 
9753)
+++ trunk/apps/Thaw/src/thaw/core/Core.java     2006-07-25 17:23:42 UTC (rev 
9754)
@@ -32,7 +32,10 @@

        private static String lookAndFeel = null;

+       public final static int MAX_CONNECT_TRIES = 3;
+       public final static int TIME_BETWEEN_EACH_TRY = 2500;

+
        /**
         * Creates a core, but do nothing else (no initialization).
         */
@@ -76,14 +79,12 @@
         * @return true is success, false if not
         */
        public boolean initAll() {
-               if(!initI18n())
-                       return false;
-
                if(!initConfig())
                        return false;

                if(!initNodeConnection())
-                       return false;
+                       new WarningWindow(this, "Unable to connect to 
"+config.getValue("nodeAddress")+":"+
+                                         config.getValue("nodePort"));

                if(!initGraphics())
                        return false;
@@ -99,16 +100,7 @@
        }


-       /** 
-        * Init I18n with default values.
-        */
-       public boolean initI18n() {
-               // Hum, nothing to do ?

-               return true;
-       }
-
-
        /**
         * Init configuration. May re-set I18n.
         */
@@ -145,11 +137,7 @@
                                                       
Integer.parseInt(config.getValue("maxUploadSpeed")));

                        if(!connection.connect()) {
-                               new WarningWindow(this, "Unable to connect to 
"+config.getValue("nodeAddress")+":"+
-                                                 config.getValue("nodePort"));
-                               
-                               /* Not returning false,
-                                  else it will break the loading */
+                               return false;
                        }

                        queryManager = new FCPQueryManager(connection);
@@ -167,8 +155,10 @@
                                clientHello = new FCPClientHello(queryManager, 
config.getValue("thawId"));

                                if(!clientHello.start(null)) {
-                                       new WarningWindow(this, 
I18n.getMessage("thaw.error.idAlreadyUsed"));
+                                       Logger.warning(this, "Id already used 
!");
                                        connection.disconnect();
+                                       new WarningWindow(this, "Unable to 
connect to "+config.getValue("nodeAddress")+":"+config.getValue("nodePort"));
+                                       return false;
                                } else {
                                        Logger.debug(this, "Hello successful");
                                        Logger.debug(this, "Node name    : 
"+clientHello.getNodeName());
@@ -182,8 +172,8 @@
                                        FCPWatchGlobal watchGlobal = new 
FCPWatchGlobal(true);
                                        watchGlobal.start(queueManager);

-                                       FCPQueueLoader queueLoader = new 
FCPQueueLoader();
-                                       queueLoader.start(queueManager, 
config.getValue("thawId"));
+                                       FCPQueueLoader queueLoader = new 
FCPQueueLoader(config.getValue("thawId"));
+                                       queueLoader.start(queueManager);

                                }

@@ -192,7 +182,7 @@
                } catch(Exception e) { /* A little bit not ... "nice" ... */
                        Logger.warning(this, "Exception while connecting : 
"+e.toString()+" ; "+e.getMessage() + " ; "+e.getCause());
                        e.printStackTrace();
-                       new WarningWindow(this, "Unable to connect to the node. 
Please check your configuration.");
+                       return false;
                }

                if(connection.isConnected())
@@ -355,8 +345,28 @@
                Logger.debug(this, "Move on the connection (?)");

                if(o == connection && !connection.isConnected()) {
-                       new WarningWindow(this, "We have been disconnected");
-                       disconnect();
+                       int nmbReconnect = 0;
+
+                       for(nmbReconnect = 0;
+                           nmbReconnect < MAX_CONNECT_TRIES ;
+                           nmbReconnect++) {
+                               
+                               try {
+                                       Thread.sleep(TIME_BETWEEN_EACH_TRY);
+                               } catch(java.lang.InterruptedException e) {
+                                       // brouzouf
+                               }
+                               
+                               Logger.info(this, "Trying to reconnect ... : "+ 
Integer.toString(nmbReconnect));
+
+                               if(initNodeConnection())
+                                       break;
+                       }
+                       
+                       if(nmbReconnect == MAX_CONNECT_TRIES) {
+                               new WarningWindow(this, "We have been 
disconnected");
+                       }
+                       
                }
        }


Modified: trunk/apps/Thaw/src/thaw/core/Logger.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Logger.java   2006-07-25 16:48:20 UTC (rev 
9753)
+++ trunk/apps/Thaw/src/thaw/core/Logger.java   2006-07-25 17:23:42 UTC (rev 
9754)
@@ -94,10 +94,10 @@
         * As it. Similar to verbose()
         */
        public static void asIt(Object o, String msg) {
-               //if(LOG_LEVEL >= 5) {
+               if(LOG_LEVEL >= 5) {
                        System.out.println(msg);
                        notifyLogListeners(msg);
-                       //}
+               }
        }



Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java      2006-07-25 16:48:20 UTC 
(rev 9753)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java      2006-07-25 17:23:42 UTC 
(rev 9754)
@@ -100,13 +100,15 @@
        }

        /**
-        * Used for resuming.
+        * Used for resuming from a PersistentPut.
         * @param publicKey : Complete key (with filename, etc)
         */
        public FCPClientPut(String identifier, String publicKey,
                            int priority, int persistence, boolean global,
-                           String srcFile, String status, int progress,
+                           String filePath, String status, int progress,
                            long fileSize, FCPQueueManager queueManager) {
+               
+
                if(fileSize > 0)
                        this.fileSize = fileSize;

@@ -127,11 +129,12 @@

                this.publicKey = publicKey;

-               if(srcFile != null) {
-                       String[] plop = 
srcFile.split(File.separator.replaceAll("\\\\", "\\\\\\\\"));
+               if(filePath != null && filePath.startsWith("thaw")) {
+
+                       String[] plop = 
filePath.split(File.separator.replaceAll("\\\\", "\\\\\\\\"));
                        this.name = plop[plop.length-1];

-                       this.localFile = new File(srcFile);
+                       this.localFile = new File(filePath);
                        if(this.localFile.length() > 0)
                                this.fileSize = this.localFile.length();


Modified: trunk/apps/Thaw/src/thaw/fcp/FCPQueueLoader.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPQueueLoader.java    2006-07-25 16:48:20 UTC 
(rev 9753)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPQueueLoader.java    2006-07-25 17:23:42 UTC 
(rev 9754)
@@ -10,17 +10,16 @@
  * Send himself the ListPersistentRequests.
  * It remains active to receive and add the persistentGet/Put receive during 
the execution
  */
-public class FCPQueueLoader implements Observer {
-       FCPQueueManager queueManager;
-       String thawId;
+public class FCPQueueLoader implements FCPQuery, Observer {
+       private FCPQueueManager queueManager;
+       private String thawId;

-       public FCPQueueLoader() {
-               
+       public FCPQueueLoader(String thawId) {
+               this.thawId = thawId;
        }

-       public boolean start(FCPQueueManager queueManager, String thawId) {
+       public boolean start(FCPQueueManager queueManager) {
                this.queueManager = queueManager;
-               this.thawId = thawId;

                queueManager.getQueryManager().addObserver(this);

@@ -36,7 +35,7 @@


        public boolean stop(FCPQueueManager queueManager) {
-               /* Ignored */
+               queueManager.getQueryManager().deleteObserver(this);
                return true;
        }

@@ -100,11 +99,6 @@
                        if(msg.getValue("Global").equals("false"))
                                global = false;

-                       String srcFile = null;
-
-                       if(msg.getValue("Identifier").startsWith(thawId))
-                               srcFile = msg.getValue("ClientToken");
-
                        int priority = 
Integer.parseInt(msg.getValue("PriorityClass"));

                        long fileSize = 0;
@@ -112,10 +106,16 @@
                        if(msg.getValue("DataLength") != null)
                                fileSize = 
Long.parseLong(msg.getValue("DataLength"));

+                       String filePath=null;
+
+                       if(msg.getValue("Identifier").startsWith(thawId))
+                               filePath = msg.getValue("ClientToken");
+
                        FCPClientPut clientPut = new 
FCPClientPut(msg.getValue("Identifier"),
                                                                  
msg.getValue("URI"), // key
                                                                  priority, 
persistence, global,
-                                                                 srcFile, 
"Inserting", 0, fileSize,
+                                                                 filePath,
+                                                                 "Inserting", 
0, fileSize,
                                                                  queueManager);




Reply via email to