FleetProcess.java: add masterClear() method, use it in Main.java
[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, words, and tokens
11  *           from the master, "on 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; may be buffered */
21     public abstract void sendInstruction(Instruction i);
22
23     /** dispatch a word to a given destination; may be buffered */
24     public abstract void sendWord(Destination d, BitVector word);
25
26     /** dispatch a word to a given destination; may be buffered */
27     public abstract void sendWord(Destination d, BitVector word, BitVector signal);
28
29     /** convenience method: sends the word to d's data destination */
30     public void sendWord(Dock d, BitVector word) { sendWord(d.getDataDestination(), word); }
31
32     /** dispatch a token to a given destination; may be buffered */
33     public abstract void sendToken(Destination d);
34
35     /** convenience method: sends a token to d's data destination */
36     public void sendToken(Dock d) { sendToken(d.getDataDestination()); }
37
38     /** convenience method: sends a token to d's instruction destination */
39     public void sendTorpedo(Dock d) { sendToken(d.getInstructionDestination()); }
40
41     /** flush all instructions, words, and tokens dispatched so far */
42     public abstract void flush();
43
44     /** the dock used to read back data from the slave */
45     public abstract Dock getDebugInputDock();
46
47     /** returns the next word delivered at the dock specified by <tt>getDebugInputDock()</tt> */
48     public abstract BitVector recvWord();
49
50     /** Terminate the process; subclasses may be assured that this will be called exactly once. */
51     protected abstract void _terminate();
52
53     public void masterClear() { throw new RuntimeException("not implemented"); }
54
55     /** Terminate the process. */
56     public final synchronized void terminate() {
57         if (terminated) return;
58         terminated = true;
59         _terminate();
60     }
61
62     /** Returns true if the process is terminated */
63     public final boolean isTerminated() { return terminated; }
64
65     public synchronized void finalize() { terminate(); }
66
67     /** return the Fleet that this FleetProcess controls */
68     public abstract Fleet getFleet();
69 }