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 ;
}
/*
* 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 ;
}
/**
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 ) ;
}
}
}
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;
}
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;
}