3 import java.util.Vector;
6 public class Register implements java.io.Serializable, java.lang.Cloneable {
8 private static final long serialVersionUID = 1L;
10 // a voir si on le met pas ds autre objet
11 final int MAX_COUNT_NOT_ALIVE = 3;
14 public static Register Instance;
15 private String appliName; // name of the appli
16 private Vector<Node> liste; // list of the nodes of the Register
17 // private ListeTask listeOfTasks = null; //liste of the TaskId of the appli
18 // private int version=0;
19 private String[] params; // params of the appli
20 private int numBackupNeighbors = 3;
21 private int numOfTasks;
22 private JaceSpawnerInterface spawnerStub = null;
23 private ListeTask listeOfTasks = null; // liste of the TaskId of the appli
28 liste = new Vector<Node>();
31 public synchronized static Register Instance() {
32 if (Instance == null) {
33 Instance = new Register();
38 public synchronized String getAppliName() {
42 public synchronized int existNode(Node node) {
45 .println("Node est null dans existNode");
50 while ((existe == -1) && (index < liste.size())) {
51 if (node.equals((Node) liste.get(index))) {
60 * public synchronized int getVersion(){ return version; }
62 * public void setVersion(int version){ this.version=version; }
65 public synchronized int addNode( Node host )
70 System.err.println( "In Register.addNode : host == null !" ) ;
74 is = existNodeOfStub( host.getStub() ) ;
77 System.out.println("This node exists yet, I replace it");
79 liste.setElementAt(host, is);
88 * Add extra Nodes (for extra Spawners) at the beginning of the register.
89 * @param host The extra Node
91 public synchronized void addNodeBeg(Node host) {
95 .println("In Register.addNode : host.getIP() == null !");
97 is = existNodeOfStub(host.getStub());
99 System.out.println("This node exists yet, I replace it");
100 // System.out.println("MERDE !!");
101 // System.out.println("MERDE !!");
102 // System.out.println("MERDE !!");
103 // System.out.println("MERDE !!");
104 // System.out.println("MERDE !!");
105 // System.out.println("MERDE !!");
106 // System.out.println("MERDE !!");
107 liste.setElementAt(host, is);
113 public synchronized int existNodeOfStub(JaceInterface stub) {
114 // System.out.println("remote " + stub + "\n\n");
117 .println("Stub = NULL in existNodeOfStub");
122 while ((existe == -1) && (index < liste.size())) {
124 if (stub.equals(((Node) liste.get(index)).getStub())) {
132 public synchronized Node getNodeOfStub(JaceInterface stub) {
134 if (liste.isEmpty()) {
139 .println("In Register.getNodeOfStub : stub == null !");
141 is = existNodeOfStub(stub);
143 return (Node) liste.get(is);
145 // System.out.println("stub : ce noeud existe poooooooooooo");
151 public synchronized Node getNodeOfName(String name) {
153 if (liste.isEmpty()) {
158 .println("In Register.getNodeOfName : name == null !");
160 while ((is == -1) && (index < liste.size())) {
162 if (name.equals(((Node) liste.get(index)).getName())) {
169 return (Node) liste.get(is);
171 // System.out.println("stub : ce noeud existe poooooooooooo");
178 public synchronized Node getNodeAt(int index) {
179 return (Node) liste.get(index);
182 public synchronized boolean removeNode(Node n) {
183 return ( liste.remove( n ) ) ;
186 public synchronized boolean removeNodeOfName( String s )
188 boolean removed = false ;
190 // System.out.println("begin remove");
192 while( i < liste.size() && ! removed )
194 // System.out.println("i="+i+" s="+s);
195 if( ((Node) liste.get(i)).getName().equals(s) )
203 // System.out.println("end remove");
207 public synchronized int getSize() {
211 public synchronized Vector<Node> getListe() {
215 public synchronized void setParams(String[] myParams) {
219 public synchronized void setAppliName(String name) {
223 public synchronized void setSpawnerStub(JaceSpawnerInterface ref) {
227 public synchronized void replaceBy(Register newReg) {
233 public synchronized void setListeOfTasks(ListeTask myListe) {
234 listeOfTasks = myListe;
237 public synchronized ListeTask getListeOfTasks() {
241 public synchronized int getNumBackupNeighbors() {
242 return numBackupNeighbors;
245 public void setNumBackupNeighbors(int i) {
246 numBackupNeighbors = i;
249 public synchronized JaceSpawnerInterface getSpawnerStub() {
253 public synchronized void purge() {
254 for (int i = 0; i < liste.size(); i++)
255 if (((Node) liste.elementAt(i)).getOutputStream() != null) {
257 ((Node) liste.elementAt(i)).getOutputStream().close();
258 } catch (Exception e) {
259 System.err.println("Unable to close outputStream :" + e);
266 public synchronized String[] getParams() {
270 public synchronized Vector<Node> getListOfNodes() {
274 public void setInstance() {
278 public void setNbOfTasks(int nbOfTasks) {
279 numOfTasks = nbOfTasks;
282 public int getNbOfTasks() {
286 // affiche la liste des nom (ou IP si pas de nom) des machine du Register
287 public synchronized void viewAll() {
288 String aff = "Nb of Daemons registered: " + getSize();
290 String inter = "\n\t";
292 if (liste.isEmpty()) {
293 System.err.println("My Register is empty !!!!!");
295 for (int i = 0; i < liste.size(); i++) {
296 noeud = getNodeAt(i);
297 count = (i + 1) + " : ";
301 if (noeud.getName() != null) {
302 aff += inter + count + noeud.getName() + /*
308 + noeud.getAliveFlag() + ", count : "
309 + noeud.getNbOfBeats();
311 aff += inter + count + noeud.getIP() + " "
312 + noeud.getName() + " with appli : "
313 + noeud.getAppliName() + ", alive : "
314 + noeud.getAliveFlag();
318 * if (noeud.getWorkerStub() != null) { aff +=
319 * ", stub = PAS null"; } else { aff += ", stub = NULL"; }
323 System.out.println(aff);
325 System.out.println("\n");