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;
10 public class JaceSpawnerServer extends UnicastRemoteObject implements
11 JaceSpawnerInterface {
13 private static final long serialVersionUID = 1L;
16 boolean finished = false;
19 public JaceSpawnerServer() throws RemoteException {
23 @SuppressWarnings("unchecked")
24 public void startProcess(Vector spawnersList) throws RemoteException {
25 JaceSpawner.Instance().startProcess(spawnersList);
28 public Register getRegister(int rank) throws RemoteException {
29 return JaceSpawner.Instance().getRegister(rank);
32 public void killApplication(JaceInterface stub) throws RemoteException {
34 // Node noeud = Register.Instance().getNodeOfStub(stub);
35 // noeud.setAppliName(null);
36 // new ReconnectThread(stub,noeud.getName()).start();
37 // Register.Instance().removeNode(noeud);
40 * if (Register.Instance().getSize() < 1) { long finalTime =
41 * RunningApplication.Instance().getChrono().getValue(); int nb =
42 * RunningApplication.Instance().getNumberOfDisconnections();
43 * System.out.println("Application finished successfully !!!!!!");
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 !!!!!!\n");
52 * System.out.println("TOTAL TIME in s : " + (finalTime/1000));
53 * System.out.println("nb of desconnections : " + nb);
55 * //purger l'appli RunningApplication.Instance().purge(); }
59 public long getChronoValue(String appliName) throws RemoteException {
61 if (RunningApplication.Instance().getName().equals(appliName)) {
62 res = RunningApplication.Instance().getChrono().getValue();
63 // System.out.println("temps chrono : " + res + " ms\n");
65 System.err.println("No application of name "+appliName+" on this Spawner !");
70 public void setOver(boolean bool) throws RemoteException {
71 JaceSpawner.Instance().broadcastFinished(bool);
75 public void setFinished(boolean bool) throws RemoteException {
80 public String getName() throws RemoteException {
81 return LocalHost.Instance().getName();
84 public boolean getFinished() throws RemoteException {
88 public void signalDeadNode(JaceInterface host, int rankOfDead)
89 throws RemoteException {
90 System.out.println("SignalDeadNode of rank " + rankOfDead);
91 JaceSpawner.Instance().signalDeadNode(host, rankOfDead);
94 // heartBeat that detects if a Spawner is dead or alive
95 public void beating() throws RemoteException {
96 ScanThreadSpawner.Instance().setAliveTime();
98 // System.out.println("spawner is pinging me");
101 public synchronized void replaceBy(JaceSpawnerInterface oldStub,
102 JaceSpawnerInterface stub) throws RemoteException {
103 Calendar cal = new GregorianCalendar();
104 System.out.println("at time=" + cal.get(Calendar.MINUTE) + ":"
105 + cal.get(Calendar.SECOND));
106 System.out.println("replacing a dead spawner by another");
107 JaceSpawner.Instance().replaceBy(oldStub, stub);
108 RunningApplication.Instance().incrementNumberOfSpawnerDisconnections();
111 public void updateHeart(JaceSpawnerInterface stub) throws RemoteException {
112 HeartBeatSpawner.Instance().setServer(stub);
115 public boolean ping() throws RemoteException {
119 public synchronized void replaceDeamonBy(Node oldNode, Node node, int rank)
120 throws RemoteException {
121 Calendar cal = new GregorianCalendar();
122 System.out.println("at time=" + cal.get(Calendar.MINUTE) + ":"
123 + cal.get(Calendar.SECOND));
124 if (Register.Instance().removeNodeOfName(oldNode.getName()))
125 System.out.println("Node " + oldNode.getName() + " of rank " + rank
126 + " has been removed");
128 System.out.println("Node " + oldNode.getName() + " of rank " + rank
129 + " hasn't been removed");
133 Register.Instance().addNode(node);
135 TaskId myTaskId = Register.Instance().getListeOfTasks()
136 .getTaskIdOfHostStub(oldNode.getStub());
138 myTaskId.setHostIP(node.getIP());
140 myTaskId.setHostName(node.getName());
141 myTaskId.setHostStub(node.getStub());
142 // Register.Instance().setVersion(Register.Instance().getVersion()+1);
143 RunningApplication.Instance().incrementNumberOfDisconnections();
144 System.out.println("Replacing node: " + oldNode.getName() + " with: "
146 // Register.Instance().getListeOfTasks().viewAll();
148 System.err.println( "ReplaceDaemon: The new node is null!" ) ;
153 // public void setIdAlgo( String _s ) throws RemoteException
155 // JaceSpawner.Instance().setIdAlgo( _s ) ;