package jaceP2P;
-import java.util.Vector;
+import java.util.ArrayList;
+
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
// constructors
public Register() {
- liste = new Vector<Node>();
+ liste = new ArrayList<Node>() ;
}
public synchronized static Register Instance() {
}
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 ;
}
/*
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 ;
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 !!");
// 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 ) ;
}
}
return liste.size();
}
- public synchronized Vector<Node> getListe() {
+ public synchronized ArrayList<Node> getListe() {
return liste;
}
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);
}
return params;
}
- public synchronized Vector<Node> getListOfNodes() {
+ public synchronized ArrayList<Node> getListOfNodes() {
return liste;
}