update marina/testCode/.gitignore
[fleet.git] / marina / testCode / 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 token to a given destination; may be buffered */
27     public abstract void sendToken(Destination d);
28
29     /** flush all instructions, words, and tokens dispatched so far */
30     public abstract void flush();
31
32     /** the dock used to read back data from the slave */
33     public abstract Dock getDebugInputDock();
34
35     /** returns the next word delivered at the dock specified by <tt>getDebugInputDock()</tt> */
36     public abstract BitVector recvWord();
37
38     /** Terminate the process; subclasses may be assured that this will be called exactly once. */
39     protected abstract void _terminate();
40
41     /** Terminate the process. */
42     public final synchronized void terminate() {
43         if (terminated) return;
44         terminated = true;
45         _terminate();
46     }
47
48     /** Returns true if the process is terminated */
49     public final boolean isTerminated() { return terminated; }
50
51     public synchronized void finalize() { terminate(); }
52
53     /** return the Fleet that this FleetProcess controls */
54     public abstract Fleet getFleet();
55 }