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 void addNode(Node host) {
69 .println("In Register.addNode : host.getIP() == null !");
71 is = existNodeOfStub(host.getStub());
73 System.out.println("This node exists yet, I replace it");
74 // System.out.println("MERDE !!");
75 // System.out.println("MERDE !!");
76 // System.out.println("MERDE !!");
77 // System.out.println("MERDE !!");
78 // System.out.println("MERDE !!");
79 // System.out.println("MERDE !!");
80 // System.out.println("MERDE !!");
81 liste.setElementAt(host, is);
87 public synchronized int existNodeOfStub(JaceInterface stub) {
88 // System.out.println("remote " + stub + "\n\n");
91 .println("Stub = NULL in existNodeOfStub");
96 while ((existe == -1) && (index < liste.size())) {
98 if (stub.equals(((Node) liste.get(index)).getStub())) {
106 public synchronized Node getNodeOfStub(JaceInterface stub) {
108 if (liste.isEmpty()) {
113 .println("In Register.getNodeOfStub : stub == null !");
115 is = existNodeOfStub(stub);
117 return (Node) liste.get(is);
119 // System.out.println("stub : ce noeud existe poooooooooooo");
125 public synchronized Node getNodeOfName(String name) {
127 if (liste.isEmpty()) {
132 .println("In Register.getNodeOfName : name == null !");
134 while ((is == -1) && (index < liste.size())) {
136 if (name.equals(((Node) liste.get(index)).getName())) {
143 return (Node) liste.get(is);
145 // System.out.println("stub : ce noeud existe poooooooooooo");
152 public synchronized Node getNodeAt(int index) {
153 return (Node) liste.get(index);
156 public synchronized boolean removeNode(Node n) {
157 return (liste.remove(n));
160 public synchronized boolean removeNodeOfName(String s) {
161 boolean removed = false;
163 // System.out.println("begin remove");
165 while (i < liste.size() && !removed) {
166 // System.out.println("i="+i+" s="+s);
167 if (((Node) liste.get(i)).getName().equals(s)) {
173 // System.out.println("end remove");
177 public synchronized int getSize() {
181 public synchronized Vector<Node> getListe() {
185 public synchronized void setParams(String[] myParams) {
189 public synchronized void setAppliName(String name) {
193 public synchronized void setSpawnerStub(JaceSpawnerInterface ref) {
197 public synchronized void replaceBy(Register newReg) {
203 public synchronized void setListeOfTasks(ListeTask myListe) {
204 listeOfTasks = myListe;
207 public synchronized ListeTask getListeOfTasks() {
211 public synchronized int getNumBackupNeighbors() {
212 return numBackupNeighbors;
215 public void setNumBackupNeighbors(int i) {
216 numBackupNeighbors = i;
219 public synchronized JaceSpawnerInterface getSpawnerStub() {
223 public synchronized void purge() {
224 for (int i = 0; i < liste.size(); i++)
225 if (((Node) liste.elementAt(i)).getOutputStream() != null) {
227 ((Node) liste.elementAt(i)).getOutputStream().close();
228 } catch (Exception e) {
229 System.err.println("Unable to close outputStream :" + e);
236 public synchronized String[] getParams() {
240 public synchronized Vector<Node> getListOfNodes() {
244 public void setInstance() {
248 public void setNbOfTasks(int nbOfTasks) {
249 numOfTasks = nbOfTasks;
252 public int getNbOfTasks() {
256 // affiche la liste des nom (ou IP si pas de nom) des machine du Register
257 public synchronized void viewAll() {
258 String aff = "Nb of Daemons registered: " + getSize();
260 String inter = "\n\t";
262 if (liste.isEmpty()) {
263 System.err.println("My Register is empty !!!!!");
265 for (int i = 0; i < liste.size(); i++) {
266 noeud = getNodeAt(i);
267 count = (i + 1) + " : ";
271 if (noeud.getName() != null) {
272 aff += inter + count + noeud.getName() + /*
278 + noeud.getAliveFlag() + ", count : "
279 + noeud.getNbOfBeats();
281 aff += inter + count + noeud.getIP() + " "
282 + noeud.getName() + " with appli : "
283 + noeud.getAppliName() + ", alive : "
284 + noeud.getAliveFlag();
288 * if (noeud.getWorkerStub() != null) { aff +=
289 * ", stub = PAS null"; } else { aff += ", stub = NULL"; }
293 System.out.println(aff);
295 System.out.println("\n");