Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9528cf0b63e4e3e2882704faa09262b3243166d4
[jaceP2P.git] / src / jaceP2P / JaceSpawnerServer.java
1 package jaceP2P;
2
3 import java.rmi.RemoteException;
4 import java.rmi.server.UnicastRemoteObject;
5 import java.util.Calendar;
6 import java.util.GregorianCalendar;
7 import java.util.Vector;
8
9
10 public class JaceSpawnerServer extends UnicastRemoteObject implements
11                 JaceSpawnerInterface {
12
13         private static final long serialVersionUID = 1L;
14
15         int nbKilled = 0;
16         boolean finished = false;
17
18         // constructeur
19         public JaceSpawnerServer() throws RemoteException {
20                 super();
21         }
22
23         @SuppressWarnings("unchecked")
24         public void startProcess(Vector spawnersList) throws RemoteException {
25                 JaceSpawner.Instance().startProcess(spawnersList);
26
27         }
28
29         public Register getRegister(int rank) throws RemoteException {
30                 return JaceSpawner.Instance().getRegister(rank);
31         }
32
33         public void killApplication(JaceInterface stub) throws RemoteException {
34
35                 // Node noeud = Register.Instance().getNodeOfStub(stub);
36                 // noeud.setAppliName(null);
37                 // new ReconnectThread(stub,noeud.getName()).start();
38                 // Register.Instance().removeNode(noeud);
39                 // nbKilled++;
40                 /*
41                  * if (Register.Instance().getSize() < 1) { long finalTime =
42                  * RunningApplication.Instance().getChrono().getValue(); int nb =
43                  * RunningApplication.Instance().getNumberOfDisconnections();
44                  * System.out.println("Application finished successfully !!!!!!");
45                  * System.out.println("Application finished successfully !!!!!!");
46                  * System.out.println("Application finished successfully !!!!!!");
47                  * System.out.println("Application finished successfully !!!!!!");
48                  * System.out.println("Application finished successfully !!!!!!");
49                  * System.out.println("Application finished successfully !!!!!!");
50                  * System.out.println("Application finished successfully !!!!!!");
51                  * System.out.println("Application finished successfully !!!!!!");
52                  * System.out.println("Application finished successfully !!!!!!\n");
53                  * System.out.println("TOTAL TIME in s : " + (finalTime/1000));
54                  * System.out.println("nb of desconnections : " + nb);
55                  * 
56                  * //purger l'appli RunningApplication.Instance().purge(); }
57                  */
58         }
59
60         public long getChronoValue(String appliName) throws RemoteException {
61                 long res = -1;
62                 if (RunningApplication.Instance().getName().equals(appliName)) {
63                         res = RunningApplication.Instance().getChrono().getValue();
64                         // System.out.println("temps chrono : " + res + " ms\n");
65                 } else {
66                         System.err.println("No application of name "+appliName+" on this Spawner !");
67                 }
68                 return res;
69         }
70
71         public void setOver(boolean bool) throws RemoteException {
72                 JaceSpawner.Instance().broadcastFinished(bool);
73
74         }
75
76         public void setFinished(boolean bool) throws RemoteException {
77                 finished = bool;
78
79         }
80
81         public String getName() throws RemoteException {
82                 return LocalHost.Instance().getName();
83         }
84
85         public boolean getFinished() throws RemoteException {
86                 return finished;
87         }
88
89         public void signalDeadNode(JaceInterface host, int rankOfDead)
90                         throws RemoteException {
91                 System.out.println("SignalDeadNode of rank " + rankOfDead);
92                 JaceSpawner.Instance().signalDeadNode(host, rankOfDead);
93         }
94
95         // heartBeat that detects if a Spawner is dead or alive
96         public void beating() throws RemoteException {
97                 ScanThreadSpawner.Instance().setAliveTime();
98
99                 // System.out.println("spawner is pinging me");
100         }
101
102         public synchronized void replaceBy(JaceSpawnerInterface oldStub,
103                         JaceSpawnerInterface stub) throws RemoteException {
104                 Calendar cal = new GregorianCalendar();
105                 System.out.println("at time=" + cal.get(Calendar.MINUTE) + ":"
106                                 + cal.get(Calendar.SECOND));
107                 System.out.println("replacing a dead spawner by another");
108                 JaceSpawner.Instance().replaceBy(oldStub, stub);
109                 RunningApplication.Instance().incrementNumberOfSpawnerDisconnections();
110         }
111
112         public void updateHeart(JaceSpawnerInterface stub) throws RemoteException {
113                 HeartBeatSpawner.Instance().setServer(stub);
114         }
115
116         public boolean ping() throws RemoteException {
117                 return true;
118         }
119
120         public synchronized void replaceDeamonBy(Node oldNode, Node node, int rank)
121                         throws RemoteException {
122                 Calendar cal = new GregorianCalendar();
123                 System.out.println("at time=" + cal.get(Calendar.MINUTE) + ":"
124                                 + cal.get(Calendar.SECOND));
125                 if (Register.Instance().removeNodeOfName(oldNode.getName()))
126                         System.out.println("Node " + oldNode.getName() + " of rank " + rank
127                                         + " has been removed");
128                 else
129                         System.out.println("Node " + oldNode.getName() + " of rank " + rank
130                                         + " hasn't been removed");
131                 Register.Instance().addNode(node);
132
133                 TaskId myTaskId = Register.Instance().getListeOfTasks()
134                                 .getTaskIdOfHostStub(oldNode.getStub());
135
136                 myTaskId.setHostIP(node.getIP());
137
138                 myTaskId.setHostName(node.getName());
139                 myTaskId.setHostStub(node.getStub());
140                 // Register.Instance().setVersion(Register.Instance().getVersion()+1);
141                 RunningApplication.Instance().incrementNumberOfDisconnections();
142                 System.out.println("Replacing node: " + oldNode.getName() + " with: "
143                                 + node.getName());
144                 // Register.Instance().getListeOfTasks().viewAll();
145         }
146
147 }