Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Correction of some bugs and performance enhancement.
[jaceP2P.git] / src / jaceP2P / Task.java
index ffad2e9..f7db564 100644 (file)
@@ -5,7 +5,7 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.rmi.ConnectException;
 import java.rmi.RemoteException;
-import java.util.Vector;
+import java.util.ArrayList;
 
 //import java.util.Calendar;
 //import java.util.GregorianCalendar;
@@ -26,13 +26,13 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
        public int nb_not_recv;
        public boolean electedNode = false;
        public boolean respSent = false;
-       public Vector<Integer> resp;
+       public ArrayList<Integer> resp;
        public int verifNum = 0;
        public LastSave lastSave = new LastSave();
-       public Vector<Integer> neighbors;
-       public Vector<Boolean> neighborsValues;
-       public Vector<Integer> dependancies;
-       public Vector<Boolean> values;
+       public ArrayList<Integer> neighbors;
+       public ArrayList<Boolean> neighborsValues;
+       public ArrayList<Integer> dependancies;
+       public ArrayList<Boolean> values;
        public int sendId;
        public String action = "nothing";
        public boolean verdict = false;
@@ -57,22 +57,21 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
        public Task sauv;
        public BackupConvg sauvConvg = new BackupConvg();
        public boolean postReloading = false;
-       @SuppressWarnings("unchecked")
-       public Vector reduceAll;
+       public ArrayList<Object> reduceAll;
 
        int cpt = 0;
        int count = 0;
        Thread th;
 
        public Task() {
-               reduceAll = new Vector<Object>();
-               dependancies = new Vector<Integer>();
-               values = new Vector<Boolean>();
-               resp = new Vector<Integer>();
+               reduceAll = new ArrayList<Object>();
+               dependancies = new ArrayList<Integer>();
+               values = new ArrayList<Boolean>();
+               resp = new ArrayList<Integer>();
                saved = new boolean[2];
                sauv = this;
-               neighbors = new Vector<Integer>();
-               neighborsValues = new Vector<Boolean>();
+               neighbors = new ArrayList<Integer>();
+               neighborsValues = new ArrayList<Boolean>();
        }
 
        public void getBackupForNewNode(int rank) {
@@ -124,7 +123,7 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
        }
 
        // method to overload by user in the appli to specify the reduceAll method
