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 ds existNode");
49 while ((existe == -1) && (index < liste.size())) {
50 if (node.equals((Node) liste.get(index))) {
59 * public synchronized int getVersion(){ return version; }
61 * public void setVersion(int version){ this.version=version; }
64 public synchronized void addNode(Node host) {
68 .println("ds Register.addNode : host.getIP() == null !!!!!!!!!!!!!!!");
70 is = existNodeOfStub(host.getStub());
72 System.out.println("This node exists yet, I replace it");
73 // System.out.println("MERDE !!");
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 liste.setElementAt(host, is);
86 public synchronized int existNodeOfStub(JaceInterface stub) {
87 // System.out.println("remote " + stub + "\n\n");
90 .println("!!!!!!!!!!!!!!!!!!!!!!!!! stub = NULL ds existNodeOfStub = ");
94 while ((existe == -1) && (index < liste.size())) {
96 if (stub.equals(((Node) liste.get(index)).getStub())) {
104 public synchronized Node getNodeOfStub(JaceInterface stub) {
106 if (liste.isEmpty()) {
111 .println("ds Register.getNodeOfStub : stub == null !!!!!!!!!!!!!!!");
113 is = existNodeOfStub(stub);
115 return (Node) liste.get(is);
117 // System.out.println("stub : ce noeud existe poooooooooooo");
123 public synchronized Node getNodeOfName(String name) {
125 if (liste.isEmpty()) {
130 .println("ds Register.getNodeOfName : name == null !!!!!!!!!!!!!!!");
132 while ((is == -1) && (index < liste.size())) {
134 if (name.equals(((Node) liste.get(index)).getName())) {
141 return (Node) liste.get(is);
143 // System.out.println("stub : ce noeud existe poooooooooooo");
150 public synchronized Node getNodeAt(int index) {
151 return (Node) liste.get(index);
154 public synchronized boolean removeNode(Node n) {
155 return (liste.remove(n));
158 public synchronized boolean removeNodeOfName(String s) {
159 boolean removed = false;
161 // System.out.println("begin remove");
163 while (i < liste.size() && !removed) {
164 // System.out.println("i="+i+" s="+s);
165 if (((Node) liste.get(i)).getName().equals(s)) {
171 // System.out.println("end remove");
175 public synchronized int getSize() {
179 public synchronized Vector<Node> getListe() {
183 public synchronized void setParams(String[] myParams) {
187 public synchronized void setAppliName(String name) {
191 public synchronized void setSpawnerStub(JaceSpawnerInterface ref) {
195 public synchronized void replaceBy(Register newReg) {
201 public synchronized void setListeOfTasks(ListeTask myListe) {
202 listeOfTasks = myListe;
205 public synchronized ListeTask getListeOfTasks() {
209 public synchronized int getNumBackupNeighbors() {
210 return numBackupNeighbors;
213 public void setNumBackupNeighbors(int i) {
214 numBackupNeighbors = i;
217 public synchronized JaceSpawnerInterface getSpawnerStub() {
221 public synchronized void purge() {
222 for (int i = 0; i < liste.size(); i++)
223 if (((Node) liste.elementAt(i)).getOutputStream() != null) {
225 ((Node) liste.elementAt(i)).getOutputStream().close();
226 } catch (Exception e) {
227 System.out.println("unable to close outputStream :" + e);
234 public synchronized String[] getParams() {
238 public synchronized Vector<Node> getListOfNodes() {
242 public void setInstance() {
246 public void setNbOfTasks(int nbOfTasks) {
247 numOfTasks = nbOfTasks;
250 public int getNbOfTasks() {
254 // affiche la liste des nom (ou IP si pas de nom) des machine du Register
255 public synchronized void viewAll() {
256 String aff = "Nb of Daemons registered: " + getSize();
258 String inter = "\n\t";
260 if (liste.isEmpty()) {
261 System.out.println("My Register is empty !!!!!");
263 for (int i = 0; i < liste.size(); i++) {
264 noeud = getNodeAt(i);
265 count = (i + 1) + " : ";
269 if (noeud.getName() != null) {
270 aff += inter + count + noeud.getName() + /*
276 + noeud.getAliveFlag() + ", count : "
277 + noeud.getNbOfBeats();
279 aff += inter + count + noeud.getIP() + " "
280 + noeud.getName() + " with appli : "
281 + noeud.getAppliName() + ", alive : "
282 + noeud.getAliveFlag();
286 * if (noeud.getWorkerStub() != null) { aff +=
287 * ", stub = PAS null"; } else { aff += ", stub = NULL"; }
291 System.out.println(aff);
293 System.out.println("\n");