total overhaul: fleetcode-1.0 api finished
[fleet.git] / src / edu / berkeley / fleet / interpreter / InterpreterShip.java
1 package edu.berkeley.fleet.interpreter;
2 import edu.berkeley.fleet.api.*;
3 import edu.berkeley.fleet.two.*;
4 import java.util.*;
5 import java.io.*;
6
7 /** a ship, which belongs to a fleet and which may have many ports */
8 abstract class InterpreterShip extends FleetTwoShip {
9         
10     /** You should instantiate a bunch of Inboxes and Outboxes in your constructor */
11     public InterpreterShip(Interpreter fleet, String name, ShipDescription sd) {
12         super(fleet, sd);
13     }
14
15     private HashMap<String,InterpreterDock> ports = new HashMap<String,InterpreterDock>();
16
17     public Iterator<Dock> iterator() { return (Iterator<Dock>)(Object)ports.values().iterator(); }
18     public Interpreter        getInterpreter() { return (Interpreter)getFleet(); }
19
20     /**
21      *  Override this method, check inboxes for the data you need, and
22      *  if you find it, deposit results in an outbox; we'll take care
23      *  of the rest.
24      */
25     public abstract void service();
26
27     public final void _service() {
28         for(InterpreterDock p : ports.values()) p.service();
29         service();
30     }
31
32     protected void addDock(String name, InterpreterDock port) {
33         ports.put(name, port);
34     }
35
36     public void shutdown() {
37         for(InterpreterDock p : ports.values())
38             p.shutdown();
39     }
40 }