Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fixing some bugs.
[jaceP2P.git] / src / jaceP2P / SuperNodeListe.java
index fc4a23c..61add0a 100644 (file)
@@ -46,6 +46,9 @@ public class SuperNodeListe implements Cloneable {
        // TODO change to have non-static list
        // using a config file
        // in order to discover new superNodes dynamicaly
+       
+       /* Sébastien Miquée -- ajout de la lecture du fichier de config **/
+       
        @SuppressWarnings("unchecked")
        public void staticInitialization() {
                String adr = "";
@@ -64,7 +67,7 @@ public class SuperNodeListe implements Cloneable {
 
                        br.close();
                } catch (Exception e) {
-                       System.out.println(e.toString());
+                       System.err.println(e.toString());
                }
 
                // String adr1 =
@@ -137,8 +140,8 @@ public class SuperNodeListe implements Cloneable {
                if (is != -1) {
                        ((SuperNodeData) liste.elementAt(is)).setStub(stub);
                } else {
-                       System.out.println("this superNode does not exist : " + snode);
-                       System.out.println("add the new SuperNode");
+                       System.err.println("This superNode does not exist : " + snode);
+                       System.out.println("Add the new SuperNode");
                        SuperNodeData data = new SuperNodeData(snode, port);
                        data.setStub(stub);
                        data.setNbOfNodes(0);
@@ -163,14 +166,14 @@ public class SuperNodeListe implements Cloneable {
                        return null;
                } else {
                        if (superNode == null) {
-                               System.out
+                               System.err
                                                .println("In Register.getNode : host == null !!!!!!!!!!!!!!!");
                        }
                        is = existSuperNode(superNode);
                        if (is != -1) {
                                return ((SuperNodeData) liste.get(is)).getStub();
                        } else {
-                               System.out.println("this superNode does not exist");
+                               System.err.println("This superNode does not exist");
                                return null;
                        }
                }
@@ -178,8 +181,8 @@ public class SuperNodeListe implements Cloneable {
 
        public synchronized int existSuperNode(String snode) {
                if (snode == null) {
-                       System.out
-                                       .println("!!!!!!!!!!!!!!!!!!!!!!!!!   hostIP in existNode = "
+                       System.err
+                                       .println("HostIP in existNode = "
                                                        + snode);
                }
                int existe = -1;
@@ -224,7 +227,7 @@ public class SuperNodeListe implements Cloneable {
                        SuperNodeData d = (SuperNodeData) liste.elementAt(is);
                        d.setNbOfNodes(nb);
                } else {
-                       System.out.println("ce superNode existe pas ds ma liste : " + IP);
+                       System.err.println("This SuperNode does not exists in my list: " + IP);
                }
        }
 
@@ -272,7 +275,7 @@ public class SuperNodeListe implements Cloneable {
                                        System.out.println("size:" + liste.size());
                                        viewAll();
                                } catch (Exception e) {
-                                       System.out.println("SuperNode " + remoteIP
+                                       System.err.println("SuperNode " + remoteIP
                                                        + " is down or not already launched: " + e);
                                }
                        } else
@@ -289,8 +292,8 @@ public class SuperNodeListe implements Cloneable {
                                liste.add(data);
                                TokenThread.Instance().setToken();
                        } else {
-                               System.out
-                                               .println("no superNode alive in the static List, closing application");
+                               System.err
+                                               .println("No superNode alive in the static List, closing application");
                                System.exit(1);
                        }
 
@@ -315,7 +318,7 @@ public class SuperNodeListe implements Cloneable {
                        // System.out.println("je remove le noeud de rang " + i);
                        liste.remove(i);
                } else {
-                       System.out.println("super node existe pas");
+                       System.err.println("The SuperNode does not exists!");
                }
        }
 
@@ -359,7 +362,7 @@ public class SuperNodeListe implements Cloneable {
                                        try {
                                                remoteStub.addGNode( _g ) ;
                                        } catch( Exception e ) {
-                                               System.err.println( "Unable to add new GNode at SuperNode " + d.getIP() ) ;
+                                               System.err.println( "Unable to add new GNode on SuperNode " + d.getIP() ) ;
                                        }
                                }
                        }
@@ -384,12 +387,38 @@ public class SuperNodeListe implements Cloneable {
                                        try {
                                                remoteStub.removeGNode( _g ) ;
                                        } catch( Exception e ) {
-                                               System.err.println( "Unable to remove GNode at SuperNode " + d.getIP() ) ;
+                                               System.err.println( "Unable to remove GNode on SuperNode " + d.getIP() ) ;
                                        }
                                }
                        }
                }
        }
+       
+       
+       protected boolean workingOnGnodes()
+       {
+               boolean ok = true ;     
+               
+               SuperNodeData d = null ;
+               JaceSuperNodeInterface remoteStub = null ;
+
+               for( int i = 0 ; i < liste.size() ; i++ ) 
+               {
+                       d = (SuperNodeData) liste.elementAt( i ) ;
+                       if( ! d.getIP().equals(LocalHost.Instance().getIP() ) ) 
+                       {
+                               // if not me, I inform the other super nodes
+                               remoteStub = d.getStub() ;
+                               try {
+                                       ok = ok && remoteStub.blockForMapping() ;
+                               } catch( Exception e ) {
+                                       System.err.println( "Unable to remove GNode at SuperNode " + d.getIP() ) ;
+                               }
+                       }
+               }
+            
+           return ok ;
+       }
 
        public void setMapping( Algo al ) 
        {