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 boolean someempty = false;
37 for(InterpreterDock d : docks.values()) {
38 if (!d.isInputDock()) continue;
39 if (d.flushing) someflushing = true;
40 else allflushing = false;
41 if (!d.flushing && !d.dataReadyForShip) someempty = true;
44 for(InterpreterDock d : docks.values())
48 } else if (someflushing && !someempty) {
49 for(InterpreterDock d : docks.values())
50 if (d.isInputDock() && !d.flushing && d.dataReadyForShip) {
51 System.out.println("FLUSH AT " + this);
52 d.dataReadyForShip = false;
56 // now pass control to the subclass
61 for(InterpreterDock p : docks.values())
65 public Interpreter getInterpreter() { return (Interpreter)getFleet(); }