total overhaul: fleetcode-1.0 api finished
[fleet.git] / src / edu / berkeley / fleet / api / FleetProcess.java
1 package edu.berkeley.fleet.api;
2 import java.io.*;
3 import java.util.*;
4
5 /**
6  *  Represents a <i>running</i> "slave" fleet with debugging
7  *  facilities controlled by the "master" JVM.
8  *
9  *  <p>Each Fleet which supports this API must include:
10  *  <ul><li> The ability to dispatch instructions from the master, "on
11  *           the fly".
12  *      <li> A "debug.in" dock such that any words delivered there
13  *           are sent back to the master.
14  *  </ul>
15  */
16 public abstract class FleetProcess {
17
18     private boolean terminated = false;
19
20     /** dispatch an instruction */
21     public abstract void dispatchInstruction(Instruction i);
22
23     /** the dock used to read back data from the slave */
24     public abstract Dock getDebugInputDock();
25
26     /** returns the next word delivered at the dock specified by <tt>getDebugInputDock()</tt> */
27     public abstract BitVector readWord();
28
29     /** Terminate the process; subclasses may be assured that this will be called exactly once. */
30     protected abstract void _terminate();
31
32     public final synchronized void terminate() {
33         if (terminated) return;
34         terminated = true;
35         _terminate();
36     }
37
38     public final boolean isTerminated() { return terminated; }
39     public synchronized void finalize() { terminate(); }
40 }