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