3 import java.io.ByteArrayInputStream;
4 import java.io.ObjectInputStream;
5 import java.util.Vector;
9 public class TaskLauncher {
19 @SuppressWarnings({ "unchecked", "static-access" })
20 public void loadOrReloadTask(Backup b, Backup bConvg) {
21 String appliName = Register.Instance().getAppliName();
22 System.out.println("appliName=" + appliName);
24 BackupConvg tskConvg = new BackupConvg();
25 // parse the file:/path and transform the .class of the user in java
28 c = load.load(appliName);
30 // instanciate the appli (the .class of the user) and load it
31 tsk = ((Task) c.newInstance());
32 } catch (Exception e) {
33 System.err.println("Unable to instanciate the class :" + e);
37 byte[] tab = b.getData();
38 // System.out.println("size of the byte array : " + tab.length +
41 // convert the stream received in an object of the same type of
42 // the user class, that inherits from Tasks (but is not such
43 // generic as a simple Task object)
45 ObjectInputStream stream = new ObjectInputStream(
46 new ByteArrayInputStream(tab));
47 tsk = tsk.jaceP2P_ConvertStream(stream);
50 } catch (Exception e) {
52 .println("JaceP2P_Error ds TaskLauncher.loadOrReloadTask() "
53 + "when converting the stream in Task : "
57 TaskId id = Register.Instance().getListeOfTasks()
58 .getTaskIdOfHostStub(LocalHost.Instance().getStub());
59 // assign the attributes of the Task object :
60 tsk.setId(id); // assign JaceMyId, jaceTaskId, jaceSize
61 tsk.setParam(Register.Instance().getParams()); // assign
64 System.out.println("No backup");
67 // insert Task in taskObject, the attribute of the JaceSession class
68 JaceSession.Instance().addTaskObject(tsk);
69 // System.out.println("After add task");
72 int it = b.getIteration();
74 System.out.println("timeStep=" + tsk.timeStep);
76 // reinit the Task object as it was overloaded by the user in
79 int itConv = bConvg.getIteration();
81 byte[] tab1 = bConvg.getData();
82 ObjectInputStream stream = new ObjectInputStream(
83 new ByteArrayInputStream(tab1));
84 tskConvg = (BackupConvg) stream.readObject();
85 if (tskConvg.timeStep >= tsk.timeStep) {
86 System.out.println("state=" + tskConvg.state);
87 tsk.state = tskConvg.state;
88 tsk.nb_not_recv = tskConvg.nb_not_recv;
89 tsk.electedNode = tskConvg.electedNode;
90 tsk.respSent = tskConvg.respSent;
91 // System.out.println("avant la copie des vecteurs");
92 tsk.neighbors = (Vector) (tskConvg.neighbors)
95 tsk.neighborsValues = (Vector) (tskConvg.neighborsValues)
97 if (bConvg.getIteration() >= b.getIteration())
98 tsk.reduceAll = (Vector) (tskConvg.reduceAll)
100 tsk.resp = (Vector) (tskConvg.resp).clone();
101 // System.out.println("apres la copie des vecteurs");
102 tsk.underTh = tskConvg.underTh;
103 tsk.verifNum = tskConvg.verifNum;
104 tsk.sendId = tskConvg.sendId;
105 tsk.finalStep = tskConvg.finalStep;
106 tsk.action = tskConvg.action;
107 tsk.verdict = tskConvg.verdict;
108 tsk.localCV_state = tskConvg.localCV_state;
109 tsk.timeStep = tskConvg.timeStep;
110 tsk.lastSave = tskConvg.lastSave;
112 // tsk.jaceP2P_Iteration=tskConvg.jaceP2P_Iteration;
113 tsk.recievedVerdict = tskConvg.recievedVerdict;
118 System.out.println("Reinit Task");
119 tsk.jaceP2P_ReinitTask();
120 tsk.postReloading = true;
121 tsk.reloading = false;
123 // initialize the task with the appli specific data (Method
124 // jaceP2P_InitTask() overloaded in the appli code by the user)
125 // System.out.println("Before Init task");
127 tsk.jaceP2P_InitTask();
128 // System.out.println("After Init task");
131 if (LocalHost.Instance().getStartedThreads() == false) {
132 // create the thread Sender (only 1 Sender thread per node, even
133 // if several tasks like in Jace) which is the thread
135 // for sending messages stored in JaceBuffer (the queue of
137 if (JaceDaemon.Instance().getProtocol().equals("rmi")) {
138 Sender.setInstance(SenderRmi.Instance());
139 SenderRmi.Instance().start();
142 Sender.setInstance(SenderSocket.Instance());
143 SenderSocket.Instance().start();
146 ScanThread.Instance().start();
147 LocalHost.Instance().setStartedThreads(true);
150 // Create the computing thread (the thread of the Task object) and
152 Thread th = new Thread(tsk, new String().valueOf(tsk.jaceMyId));
155 // keep this thread in an attribute of JaceSession (taskThread)
156 JaceSession.Instance().addTaskThread(th);
158 Thread.currentThread().yield();
160 } catch (Exception e) {
161 System.err.println("Problem in TaskLauncher.loadOrReloadTask() : " + e);
162 e.printStackTrace(System.out);