initial commit
[fleet.git] / src / edu / berkeley / fleet / Fleet.java
1 package edu.berkeley.fleet;
2
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.*;
9 import java.util.*;
10 import java.io.*;
11
12 public class Fleet {
13
14     /** some "halt ship" can turn this on to stop the interpreter */
15     public boolean halt = false;
16
17     public int[] mem = new int[0];
18     public ArrayList<String> imports = new ArrayList<String>();
19
20     public HashMap<String,Ship> ships = new HashMap<String,Ship>();
21
22     public void go() {
23         while(!halt)
24             for(Ship ship : ships.values())
25                 ship._service();
26     }
27
28     public Ship.Inbox getInbox(String ship, String port) {
29         Ship s = ships.get(ship);
30         if (s == null) throw new RuntimeException("unknown ship \""+ship+"\"");
31         Ship.Inbox ret = s.inboxes.get(port);
32         if (ret == null) throw new RuntimeException("unknown port \""+ship+"."+port+"\"");
33         return ret;
34     }
35
36     public Ship.Outbox getOutbox(String ship, String port) {
37         Ship s = ships.get(ship);
38         if (s == null) throw new RuntimeException("unknown ship \""+ship+"\"");
39         Ship.Outbox ret = s.outboxes.get(port);
40         if (ret == null) throw new RuntimeException("unknown port \""+ship+"."+port+"\"");
41         return ret;
42     }
43
44
45 }