+
package edu.berkeley.fleet.interpreter;
import edu.berkeley.fleet.api.*;
-import edu.berkeley.fleet.doc.*;
+import edu.berkeley.fleet.two.*;
import java.util.*;
import java.io.*;
-/** a ship, which belongs to a fleet and which may have many ports */
-abstract class InterpreterShip extends Ship {
+/** a ship, which belongs to a fleet and which may have many docks */
+abstract class InterpreterShip extends FleetTwoShip {
+ LinkedHashMap<String,InterpreterDock> docks = new LinkedHashMap<String,InterpreterDock>();
+
/** You should instantiate a bunch of Inboxes and Outboxes in your constructor */
- public InterpreterShip(Interpreter fleet, String name, String type) {
- this.fleet = fleet;
- this.type = type;
+ public InterpreterShip(Interpreter fleet, ShipDescription sd) {
+ super(fleet, sd);
}
- private Interpreter fleet;
- private String type;
- private HashMap<String,InterpreterPump> ports = new HashMap<String,InterpreterPump>();
-
- public Iterable<Pump> getPumps() { return (Iterable<Pump>)(Object)ports.values(); }
- public String getType() { return type; }
- public Fleet getFleet() { return fleet; }
- public Interpreter getInterpreter() { return fleet; }
-
- public void setShipDescription(ShipDescription sd) {
- for(InterpreterPump ibb : ports.values()) {
- for(PumpDescription bbd : sd) {
- if (bbd.getName().equals(ibb.getName()))
- ibb.setDescription(bbd);
- }
- }
+ public Iterator<Dock> iterator() {
+ return (Iterator<Dock>)(Object)docks.values().iterator();
}
/**
public abstract void service();
public final void _service() {
- for(InterpreterPump p : ports.values()) p.service();
+
+ // service all the docks
+ for(InterpreterDock p : docks.values()) p.service();
+
+ // flushing logic (must come between dock servicing and subclass)
+ boolean someflushing = false;
+ boolean allflushing = true;
+ boolean someempty = false;
+ for(InterpreterDock d : docks.values()) {
+ if (!d.isInputDock()) continue;
+ if (d.flushing) someflushing = true;
+ else allflushing = false;
+ if (!d.flushing && !d.dataReadyForShip) someempty = true;
+ }
+ if (allflushing && someflushing) {
+ for(InterpreterDock d : docks.values())
+ if (d.isInputDock())
+ d.flushing = false;
+ return;
+ } else if (someflushing && !someempty) {
+ for(InterpreterDock d : docks.values())
+ if (d.isInputDock() && !d.flushing && d.dataReadyForShip)
+ d.dataReadyForShip = false;
+ }
+
+ // now pass control to the subclass
service();
}
- protected void addPump(String name, InterpreterPump port) {
- ports.put(name, port);
+ public void reset() {
+ for(InterpreterDock p : docks.values())
+ p.reset();
}
- public void shutdown() {
- for(InterpreterPump p : ports.values())
- p.shutdown();
- }
+ public Interpreter getInterpreter() { return (Interpreter)getFleet(); }
}