* @since JDK1.5011
*/
-public class Process extends Thread
+public abstract class Process extends Thread
{
/**
* This attribute represents a bind between a java process object and
* The arguments of the method function of the process.
*/
public Vector args;
+
+ /* process synchronisation tools */
+ protected Sem schedBegin, schedEnd;
/**
* Default constructor. (used in ApplicationHandler to initialize it)
this.name = null;
this.bind = 0;
this.args = new Vector();
+ schedBegin = new Sem(0);
+ schedEnd = new Sem(0);
}
if (name==null)
throw new NullPointerException("Process name cannot be NULL");
-
- this.args.addAll(Arrays.asList(args));
+
+
+ this.args = new Vector();
+
+ if(null != args)
+ this.args.addAll(Arrays.asList(args));
+
this.name = name;
this.id = nextProcessId++;
+
+ schedBegin = new Sem(0);
+ schedEnd = new Sem(0);
Msg.processCreate(this,host);
}
public synchronized void run() {
try {
- String[] args; /* do not fill it before the signal or this.args will be empty */
+ String[] args = null; /* do not fill it before the signal or this.args will be empty */
- waitSignal(); /* wait for other people to fill the process in */
-
- args = new String[this.args.size()];
- this.args.toArray(args);
+ //waitSignal(); /* wait for other people to fill the process in */
+
+
+ try {
+ schedBegin.acquire();
+ } catch(InterruptedException e) {
+ }
+
+
+
+ if(this.args.size() > 0)
+ {
+
+ args = new String[this.args.size()];
+ this.args.toArray(args);
+ }
- Msg.info("["+this.name+"/"+this.getHost().getName()+"] Start");
this.main(args);
Msg.processExit(this);
+ schedEnd.release();
} catch (MsgException e) {
e.printStackTrace();
Msg.info("Unexpected behavior. Stopping now");
* @exception JniException on JNI madness
*/
private void waitSignal() throws JniException{
- Msg.waitSignal(this);
+ Msg.waitSignal(this);
+ unschedule();
}
/**
- * The main function of the process (to override).
- */
-
- public void main(String[] args) throws MsgException {
-
- // TODO
- // ALL DERIVED CLASS OF THIS CLASS MUST OVERRIDE THIS METHOD
- }
+ * The main function of the process (to implement).
+ */
+ public abstract void main(String[] args)
+ throws JniException, NativeException;
+
+
+ public void unschedule() {
+
+ try {
+ schedEnd.release();
+ schedBegin.acquire();
+ } catch(InterruptedException e){
+
+ }
+ }
+ public void schedule() {
+
+ try {
+ schedBegin.release();
+ schedEnd.acquire();
+ } catch(InterruptedException e) {
+
+ }
+ }
+
+ public void taskSend(Channel channel,Task task, Host host) throws NativeException, JniException {
+ Msg.channelPut(channel,task,host);
+ }
+
+ public Task taskReceive(Channel channel) throws NativeException, JniException {
+ return Msg.channelGet(channel);
+ }
}
+
+