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 // @SuppressWarnings("unused")
38 // JaceSpawner spawner = new JaceSpawner(params, appliName, reg, nbTasks,
39 // snodeStub, rank, heartTime, tag, nbdc, nbsdc,
40 // nbDaemonPerSpawner, nbDaemonPerThread);
41 HeartBeatThread.Instance().kill();
42 return Register.Instance().getSpawnerStub();
45 public synchronized int updateRegister(Register newReg,
46 JaceInterface voisinStub, int req) throws RemoteException {
48 // If beginning of appli, tell nodes to beat the next neighbor
49 // and no longer the SuperNode
51 System.out.println("I change to ping a Daemon");
52 HeartBeatThread.Instance().setServer((Object) voisinStub);
54 Calendar cal = new GregorianCalendar();
55 System.out.println("at time=" + cal.get(Calendar.MINUTE) + ":"
56 + cal.get(Calendar.SECOND));
57 System.out.println("name of spawner: "
58 + newReg.getSpawnerStub().getName());
59 // 1 - replace the old Register by the new one
60 System.out.println(" \n\n NEW REGISTER \n\n");
61 // if(Register.Instance().getVersion()<=newReg.getVersion()){
62 System.out.println("replacing Register !!!!!!$$$$$$$$******");
63 Register.Instance().replaceBy(newReg);
64 Register.Instance().viewAll();
67 // initialise the BackupsManager if not exists (i.e. myRank = -1)
68 // which means that not init so first reload
70 // if (BackupsManager.Instance().getMyRank() == -1) {
71 // 1 - create the BackupsManager
72 // 2 - get an eventual Backup for my Task
73 // 3 - restart it if any
74 // BackupsManager.Instance().initialize();
76 new InitiateAppli(req).start();
81 public void updateRegister(Node oldNode, Node node) throws RemoteException {
84 // HeartBeatThread.Instance().setServer((Object)node.getStub());
85 // 1 - replace the old Register by the new one
86 Calendar cal = new GregorianCalendar();
87 System.out.println("at time=" + cal.get(Calendar.MINUTE) + ":"
88 + cal.get(Calendar.SECOND));
89 System.out.println("Modify REGISTER");
91 // System.out.println("blablablablabalablablabalbalab");
92 System.out.println("oldName=" + oldNode.getName());
93 boolean b = Register.Instance().removeNodeOfName(oldNode.getName());
95 System.out.println("removed old Node!!!!!");
97 System.out.println("didn't find old Node!!!!");
99 Register.Instance().addNode(node);
100 Register.Instance().viewAll();
101 TaskId myTaskId = null;
102 myTaskId = Register.Instance().getListeOfTasks()
103 .getTaskIdOfHostStub(oldNode.getStub());
104 myTaskId.setHostIP(node.getIP());
105 myTaskId.setHostName(node.getName());
106 // Register.Instance().setVersion(version);
107 myTaskId.setHostStub(node.getStub());
109 } catch (Exception e) {
110 System.out.println("error in updateregister :" + e);
111 // e.printStackTrace();
115 public Vector<?> getIterationOfBackup(int remoteRank, int tag)
116 throws RemoteException {
117 Backup b = BackupsManager.Instance().getBackupTaskOfRank(remoteRank,
119 Vector<?> result = b.getIterationStep();
123 public Backup getRemoteBackup(int remoteRank, int tag)
124 throws RemoteException {
125 Backup b = BackupsManager.Instance().getBackupTaskOfRank(remoteRank,
130 public void suicide(String debugMsg) throws RemoteException {
131 System.out.println("suiciiiiiiiiiiiide : "/* + debugMsg */);
132 new ReinitDaemon().start();
135 public void iSendYou(Message msg) throws RemoteException {
136 // on met le Message ds le MsgQueue correspondant ma tache
137 // DS CAS ASYNC, on supprime un msg de meme tag ET meme sender
138 // System.out.println("get msg from MSGQueue sent from "+msg.getSender().getRank());
139 MsgQueue.Instance().add(msg);
142 public int getTimeStep() throws RemoteException {
143 return JaceSession.Instance().getTaskObject().timeStep;
146 public void saveTask(int rank, byte[] tsk, int iteration, int timeStep,
147 String appliName, int tag) throws RemoteException {
149 while (JaceSession.Instance().getTaskObject().reloading == true)
152 } catch (Exception e) {
154 Backup back = BackupsManager.Instance().getBackupTaskOfRank(rank, tag);
156 if (back.getStep() < timeStep
157 || (back.getStep() == timeStep && back.getIteration() < iteration)) {
158 back.setIteration(iteration);
159 // System.out.print("\n\n they put in me a backup with iter="+back.getIteration()+" for the node of rank="+rank+"\n\n");
160 back.setStep(timeStep);
166 * TaskId recev=null; recev =
167 * Register.Instance().getListeOfTasks().getTaskIdOfRank(rank);
168 * JaceInterface stub; stub=recev.getHostStub();
169 * stub.setSaved(true);
171 * }catch(Exception e){
172 * System.out.println("unable to acknowledge receiving the backup :"
177 System.out.println("No task at this rank");
178 // TODO : what to do ?
183 public void setSaved(boolean bool) throws RemoteException {
184 JaceSession.Instance().getTaskObject().setSaved(bool);
187 public boolean getReloading() throws RemoteException {
188 return JaceSession.Instance().getTaskObject().reloading;
191 public int getVerifNum() throws RemoteException {
192 return JaceSession.Instance().getTaskObject().verifNum;
195 public String getState() throws RemoteException {
196 return JaceSession.Instance().getTaskObject().state;
199 public void initializeVerif(int tag) throws RemoteException {
200 JaceSession.Instance().getTaskObject().initializeVerif(tag);
203 public void savOrFinOrRest(int tag, int step, boolean verd,
204 Vector<?> recievedValue) throws RemoteException {
205 JaceSession.Instance().getTaskObject().savOrFinOrRest(tag, step, verd,
209 public synchronized boolean setNbNeighboursNotConv(int tag, int idNeigh,
210 int neighborTimeStep) throws RemoteException {
211 return JaceSession.Instance().getTaskObject().setNbNeighboursNotConv(
212 tag, idNeigh, neighborTimeStep);
215 public synchronized int getNbNeighboursNotConv() throws RemoteException {
216 return JaceSession.Instance().getTaskObject().nb_not_recv;
219 public synchronized void response(int neighId, int tag, int response,
220 Vector<?> recievedValue) throws RemoteException {
221 JaceSession.Instance().getTaskObject().response(neighId, tag, response,
225 public boolean ping() throws RemoteException {
226 // System.out.println("pingggggggggggg");
230 public void updateHeart(JaceInterface stub) throws RemoteException {
231 System.out.println("I change to ping a Daemon");
232 HeartBeatThread.Instance().setServer((Object) stub);
235 public void updateHeart(JaceSuperNodeInterface stub) throws RemoteException {
236 System.out.println("I change to ping a superNode");
237 HeartBeatThread.Instance().setServer((Object) stub);
240 public long beating(JaceInterface workerStub) throws RemoteException {
241 Node noeud = Register.Instance().getNodeOfStub(workerStub);
243 noeud.setAliveFlag(true);
244 noeud.setAliveTime();
245 // System.out.println("beating$$$$$$$$$");
246 return noeud.getAliveTime();
249 // System.out.println("le noeud " + workerIP +
250 // " est pas ds la liste des noeuds connectes");
255 public void setScanning(boolean bool) throws RemoteException {
258 ScanThread.Instance().setScanning(bool);
259 synchronized (ScanThread.Instance()) {
260 ScanThread.Instance().notify();
262 } catch (Exception e) {
263 System.out.println("error in setScanning: " + e);
265 // System.out.println("before notify!!!!!!!!!");
266 // try{ScanThread.Instance().notify();}
267 // catch(Exception e){
268 // System.out.println("error in notify:"+e);
270 // System.out.println("notify!!!!!!!!!");
273 // ScanThread.Instance().setScanning(false);
276 class InitiateAppli extends Thread {
279 public InitiateAppli(int req) {
284 BackupsManager.Instance().initialize(req);
289 class ReinitDaemon extends Thread {
291 public ReinitDaemon() {
295 JaceDaemon.Instance().reinitDaemon();