Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Correction of some bugs and performance enhancement.
[jaceP2P.git] / src / jaceP2P / Register.java
index 1c4fdb6..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 ;
        }
 
        /*
@@ -76,9 +84,9 @@ public class Register implements java.io.Serializable, java.lang.Cloneable {
                if (is != -1) {
                        System.out.println("This node exists yet, I replace it");
 
-                       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 ) ;
                }
        }
        
@@ -208,7 +215,7 @@ public class Register implements java.io.Serializable, java.lang.Cloneable {
                return liste.size();
        }
 
-       public synchronized Vector<Node> getListe() {
+       public synchronized ArrayList<Node> getListe() {
                return liste;
        }
 
@@ -252,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);
                                }
@@ -267,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;
        }