Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Correction of some bugs and performance enhancement.
[jaceP2P.git] / src / jaceP2P / Register.java
index 680c05d..d599565 100644 (file)
@@ -1,6 +1,7 @@
 package jaceP2P;
 
-import java.util.Vector;
+import java.util.ArrayList;
+
 
 
 public class Register implements java.io.Serializable, java.lang.Cloneable {
@@ -13,7 +14,7 @@ public class Register implements java.io.Serializable, java.lang.Cloneable {
        // attributes
        public static Register Instance;
        private String appliName; // name of the appli
-       private Vector<Node> liste; // list of the nodes of the Register
+       private ArrayList<Node> liste; // list of the nodes of the Register
        // private ListeTask listeOfTasks = null; //liste of the TaskId of the appli
        // private int version=0;
        private String[] params; // params of the appli
@@ -25,7 +26,7 @@ public class Register implements java.io.Serializable, java.lang.Cloneable {
        // constructors
 
        public Register() {
-               liste = new Vector<Node>();
+               liste = new ArrayList<Node>() ;
        }
 
        public synchronized static Register Instance() {
@@ -40,20 +41,27 @@ public class Register implements java.io.Serializable, java.lang.Cloneable {
        }
 
        public synchronized int existNode(Node node) {
-               if (node == null) {
+               if( node == null ) 
+               {
                        System.err
                                        .println("Node est null dans existNode");
                        return -1 ;
                }
+               
                int existe = -1;
                int index = 0;
-               while ((existe == -1) && (index < liste.size())) {
-                       if (node.equals((Node) liste.get(index))) {
-                               existe = index;
-                       } else
-                               index++;
+               
+               while ((existe == -1) && (index < liste.size())) 
+               {
+                       if (node.equals((Node) liste.get(index))) 
+                       {
+                               existe = index ;
+                       } else {
+                               index++ ;
+                       }
                }
-               return existe;
+               
+               return existe ;
        }
 
        /*
@@ -62,26 +70,26 @@ public class Register implements java.io.Serializable, java.lang.Cloneable {
         * public void setVersion(int version){ this.version=version; }
         */
 
-       public synchronized void addNode(Node host) {
-               int is = -1;
-               if (host == null) {
-                       System.err
-                                       .println("In Register.addNode : host.getIP() == null !");
+       public synchronized int addNode( Node host ) 
+       {
+               int is = -1 ;
+               if( host == null ) 
+               {
+                       System.err.println( "In Register.addNode : host == null !" ) ;
+                       return 1 ;
                }
-               is = existNodeOfStub(host.getStub());
+               
+               is = existNodeOfStub( host.getStub() ) ;
+               
                if (is != -1) {
                        System.out.println("This node exists yet, I replace it");
-                       // System.out.println("MERDE !!");
-                       // System.out.println("MERDE !!");
-                       // System.out.println("MERDE !!");
-                       // System.out.println("MERDE !!");
-                       // System.out.println("MERDE !!");
-                       // System.out.println("MERDE !!");
-                       // System.out.println("MERDE !!");
-                       liste.setElementAt(host, is);
+
+                       liste.set( is, host ) ;
                } else {
-                       liste.add(host);
+                       liste.add( host ) ;
                }
+               
+               return 0 ;
        }
 
        /**
@@ -91,12 +99,11 @@ public class Register implements java.io.Serializable, java.lang.Cloneable {
        public synchronized void addNodeBeg(Node host) {
                int is = -1;
                if (host == null) {
-                       System.err
-                                       .println("In Register.addNode : host.getIP() == null !");
+                       System.err.println( "In Register.addNode : host.getIP() == null !" ) ;
                }
-               is = existNodeOfStub(host.getStub());
+               is = existNodeOfStub( host.getStub() ) ;
                if (is != -1) {
-                       System.out.println("This node exists yet, I replace it");
+                       System.out.println( "This node exists yet, I replace it" ) ;
                        // System.out.println("MERDE !!");
                        // System.out.println("MERDE !!");
                        // System.out.println("MERDE !!");
@@ -104,9 +111,9 @@ public class Register implements java.io.Serializable, java.lang.Cloneable {
                        // System.out.println("MERDE !!");
                        // System.out.println("MERDE !!");
                        // System.out.println("MERDE !!");
-                       liste.setElementAt(host, is);
+                       liste.set( is, host ) ;
                } else {
-                       liste.add(0,host);
+                       liste.add( 0, host ) ;
                }
        }
        
@@ -180,31 +187,35 @@ public class Register implements java.io.Serializable, java.lang.Cloneable {
        }
 
        public synchronized boolean removeNode(Node n) {
-               return (liste.remove(n));
+               return ( liste.remove( n ) ) ;
        }
 
-       public synchronized boolean removeNodeOfName(String s) {
-               boolean removed = false;
-               int i = 0;
+       public synchronized boolean removeNodeOfName( String s ) 
+       {
+               boolean removed = false ;
+               int i = 0 ;
                // System.out.println("begin remove");
                // viewAll();
-               while (i < liste.size() && !removed) {
+               while( i < liste.size() && ! removed ) 
+               {
                        // System.out.println("i="+i+" s="+s);
-                       if (((Node) liste.get(i)).getName().equals(s)) {
-                               liste.remove(i);
-                               removed = true;
-                       } else
-                               i++;
+                       if( ((Node) liste.get(i)).getName().equals(s) ) 
+                       {
+                               liste.remove( i ) ;
+                               removed = true ;
+                       } else {
+                               i++ ;
+                       }
                }
                // System.out.println("end remove");
-               return removed;
+               return removed ;
        }
 
        public synchronized int getSize() {
                return liste.size();
        }
 
-       public synchronized Vector<Node> getListe() {
+       public synchronized ArrayList<Node> getListe() {
                return liste;
        }
 
@@ -248,9 +259,9 @@ public class Register implements java.io.Serializable, java.lang.Cloneable {
 
        public synchronized void purge() {
                for (int i = 0; i < liste.size(); i++)
-                       if (((Node) liste.elementAt(i)).getOutputStream() != null) {
+                       if (((Node) liste.get(i)).getOutputStream() != null) {
                                try {
-                                       ((Node) liste.elementAt(i)).getOutputStream().close();
+                                       ((Node) liste.get(i)).getOutputStream().close();
                                } catch (Exception e) {
                                        System.err.println("Unable to close outputStream :" + e);
                                }
@@ -263,7 +274,7 @@ public class Register implements java.io.Serializable, java.lang.Cloneable {
                return params;
        }
 
-       public synchronized Vector<Node> getListOfNodes() {
+       public synchronized ArrayList<Node> getListOfNodes() {
                return liste;
        }