2 package edu.berkeley.fleet.interpreter;
3 import edu.berkeley.fleet.api.*;
4 import edu.berkeley.fleet.two.*;
8 /** a ship, which belongs to a fleet and which may have many docks */
9 abstract class InterpreterShip extends FleetTwoShip {
11 LinkedHashMap<String,InterpreterDock> docks = new LinkedHashMap<String,InterpreterDock>();
13 /** You should instantiate a bunch of Inboxes and Outboxes in your constructor */
14 public InterpreterShip(Interpreter fleet, ShipDescription sd) {
18 public Iterator<Dock> iterator() {
19 return (Iterator<Dock>)(Object)docks.values().iterator();
23 * Override this method, check inboxes for the data you need, and
24 * if you find it, deposit results in an outbox; we'll take care
27 public abstract void service();
29 public final void _service() {
31 // service all the docks
32 for(InterpreterDock p : docks.values()) p.service();
34 // flushing logic (must come between dock servicing and subclass)
35 boolean someflushing = false;
36 boolean allflushing = true;
37 boolean someempty = false;
38 for(InterpreterDock d : docks.values()) {
39 if (!d.isInputDock()) continue;
40 if (d.flushing) someflushing = true;
41 else allflushing = false;
42 if (!d.flushing && !d.dataReadyForShip) someempty = true;
44 if (allflushing && someflushing) {
45 for(InterpreterDock d : docks.values())
49 } else if (someflushing && !someempty) {
50 for(InterpreterDock d : docks.values())
51 if (d.isInputDock() && !d.flushing && d.dataReadyForShip)
52 d.dataReadyForShip = false;
55 // now pass control to the subclass
60 for(InterpreterDock p : docks.values())
64 public Interpreter getInterpreter() { return (Interpreter)getFleet(); }