Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Correction of some bugs and performance enhancement.
[jaceP2P.git] / src / jaceP2P / SuperNodeListe.java
index 0eede4b..107d9b7 100644 (file)
@@ -5,8 +5,8 @@ import java.io.FileInputStream;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.rmi.Naming;
+import java.util.ArrayList;
 import java.util.Random;
-import java.util.Vector;
 
 import and.Mapping.Algo;
 import and.Mapping.GNode;
@@ -16,13 +16,11 @@ public class SuperNodeListe implements Cloneable {
        // attributes
        public static SuperNodeListe Instance;
        private Random r;
-       @SuppressWarnings("unchecked")
-       private Vector liste = null;
+       private ArrayList<Object> liste = null;
 
        // constructors
-       @SuppressWarnings("unchecked")
        public SuperNodeListe() {
-               liste = new Vector();
+               liste = new ArrayList<Object>() ;
                r = new Random();
        }
 
@@ -32,13 +30,13 @@ public class SuperNodeListe implements Cloneable {
                }
                return Instance;
        }
-
+       
        @SuppressWarnings("unchecked")
        public synchronized SuperNodeListe clone() {
                SuperNodeListe d = new SuperNodeListe();
                // d.r = (Random) r.clone();
-               d.liste = (Vector) liste.clone();
-               return d;
+               d.liste = (ArrayList<Object>) liste.clone() ;
+               return d ;
        }
 
        // methods