-       public synchronized void reduceAll(Vector<?> recievedValue) {
+       public synchronized void reduceAll(ArrayList<Object> recievedValue) {
        }
 
        public void setId(TaskId Id) {
@@ -233,11 +232,11 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
        }
 
        public void reinitializeVectors() throws RemoteException {
-               values.removeAllElements();
-               dependancies.removeAllElements();
-               neighbors.removeAllElements();
-               neighborsValues.removeAllElements();
-               resp.removeAllElements();
+               values.clear() ;
+               dependancies.clear() ;
+               neighbors.clear() ;
+               neighborsValues.clear() ;
+               resp.clear() ;
        }
 
        public long jaceP2P_getChronoValue() {
@@ -433,7 +432,7 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
        }
 
        public void setValues(int index, boolean value) {
-               values.setElementAt(new Boolean(value), index);
+               values.set( index, new Boolean(value) ) ;
        }
 
        @SuppressWarnings("static-access")
@@ -637,9 +636,9 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
                        sauv.nb_not_recv = nb_not_recv;
                        sauv.electedNode = electedNode;
                        sauv.respSent = respSent;
-                       sauv.neighbors = (Vector) neighbors.clone();
-                       sauv.neighborsValues = (Vector) neighborsValues.clone();
-                       sauv.resp = (Vector) resp.clone();
+                       sauv.neighbors = (ArrayList<Integer>) neighbors.clone();
+                       sauv.neighborsValues = (ArrayList<Boolean>) neighborsValues.clone();
+                       sauv.resp = (ArrayList<Integer>) resp.clone();
                        sauv.verifNum = verifNum;
                        sauv.sendId = sendId;
                        sauv.reduceAll = reduceAll;
@@ -670,9 +669,9 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
                        sauvConvg.nb_not_recv = nb_not_recv;
                        sauvConvg.electedNode = electedNode;
                        sauvConvg.respSent = respSent;
-                       sauvConvg.neighbors = (Vector) neighbors.clone();
-                       sauvConvg.neighborsValues = (Vector) neighborsValues.clone();
-                       sauvConvg.resp = (Vector) resp.clone();
+                       sauvConvg.neighbors = (ArrayList<Integer>) neighbors.clone();
+                       sauvConvg.neighborsValues = (ArrayList<Boolean>) neighborsValues.clone();
+                       sauvConvg.resp = (ArrayList<Integer>) resp.clone();
                        sauvConvg.verifNum = verifNum;
                        sauvConvg.sendId = sendId;
                        sauvConvg.finalStep = finalStep;
@@ -1135,7 +1134,7 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
        }
 
        public synchronized void response(int neighId, int tag, int response,
-                       Vector<?> recievedValue) throws RemoteException {
+                       ArrayList<Object> recievedValue) throws RemoteException {
                // System.out.println("inside response function");
                // System.out.println("sleeping till not reloading");
                while (reloading == true) {
@@ -1159,12 +1158,12 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
 
                        if (response == 1
                                        && !state.equals("SAVING")
-                                       && (((Integer) (resp.elementAt(indexNeigh))).intValue()) != 1) {
+                                       && (((Integer) (resp.get(indexNeigh))).intValue()) != 1) {
                                // System.out.println("calling reduceAll()");
                                reduceAll(recievedValue);
                        }
                        // System.out.println("after calculating reduceAll");
-                       resp.setElementAt(response, indexNeigh);
+                       resp.set( indexNeigh, response ) ;
 
                        // System.out.println("get response ............");
                        waitForAck(3);
@@ -1175,8 +1174,8 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
 
        public void initializeSavLeader() {
                for (int i = 0; i < resp.size(); i++)
-                       resp.setElementAt(0, i);
-               respSent = false;
+                       resp.set( i, 0 ) ;
+               respSent = false ;
        }
 
        public boolean recievedAllResp() {
@@ -1224,7 +1223,7 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
                                if (((Boolean) neighborsValues.get(i)).booleanValue() == false) {
                                        nb_not_recv--;
                                        // System.out.println("le noeud "+idNeigh+" a envoyer un message de pseudoconvergence");
-                                       neighborsValues.setElementAt(new Boolean(true), i);
+                                       neighborsValues.set( i, new Boolean(true) ) ;
                                        waitForAck(3);
 
                                }
@@ -1262,9 +1261,9 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
 
                nb_not_recv = neighbors.size();
                for (int i = 0; i < neighbors.size(); i++)
-                       neighborsValues.setElementAt(new Boolean(false), i);
+                       neighborsValues.set( i, new Boolean(false) ) ;
                for (int i = 0; i < resp.size(); i++)
-                       resp.setElementAt(0, i);
+                       resp.set( i, 0 ) ;
                underTh = false;
                electedNode = false;
                localCV_state = false;
@@ -1282,14 +1281,14 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
                int neighId = -1;
                for (int i = 0; i < neighbors.size(); i++)
                        if (((Boolean) neighborsValues.get(i)).booleanValue() == false)
-                               neighId = ((Integer) neighbors.elementAt(i)).intValue();
+                               neighId = ((Integer) neighbors.get(i)).intValue();
                return neighId;
        }
 
        public boolean getValues() {
                boolean bool = true;
                for (int i = 0; i < values.size(); i++)
-                       if (((Boolean) values.elementAt(i)).equals(new Boolean(false))) {
+                       if (((Boolean) values.get(i)).equals(new Boolean(false))) {
                                bool = false;
                                break;
                        }
@@ -1342,7 +1341,7 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
        public void initializeVerifLeader() throws RemoteException {
                reinitializePPEr();
                for (int i = 0; i < resp.size(); i++)
-                       resp.setElementAt(0, i);
+                       resp.set( i, 0 ) ;
                verifNum++;
                respSent = false;
        }
@@ -1362,7 +1361,7 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
                                action = "sendVerif";
                                reinitializePPEr();
                                for (int i = 0; i < resp.size(); i++)
-                                       resp.setElementAt(0, i);
+                                       resp.set( i, 0 ) ;
                                verifNum++;
 
                                respSent = false;
@@ -1390,7 +1389,7 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
                pseudoPerBeg = false;
                pseudoPerEnd = false;
                for (int i = 0; i < values.size(); i++)
-                       values.setElementAt(new Boolean(false), i);
+                       values.set( i, new Boolean(false) ) ;
 
        }
 
@@ -1415,7 +1414,7 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
        }
 
        public void savOrFinOrRest(int tag, int step, boolean verd,
-                       Vector<?> reduceAll) {
+                       ArrayList<Object> reduceAll) {
                // System.out.println("Recieved verd "+verd+" sleeping till not reloading");
                while (reloading == true) {
                        try {
@@ -1429,7 +1428,7 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
                                action = "sendVerdict";
                                if (finalStep == true) {
                                        for (int i = 0; i < resp.size(); i++)
-                                               resp.setElementAt(0, i);
+                                               resp.set( i, 0 ) ;
                                        // System.out.println("sleeping till response is sent");
                                        while (action.equals("sendResponse") || respSent == false)
                                                try {