Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5515dc72539a3d182a08f15cead6d718fa0b5a76
[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         public Register getRegister(int rank) throws RemoteException {
29                 return JaceSpawner.Instance().getRegister(rank);
30         }
31
32         public void killApplication(JaceInterface stub) throws RemoteException {
33
34                 // Node noeud = Register.Instance().getNodeOfStub(stub);
35                 // noeud.setAppliName(null);
36                 // new ReconnectThread(stub,noeud.getName()).start();
37                 // Register.Instance().removeNode(noeud);
38                 // nbKilled++;
39                 /*
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);
54                  * 
55                  * //purger l'appli RunningApplication.Instance().purge(); }
56                  */
57         }
58
59         public long getChronoValue(String appliName) throws RemoteException {
60                 long res = -1;
61                 if (RunningApplication.Instance().getName().equals(appliName)) {
62                         res = RunningApplication.Instance().getChrono().getValue();
63                         // System.out.println("temps chrono : " + res + " ms\n");
64                 } else {
65                         System.err.println("No application of name "+appliName+" on this Spawner !");
66                 }
67                 return res;
68         }
69
70         public void setOver(boolean bool) throws RemoteException {
71                 JaceSpawner.Instance().broadcastFinished(bool);
72
73         }
74
75         public void setFinished(boolean bool) throws RemoteException {
76                 finished = bool;
77
78         }
79
80         public String getName() throws RemoteException {
81                 return LocalHost.Instance().getName();
82         }
83
84         public boolean getFinished() throws RemoteException {
85                 return finished;
86         }
87
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);
92         }
93
94         // heartBeat that detects if a Spawner is dead or alive
95         public void beating() throws RemoteException {
96                 ScanThreadSpawner.Instance().setAliveTime();
97
98                 // System.out.println("spawner is pinging me");
99         }
100
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();
109         }
110
111         public void updateHeart(JaceSpawnerInterface stub) throws RemoteException {
112                 HeartBeatSpawner.Instance().setServer(stub);
113         }
114
115         public boolean ping() throws RemoteException {
116                 return true;
117         }
118
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");
127                 else
128                         System.out.println("Node " + oldNode.getName() + " of rank " + rank
129                                         + " hasn't been removed");
130                 Register.Instance().addNode(node);
131
132                 TaskId myTaskId = Register.Instance().getListeOfTasks()
133                                 .getTaskIdOfHostStub(oldNode.getStub());
134
135                 myTaskId.setHostIP(node.getIP());
136
137                 myTaskId.setHostName(node.getName());
138                 myTaskId.setHostStub(node.getStub());
139                 // Register.Instance().setVersion(Register.Instance().getVersion()+1);
140                 RunningApplication.Instance().incrementNumberOfDisconnections();
141                 System.out.println("Replacing node: " + oldNode.getName() + " with: "
142                                 + node.getName());
143                 // Register.Instance().getListeOfTasks().viewAll();
144         }
145
146 //      @Override
147 //      public void setIdAlgo( String _s ) throws RemoteException 
148 //      {
149 //              JaceSpawner.Instance().setIdAlgo( _s ) ;
150 //      }
151 }