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;
9 public class JaceServer extends UnicastRemoteObject implements JaceInterface {
11 private static final long serialVersionUID = 1L;
13 public JaceServer() throws RemoteException {
17 public void reconnectSuperNode() throws RemoteException {
18 JaceDaemon.Instance().reconnectSuperNode();
21 // when a daemon replaces a new one it asks for the backups
22 public void getBackupForNewNode(int rank) throws RemoteException {
23 JaceSession.Instance().getTaskObject().getBackupForNewNode(rank);
26 public void setSpawner(JaceSpawnerInterface spawnerStub)
27 throws RemoteException {
28 Register.Instance().setSpawnerStub(spawnerStub);
31 // public JaceSpawnerInterface transformIntoSpawner(String[] params,
32 // String appliName, Register reg, int nbTasks,
33 // JaceSuperNodeInterface snodeStub, int rank, int heartTime, int tag,
34 // int nbdc, int nbsdc, int nbDaemonPerSpawner, int nbDaemonPerThread)
35 // throws RemoteException {
36 // System.out.println("Beginning the transformation ...");
37 // new JaceSpawner(params, appliName, reg, nbTasks,
38 // snodeStub, rank, heartTime, tag, nbdc, nbsdc,
39 // nbDaemonPerSpawner, nbDaemonPerThread);
40 // HeartBeatThread.Instance().kill();
41 // return Register.Instance().getSpawnerStub();
45 public JaceSpawnerInterface transformIntoSpawner(String[] params,
46 String appliName, Register reg, int nbTasks,
47 JaceSuperNodeInterface snodeStub, int rank, int heartTime, int tag,
48 int nbdc, int nbsdc, int nbDaemonPerSpawner, int nbDaemonPerThread,
50 throws RemoteException {
51 System.out.println("Beginning the transformation ...");
52 new JaceSpawner(params, appliName, reg, nbTasks,
53 snodeStub, rank, heartTime, tag, nbdc, nbsdc,
54 nbDaemonPerSpawner, nbDaemonPerThread, idAlgo);
55 HeartBeatThread.Instance().kill();
56 return Register.Instance().getSpawnerStub();
59 public synchronized int updateRegister(Register newReg,
60 JaceInterface voisinStub, int req) throws RemoteException {
62 // If beginning of appli, tell nodes to beat the next neighbor
63 // and no longer the SuperNode
65 System.out.println("I change to ping a Daemon");
66 HeartBeatThread.Instance().setServer((Object) voisinStub);
68 Calendar cal = new GregorianCalendar();
69 System.out.println("at time=" + cal.get(Calendar.MINUTE) + ":"
70 + cal.get(Calendar.SECOND));
71 System.out.println("name of spawner: "
72 + newReg.getSpawnerStub().getName());
73 // 1 - replace the old Register by the new one
74 System.out.println(" \n\n NEW REGISTER \n\n");
75 // if(Register.Instance().getVersion()<=newReg.getVersion()){
76 System.out.println("Replacing Register ...");
77 Register.Instance().replaceBy(newReg);
78 Register.Instance().viewAll();
81 // initialise the BackupsManager if not exists (i.e. myRank = -1)
82 // which means that not init so first reload
84 // if (BackupsManager.Instance().getMyRank() == -1) {
85 // 1 - create the BackupsManager
86 // 2 - get an eventual Backup for my Task
87 // 3 - restart it if any
88 // BackupsManager.Instance().initialize();
90 new InitiateAppli(req).start();
95 public void updateRegister(Node oldNode, Node node) throws RemoteException {
98 // HeartBeatThread.Instance().setServer((Object)node.getStub());
99 // 1 - replace the old Register by the new one
100 Calendar cal = new GregorianCalendar();
101 System.out.println("at time=" + cal.get(Calendar.MINUTE) + ":"
102 + cal.get(Calendar.SECOND));
103 System.out.println("Modify REGISTER");
105 // System.out.println("blablablablabalablablabalbalab");
106 System.out.println("oldName=" + oldNode.getName());
107 boolean b = Register.Instance().removeNodeOfName(oldNode.getName());
109 System.out.println("removed old Node!!!!!");
111 System.out.println("didn't find old Node!!!!");
113 Register.Instance().addNode(node);
114 Register.Instance().viewAll();
115 TaskId myTaskId = null;
116 myTaskId = Register.Instance().getListeOfTasks()
117 .getTaskIdOfHostStub(oldNode.getStub());
118 myTaskId.setHostIP(node.getIP());
119 myTaskId.setHostName(node.getName());
120 // Register.Instance().setVersion(version);
121 myTaskId.setHostStub(node.getStub());
123 } catch (Exception e) {
124 System.err.println("Error in updateregister :" + e);
125 // e.printStackTrace();
129 public Vector<?> getIterationOfBackup(int remoteRank, int tag)
130 throws RemoteException {
131 Backup b = BackupsManager.Instance().getBackupTaskOfRank(remoteRank,
133 Vector<?> result = b.getIterationStep();
137 public Backup getRemoteBackup(int remoteRank, int tag)
138 throws RemoteException {
139 Backup b = BackupsManager.Instance().getBackupTaskOfRank(remoteRank,
144 public void suicide(String debugMsg) throws RemoteException {
145 // System.out.println("suiciiiiiiiiiiiide : "/* + debugMsg */);
146 new ReinitDaemon().start();
149 public void iSendYou(Message msg) throws RemoteException {
150 // on met le Message ds le MsgQueue correspondant ma tache
151 // DS CAS ASYNC, on supprime un msg de meme tag ET meme sender
152 // System.out.println("get msg from MSGQueue sent from "+msg.getSender().getRank());
153 MsgQueue.Instance().add(msg);
156 public int getTimeStep() throws RemoteException {
157 return JaceSession.Instance().getTaskObject().timeStep;
160 public void saveTask(int rank, byte[] tsk, int iteration, int timeStep,
161 String appliName, int tag) throws RemoteException {
163 while (JaceSession.Instance().getTaskObject().reloading == true)
166 } catch (Exception e) {
168 Backup back = BackupsManager.Instance().getBackupTaskOfRank(rank, tag);
170 if (back.getStep() < timeStep
171 || (back.getStep() == timeStep && back.getIteration() < iteration)) {
172 back.setIteration(iteration);
173 // System.out.print("\n\n they put in me a backup with iter="+back.getIteration()+" for the node of rank="+rank+"\n\n");
174 back.setStep(timeStep);
180 * TaskId recev=null; recev =
181 * Register.Instance().getListeOfTasks().getTaskIdOfRank(rank);
182 * JaceInterface stub; stub=recev.getHostStub();
183 * stub.setSaved(true);
185 * }catch(Exception e){
186 * System.out.println("unable to acknowledge receiving the backup :"
191 System.out.println("No task at this rank");
192 // TODO : what to do ?
197 public void setSaved(boolean bool) throws RemoteException {
198 JaceSession.Instance().getTaskObject().setSaved(bool);
201 public boolean getReloading() throws RemoteException {
202 return JaceSession.Instance().getTaskObject().reloading;
205 public int getVerifNum() throws RemoteException {
206 return JaceSession.Instance().getTaskObject().verifNum;
209 public String getState() throws RemoteException {
210 return JaceSession.Instance().getTaskObject().state;
213 public void initializeVerif(int tag) throws RemoteException {
214 JaceSession.Instance().getTaskObject().initializeVerif(tag);
217 public void savOrFinOrRest(int tag, int step, boolean verd,
218 Vector<?> recievedValue) throws RemoteException {
219 JaceSession.Instance().getTaskObject().savOrFinOrRest(tag, step, verd,
223 public synchronized boolean setNbNeighboursNotConv(int tag, int idNeigh,
224 int neighborTimeStep) throws RemoteException {
225 return JaceSession.Instance().getTaskObject().setNbNeighboursNotConv(
226 tag, idNeigh, neighborTimeStep);
229 public synchronized int getNbNeighboursNotConv() throws RemoteException {
230 return JaceSession.Instance().getTaskObject().nb_not_recv;
233 public synchronized void response(int neighId, int tag, int response,
234 Vector<?> recievedValue) throws RemoteException {
235 JaceSession.Instance().getTaskObject().response(neighId, tag, response,
239 public boolean ping() throws RemoteException {
240 // System.out.println("pingggggggggggg");
244 public void updateHeart(JaceInterface stub) throws RemoteException {
245 System.out.println("I change to ping a Daemon");
246 HeartBeatThread.Instance().setServer((Object) stub);
249 public void updateHeart(JaceSuperNodeInterface stub) throws RemoteException {
250 System.out.println("I change to ping a superNode");
251 HeartBeatThread.Instance().setServer((Object) stub);
254 public long beating(JaceInterface workerStub) throws RemoteException {
255 Node noeud = Register.Instance().getNodeOfStub(workerStub);
257 noeud.setAliveFlag(true);
258 noeud.setAliveTime();
259 // System.out.println("beating$$$$$$$$$");
260 return noeud.getAliveTime();
263 // System.out.println("le noeud " + workerIP +
264 // " est pas ds la liste des noeuds connectes");
269 public void setScanning(boolean bool) throws RemoteException {
272 ScanThread.Instance().setScanning(bool);
273 synchronized (ScanThread.Instance()) {
274 ScanThread.Instance().notify();
276 } catch (Exception e) {
277 System.err.println("Error in setScanning: " + e);
279 // System.out.println("before notify!!!!!!!!!");
280 // try{ScanThread.Instance().notify();}
281 // catch(Exception e){
282 // System.out.println("error in notify:"+e);
284 // System.out.println("notify!!!!!!!!!");
287 // ScanThread.Instance().setScanning(false);
290 class InitiateAppli extends Thread {
293 public InitiateAppli(int req) {
298 BackupsManager.Instance().initialize(req);
303 class ReinitDaemon extends Thread {
305 public ReinitDaemon() {
309 JaceDaemon.Instance().reinitDaemon();