1 package edu.berkeley.fleet.interpreter;
2 import edu.berkeley.fleet.api.*;
3 import edu.berkeley.fleet.two.*;
7 /** a ship, which belongs to a fleet and which may have many docks */
8 abstract class InterpreterShip extends FleetTwoShip {
10 LinkedHashMap<String,InterpreterDock> docks = new LinkedHashMap<String,InterpreterDock>();
12 /** You should instantiate a bunch of Inboxes and Outboxes in your constructor */
13 public InterpreterShip(Interpreter fleet, ShipDescription sd) {
17 public Iterator<Dock> iterator() {
18 return (Iterator<Dock>)(Object)docks.values().iterator();
22 * Override this method, check inboxes for the data you need, and
23 * if you find it, deposit results in an outbox; we'll take care
26 public abstract void service();
28 public final void _service() {
30 // service all the docks
31 for(InterpreterDock p : docks.values()) p.service();
33 // flushing logic (must come between dock servicing and subclass)
34 boolean someflushing = false;
35 boolean allflushing = true;
36 for(InterpreterDock d : docks.values()) {
37 if (!d.isInputDock()) continue;
38 if (d.flushing) someflushing = true;
39 else allflushing = false;
42 for(InterpreterDock d : docks.values())
46 } else if (someflushing) {
47 for(InterpreterDock d : docks.values())
48 if (d.isInputDock() && !d.flushing && d.dataReadyForShip)
49 d.dataReadyForShip = false;
52 // now pass control to the subclass
57 for(InterpreterDock p : docks.values())
61 public Interpreter getInterpreter() { return (Interpreter)getFleet(); }