3 import java.util.ArrayList;
7 public class Register implements java.io.Serializable, java.lang.Cloneable {
9 private static final long serialVersionUID = 1L;
11 // a voir si on le met pas ds autre objet
12 final int MAX_COUNT_NOT_ALIVE = 3;
15 public static Register Instance;
16 private String appliName; // name of the appli
17 private ArrayList<Node> liste; // list of the nodes of the Register
18 // private ListeTask listeOfTasks = null; //liste of the TaskId of the appli
19 // private int version=0;
20 private String[] params; // params of the appli
21 private int numBackupNeighbors = 3;
22 private int numOfTasks;
23 private JaceSpawnerInterface spawnerStub = null;
24 private ListeTask listeOfTasks = null; // liste of the TaskId of the appli
29 liste = new ArrayList<Node>() ;
32 public synchronized static Register Instance() {
33 if (Instance == null) {
34 Instance = new Register();
39 public synchronized String getAppliName() {
43 public synchronized int existNode(Node node) {
47 .println("Node est null dans existNode");
54 while ((existe == -1) && (index < liste.size()))
56 if (node.equals((Node) liste.get(index)))
68 * public synchronized int getVersion(){ return version; }
70 * public void setVersion(int version){ this.version=version; }
73 public synchronized int addNode( Node host )
78 System.err.println( "In Register.addNode : host == null !" ) ;
82 is = existNodeOfStub( host.getStub() ) ;
85 System.out.println("This node exists yet, I replace it");
87 liste.set( is, host ) ;
96 * Add extra Nodes (for extra Spawners) at the beginning of the register.
97 * @param host The extra Node
99 public synchronized void addNodeBeg(Node host) {
102 System.err.println( "In Register.addNode : host.getIP() == null !" ) ;
104 is = existNodeOfStub( host.getStub() ) ;
106 System.out.println( "This node exists yet, I replace it" ) ;
107 // System.out.println("MERDE !!");
108 // System.out.println("MERDE !!");
109 // System.out.println("MERDE !!");
110 // System.out.println("MERDE !!");
111 // System.out.println("MERDE !!");
112 // System.out.println("MERDE !!");
113 // System.out.println("MERDE !!");
114 liste.set( is, host ) ;
116 liste.add( 0, host ) ;
120 public synchronized int existNodeOfStub(JaceInterface stub) {
121 // System.out.println("remote " + stub + "\n\n");
124 .println("Stub = NULL in existNodeOfStub");
129 while ((existe == -1) && (index < liste.size())) {
131 if (stub.equals(((Node) liste.get(index)).getStub())) {
139 public synchronized Node getNodeOfStub(JaceInterface stub) {
141 if (liste.isEmpty()) {
146 .println("In Register.getNodeOfStub : stub == null !");
148 is = existNodeOfStub(stub);
150 return (Node) liste.get(is);
152 // System.out.println("stub : ce noeud existe poooooooooooo");
158 public synchronized Node getNodeOfName(String name) {
160 if (liste.isEmpty()) {
165 .println("In Register.getNodeOfName : name == null !");
167 while ((is == -1) && (index < liste.size())) {
169 if (name.equals(((Node) liste.get(index)).getName())) {
176 return (Node) liste.get(is);
178 // System.out.println("stub : ce noeud existe poooooooooooo");
185 public synchronized Node getNodeAt(int index) {
186 return (Node) liste.get(index);
189 public synchronized boolean removeNode(Node n) {
190 return ( liste.remove( n ) ) ;
193 public synchronized boolean removeNodeOfName( String s )
195 boolean removed = false ;
197 // System.out.println("begin remove");
199 while( i < liste.size() && ! removed )
201 // System.out.println("i="+i+" s="+s);
202 if( ((Node) liste.get(i)).getName().equals(s) )
210 // System.out.println("end remove");
214 public synchronized int getSize() {
218 public synchronized ArrayList<Node> getListe() {
222 public synchronized void setParams(String[] myParams) {
226 public synchronized void setAppliName(String name) {
230 public synchronized void setSpawnerStub(JaceSpawnerInterface ref) {
234 public synchronized void replaceBy(Register newReg) {
240 public synchronized void setListeOfTasks(ListeTask myListe) {
241 listeOfTasks = myListe;
244 public synchronized ListeTask getListeOfTasks() {
248 public synchronized int getNumBackupNeighbors() {
249 return numBackupNeighbors;
252 public void setNumBackupNeighbors(int i) {
253 numBackupNeighbors = i;
256 public synchronized JaceSpawnerInterface getSpawnerStub() {
260 public synchronized void purge() {
261 for (int i = 0; i < liste.size(); i++)
262 if (((Node) liste.get(i)).getOutputStream() != null) {
264 ((Node) liste.get(i)).getOutputStream().close();
265 } catch (Exception e) {
266 System.err.println("Unable to close outputStream :" + e);
273 public synchronized String[] getParams() {
277 public synchronized ArrayList<Node> getListOfNodes() {
281 public void setInstance() {
285 public void setNbOfTasks(int nbOfTasks) {
286 numOfTasks = nbOfTasks;
289 public int getNbOfTasks() {
293 // affiche la liste des nom (ou IP si pas de nom) des machine du Register
294 public synchronized void viewAll() {
295 String aff = "Nb of Daemons registered: " + getSize();
297 String inter = "\n\t";
299 if (liste.isEmpty()) {
300 System.err.println("My Register is empty !!!!!");
302 for (int i = 0; i < liste.size(); i++) {
303 noeud = getNodeAt(i);
304 count = (i + 1) + " : ";
308 if (noeud.getName() != null) {
309 aff += inter + count + noeud.getName() + /*
315 + noeud.getAliveFlag() + ", count : "
316 + noeud.getNbOfBeats();
318 aff += inter + count + noeud.getIP() + " "
319 + noeud.getName() + " with appli : "
320 + noeud.getAppliName() + ", alive : "
321 + noeud.getAliveFlag();
325 * if (noeud.getWorkerStub() != null) { aff +=
326 * ", stub = PAS null"; } else { aff += ", stub = NULL"; }
330 System.out.println(aff);
332 System.out.println("\n");