1 package edu.berkeley.fleet;
3 import edu.berkeley.sbp.*;
4 import edu.berkeley.sbp.chr.*;
5 import edu.berkeley.sbp.misc.*;
6 import edu.berkeley.sbp.meta.*;
7 import edu.berkeley.sbp.bind.*;
8 import edu.berkeley.sbp.util.*;
12 public abstract class Ship {
14 HashMap<String,Inbox> inboxes = new HashMap<String,Inbox>();
15 HashMap<String,Outbox> outboxes = new HashMap<String,Outbox>();
17 protected Fleet fleet;
19 /** You should instantiate a bunch of Inboxes and Outboxes in your constructor */
20 public Ship(Fleet fleet, String name) {
23 fleet.ships.put(name, this);
26 public String toString() { return name; }
29 * Override this method, check inboxes for the data you need, and
30 * if you find it, deposit results in an outbox; we'll take care
33 public abstract void service();
35 public final void _service() {
36 for(Outbox ob : outboxes.values()) {
37 if (!ob.data.isEmpty() && !ob.destination.isEmpty()) {
38 int data = ob.data.remove();
39 Inbox destination = ob.destination.remove();
40 destination.add(data);
41 System.out.println("data: " + ob + " ----("+data+")----> " + destination);
49 private Queue<Integer> queue = new LinkedList<Integer>();
50 public boolean empty() { return queue.isEmpty(); }
51 public void add(int data) { queue.add(data); }
52 public int remove() { return queue.remove(); }
53 public String toString() { return Ship.this.name+"."+name; }
54 public Inbox(String name) {
56 Ship.this.inboxes.put(name, this);
62 public Queue<Integer> data = new LinkedList<Integer>();
63 public Queue<Inbox> destination = new LinkedList<Inbox>();
64 public void add(int data) { this.data.add(data); }
65 public void flush() { data.clear(); /* FIXME: risky */ }
66 public void addDestination(Inbox destination) { this.destination.add(destination); }
67 public boolean empty() { return data.isEmpty(); }
68 public String toString() { return Ship.this.name+"."+name; }
69 public Outbox(String name) {
71 Ship.this.outboxes.put(name, this);