@@ -48,8 +46,6 @@ public class SuperNodeListe implements Cloneable {
        // 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 = "";
                String home = System.getProperty("user.home");
@@ -91,8 +87,8 @@ public class SuperNodeListe implements Cloneable {
                // donnees ds un fichier de conf
        }
 
-       @SuppressWarnings("unchecked")
-       public Vector getListe() {
+       
+       public ArrayList<Object> getListe() {
                return liste;
        }
 
@@ -106,11 +102,11 @@ public class SuperNodeListe implements Cloneable {
                if (index < 0) {
                        index = -index;
                }
-               return (SuperNodeData) liste.elementAt(index);
+               return (SuperNodeData) liste.get(index);
        }
 
        public SuperNodeData getSuperNodeData(int i) {
-               return (SuperNodeData) liste.elementAt(i);
+               return (SuperNodeData) liste.get(i);
        }
 
        // if returns 0, there are no nodes at all
@@ -120,25 +116,24 @@ public class SuperNodeListe implements Cloneable {
                SuperNodeData return_d = null;
 
                for (int i = 0; i < liste.size(); i++) {
-                       d = (SuperNodeData) liste.elementAt(i);
+                       d = (SuperNodeData) liste.get(i);
                        if (d.getNbOfNodes() > max) {
                                max = d.getNbOfNodes();
-                               return_d = (SuperNodeData) liste.elementAt(i);
+                               return_d = (SuperNodeData) liste.get(i);
                        }
                }
                return return_d;
        }
 
        public void addStub(int index, JaceSuperNodeInterface stub) {
-               ((SuperNodeData) liste.elementAt(index)).setStub(stub);
+               ((SuperNodeData) liste.get(index)).setStub(stub);
        }
 
-       @SuppressWarnings("unchecked")
        public void addStubOf(String snode, int port, JaceSuperNodeInterface stub) {
                int is = -1;
                is = existSuperNode(snode);
                if (is != -1) {
-                       ((SuperNodeData) liste.elementAt(is)).setStub(stub);
+                       ((SuperNodeData) liste.get(is)).setStub(stub);
                } else {
                        System.err.println("This superNode does not exist : " + snode);
                        System.out.println("Add the new SuperNode");
@@ -201,7 +196,7 @@ public class SuperNodeListe implements Cloneable {
                JaceSuperNodeInterface remoteStub = null;
 
                for (int i = 0; i < liste.size(); i++) {
-                       d = (SuperNodeData) liste.elementAt(i);
+                       d = (SuperNodeData) liste.get(i);
                        if (!d.getIP().equals(LocalHost.Instance().getIP())) {
                                // if not me, I inform the other super nodes
                                remoteStub = d.getStub();
@@ -224,14 +219,13 @@ public class SuperNodeListe implements Cloneable {
                int is = -1;
                is = existSuperNode(IP);
                if (is != -1) {
-                       SuperNodeData d = (SuperNodeData) liste.elementAt(is);
+                       SuperNodeData d = (SuperNodeData) liste.get(is);
                        d.setNbOfNodes(nb);
                } else {
                        System.err.println("This SuperNode does not exists in my list: " + IP);
                }
        }
 
-       @SuppressWarnings("unchecked")
        public void locateSuperNodes(JaceSuperNodeInterface stub) {
                String remoteIP;
                int remotePort;
@@ -240,8 +234,8 @@ public class SuperNodeListe implements Cloneable {
                boolean inStaticList = false;
                while (i < liste.size() && !connected) {
                        remoteIP = LocalHost.Instance().resolve(
-                                       ((SuperNodeData) liste.elementAt(i)).getIP());
-                       remotePort = ((SuperNodeData) liste.elementAt(i)).getPort();
+                                       ((SuperNodeData) liste.get(i)).getIP());
+                       remotePort = ((SuperNodeData) liste.get(i)).getPort();
 
                        // If I'm not this superNode, I locate the others
                        if (!remoteIP.equals(LocalHost.Instance().getIP())) {
@@ -257,7 +251,7 @@ public class SuperNodeListe implements Cloneable {
                                        // SuperNodeListe.Instance().addStub(i, remoteStub);
 
                                        // Send my stub to this corresponding remote SuperNode
-                                       liste = (Vector<?>) remoteStub.sendStub(LocalHost.Instance()
+                                       liste = (ArrayList<Object>) remoteStub.sendStub(LocalHost.Instance()
                                                        .getIP(), LocalHost.Instance().getPort(), stub);
                                        System.out.println("Recieved List");
                                        connected = true;
@@ -269,7 +263,7 @@ public class SuperNodeListe implements Cloneable {
                                        // get the nb of Daemons the remote SuperNode has already
                                        // registered
                                        // nb = remoteStub.getNbOfNodes();
-                                       // ((SuperNodeData)liste.elementAt(i)).setNbOfNodes(nb);
+                                       // ((SuperNodeData)liste.get(i)).setNbOfNodes(nb);
 
                                        // System.out.println("bien envoye mon stub a " + remoteIP);
                                        System.out.println("size:" + liste.size());
@@ -299,13 +293,12 @@ public class SuperNodeListe implements Cloneable {
 
        }
 
-       @SuppressWarnings("unchecked")
        public void addSuperNode(SuperNodeData d) {
                int is = -1;
                String name = d.getIP();
                is = existSuperNode(name);
                if (is != -1) {
-                       liste.setElementAt(d, is);
+                       liste.set( is, d ) ;
                } else {
                        liste.add(d);
                }
@@ -326,12 +319,12 @@ public class SuperNodeListe implements Cloneable {
                System.out.println("\nConfig of the superNodes :");
                String msg = "";
                for (int i = 0; i < liste.size(); i++) {
-                       SuperNodeData d = (SuperNodeData) liste.elementAt(i);
+                       SuperNodeData d = (SuperNodeData) liste.get(i);
                        if (d.getIP().equals(LocalHost.Instance().getIP())) {
                                msg = "me : " + Register.Instance().getSize();
                        } else {
                                System.out.println(d.getIP() + " : "
-                                               + ((SuperNodeData) liste.elementAt(i)).getNbOfNodes());
+                                               + ((SuperNodeData) liste.get(i)).getNbOfNodes());
                        }
                }
                System.out.println(msg);
@@ -354,7 +347,7 @@ public class SuperNodeListe implements Cloneable {
 
                        for( int i = 0 ; i < liste.size() ; i++ ) 
                        {
-                               d = (SuperNodeData) liste.elementAt( i ) ;
+                               d = (SuperNodeData) liste.get( i ) ;
                                if( ! d.getIP().equals(LocalHost.Instance().getIP() ) ) 
                                {
                                        // if not me, I inform the other super nodes
@@ -379,7 +372,7 @@ public class SuperNodeListe implements Cloneable {
 
                        for( int i = 0 ; i < liste.size() ; i++ ) 
                        {
-                               d = (SuperNodeData) liste.elementAt( i ) ;
+                               d = (SuperNodeData) liste.get( i ) ;
                                if( ! d.getIP().equals(LocalHost.Instance().getIP() ) ) 
                                {
                                        // if not me, I inform the other super nodes
@@ -404,7 +397,7 @@ public class SuperNodeListe implements Cloneable {
 
                        for( int i = 0 ; i < liste.size() ; i++ ) 
                        {
-                               d = (SuperNodeData) liste.elementAt( i ) ;
+                               d = (SuperNodeData) liste.get( i ) ;
                                if( ! d.getIP().equals(LocalHost.Instance().getIP() ) ) 
                                {
                                        // if not me, I inform the other super nodes
@@ -429,7 +422,7 @@ public class SuperNodeListe implements Cloneable {
 
                        for( int i = 0 ; i < liste.size() ; i++ ) 
                        {
-                               d = (SuperNodeData) liste.elementAt( i ) ;
+                               d = (SuperNodeData) liste.get( i ) ;
                                if( ! d.getIP().equals(LocalHost.Instance().getIP() ) ) 
                                {
                                        // if not me, I inform the other super nodes
@@ -454,7 +447,7 @@ public class SuperNodeListe implements Cloneable {
 
                for( int i = 0 ; i < liste.size() ; i++ ) 
                {
-                       d = (SuperNodeData) liste.elementAt( i ) ;
+                       d = (SuperNodeData) liste.get( i ) ;
                        if( ! d.getIP().equals(LocalHost.Instance().getIP() ) ) 
                        {
                                // if not me, I inform the other super nodes
@@ -479,7 +472,7 @@ public class SuperNodeListe implements Cloneable {
 
                        for( int i = 0 ; i < liste.size() ; i++ ) 
                        {
-                               d = (SuperNodeData) liste.elementAt( i ) ;
+                               d = (SuperNodeData) liste.get( i ) ;
                                if( ! d.getIP().equals(LocalHost.Instance().getIP() ) ) 
                                {
                                        // if not me, I inform the other super nodes
@@ -503,7 +496,7 @@ public class SuperNodeListe implements Cloneable {
 
                        for( int i = 0 ; i < liste.size() ; i++ ) 
                        {
-                               d = (SuperNodeData) liste.elementAt( i ) ;
+                               d = (SuperNodeData) liste.get( i ) ;
                                if( ! d.getIP().equals( LocalHost.Instance().getIP() ) ) 
                                {
                                        // if not me, I inform the other super nodes
@@ -530,7 +523,7 @@ public class SuperNodeListe implements Cloneable {
 
                for( int i = 0 ; i < liste.size() ; i++ ) 
                {
-                       d = (SuperNodeData) liste.elementAt( i ) ;
+                       d = (SuperNodeData) liste.get( i ) ;
                        if( ! d.getIP().equals( LocalHost.Instance().getIP() ) ) 
                        {
                                // if not me, I inform the other super nodes