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();
44 public synchronized int updateRegister(Register newReg,
45 JaceInterface voisinStub, int req) throws RemoteException {
47 // If beginning of appli, tell nodes to beat the next neighbor
48 // and no longer the SuperNode
50 System.out.println("I change to ping a Daemon");
51 HeartBeatThread.Instance().setServer((Object) voisinStub);
53 Calendar cal = new GregorianCalendar();
54 System.out.println("at time=" + cal.get(Calendar.MINUTE) + ":"
55 + cal.get(Calendar.SECOND));
56 System.out.println("name of spawner: "
57 + newReg.getSpawnerStub().getName());
58 // 1 - replace the old Register by the new one
59 System.out.println(" \n\n NEW REGISTER \n\n");
60 // if(Register.Instance().getVersion()<=newReg.getVersion()){
61 System.out.println("Replacing Register ...");
62 Register.Instance().replaceBy(newReg);
63 Register.Instance().viewAll();
66 // initialise the BackupsManager if not exists (i.e. myRank = -1)
67 // which means that not init so first reload
69 // if (BackupsManager.Instance().getMyRank() == -1) {
70 // 1 - create the BackupsManager
71 // 2 - get an eventual Backup for my Task
72 // 3 - restart it if any
73 // BackupsManager.Instance().initialize();
75 new InitiateAppli(req).start();
80 public void updateRegister(Node oldNode, Node node) throws RemoteException {
83 // HeartBeatThread.Instance().setServer((Object)node.getStub());
84 // 1 - replace the old Register by the new one
85 Calendar cal = new GregorianCalendar();
86 System.out.println("at time=" + cal.get(Calendar.MINUTE) + ":"
87 + cal.get(Calendar.SECOND));
88 System.out.println("Modify REGISTER");
90 // System.out.println("blablablablabalablablabalbalab");
91 System.out.println("oldName=" + oldNode.getName());
92 boolean b = Register.Instance().removeNodeOfName(oldNode.getName());
94 System.out.println("removed old Node!!!!!");
96 System.out.println("didn't find old Node!!!!");
98 Register.Instance().addNode(node);
99 Register.Instance().viewAll();
100 TaskId myTaskId = null;
101 myTaskId = Register.Instance().getListeOfTasks()
102 .getTaskIdOfHostStub(oldNode.getStub());
103 myTaskId.setHostIP(node.getIP());
104 myTaskId.setHostName(node.getName());
105 // Register.Instance().setVersion(version);
106 myTaskId.setHostStub(node.getStub());
108 } catch (Exception e) {
109 System.err.println("Error in updateregister :" + e);
110 // e.printStackTrace();
114 public Vector<?> getIterationOfBackup(int remoteRank, int tag)
115 throws RemoteException {
116 Backup b = BackupsManager.Instance().getBackupTaskOfRank(remoteRank,
118 Vector<?> result = b.getIterationStep();
122 public Backup getRemoteBackup(int remoteRank, int tag)
123 throws RemoteException {
124 Backup b = BackupsManager.Instance().getBackupTaskOfRank(remoteRank,
129 public void suicide(String debugMsg) throws RemoteException {
130 // System.out.println("suiciiiiiiiiiiiide : "/* + debugMsg */);
131 new ReinitDaemon().start();
134 public void iSendYou(Message msg) throws RemoteException {
135 // on met le Message ds le MsgQueue correspondant ma tache
136 // DS CAS ASYNC, on supprime un msg de meme tag ET meme sender
137 // System.out.println("get msg from MSGQueue sent from "+msg.getSender().getRank());
138 MsgQueue.Instance().add(msg);
141 public int getTimeStep() throws RemoteException {
142 return JaceSession.Instance().getTaskObject().timeStep;
145 public void saveTask(int rank, byte[] tsk, int iteration, int timeStep,
146 String appliName, int tag) throws RemoteException {
148 while (JaceSession.Instance().getTaskObject().reloading == true)
151 } catch (Exception e) {
153 Backup back = BackupsManager.Instance().getBackupTaskOfRank(rank, tag);
155 if (back.getStep() < timeStep
156 || (back.getStep() == timeStep && back.getIteration() < iteration)) {
157 back.setIteration(iteration);
158 // System.out.print("\n\n they put in me a backup with iter="+back.getIteration()+" for the node of rank="+rank+"\n\n");
159 back.setStep(timeStep);
165 * TaskId recev=null; recev =
166 * Register.Instance().getListeOfTasks().getTaskIdOfRank(rank);
167 * JaceInterface stub; stub=recev.getHostStub();
168 * stub.setSaved(true);
170 * }catch(Exception e){
171 * System.out.println("unable to acknowledge receiving the backup :"
176 System.out.println("No task at this rank");
177 // TODO : what to do ?
182 public void setSaved(boolean bool) throws RemoteException {
183 JaceSession.Instance().getTaskObject().setSaved(bool);
186 public boolean getReloading() throws RemoteException {
187 return JaceSession.Instance().getTaskObject().reloading;
190 public int getVerifNum() throws RemoteException {
191 return JaceSession.Instance().getTaskObject().verifNum;
194 public String getState() throws RemoteException {
195 return JaceSession.Instance().getTaskObject().state;
198 public void initializeVerif(int tag) throws RemoteException {
199 JaceSession.Instance().getTaskObject().initializeVerif(tag);
202 public void savOrFinOrRest(int tag, int step, boolean verd,
203 Vector<?> recievedValue) throws RemoteException {
204 JaceSession.Instance().getTaskObject().savOrFinOrRest(tag, step, verd,
208 public synchronized boolean setNbNeighboursNotConv(int tag, int idNeigh,
209 int neighborTimeStep) throws RemoteException {
210 return JaceSession.Instance().getTaskObject().setNbNeighboursNotConv(
211 tag, idNeigh, neighborTimeStep);
214 public synchronized int getNbNeighboursNotConv() throws RemoteException {
215 return JaceSession.Instance().getTaskObject().nb_not_recv;
218 public synchronized void response(int neighId, int tag, int response,
219 Vector<?> recievedValue) throws RemoteException {
220 JaceSession.Instance().getTaskObject().response(neighId, tag, response,
224 public boolean ping() throws RemoteException {
225 // System.out.println("pingggggggggggg");
229 public void updateHeart(JaceInterface stub) throws RemoteException {
230 System.out.println("I change to ping a Daemon");
231 HeartBeatThread.Instance().setServer((Object) stub);
234 public void updateHeart(JaceSuperNodeInterface stub) throws RemoteException {
235 System.out.println("I change to ping a superNode");
236 HeartBeatThread.Instance().setServer((Object) stub);
239 public long beating(JaceInterface workerStub) throws RemoteException {
240 Node noeud = Register.Instance().getNodeOfStub(workerStub);
242 noeud.setAliveFlag(true);
243 noeud.setAliveTime();
244 // System.out.println("beating$$$$$$$$$");
245 return noeud.getAliveTime();
248 // System.out.println("le noeud " + workerIP +
249 // " est pas ds la liste des noeuds connectes");
254 public void setScanning(boolean bool) throws RemoteException {
257 ScanThread.Instance().setScanning(bool);
258 synchronized (ScanThread.Instance()) {
259 ScanThread.Instance().notify();
261 } catch (Exception e) {
262 System.err.println("Error in setScanning: " + e);
264 // System.out.println("before notify!!!!!!!!!");
265 // try{ScanThread.Instance().notify();}
266 // catch(Exception e){
267 // System.out.println("error in notify:"+e);
269 // System.out.println("notify!!!!!!!!!");
272 // ScanThread.Instance().setScanning(false);
275 class InitiateAppli extends Thread {
278 public InitiateAppli(int req) {
283 BackupsManager.Instance().initialize(req);
288 class ReinitDaemon extends Thread {
290 public ReinitDaemon() {
294 JaceDaemon.Instance().reinitDaemon();