1 package edu.berkeley.fleet;
2 import static edu.berkeley.fleet.Instruction.IgnoreCopyTake.*;
4 public class OutboxPort extends InstructionPort {
6 public OutboxPort(Ship ship, String name) {
10 // data in from the ship
11 private boolean empty = true;
14 public boolean empty() { return empty; }
16 /** number of tokens queued on the trigger input */
17 private int trigger = 0;
18 public void addToken() { trigger++; }
20 public void addData(int data) {
22 throw new RuntimeException("tried to add data to a non-empty outbox! you have a buggy ship!");
27 public boolean service(Instruction instruction) {
29 // if no instruction waiting, do nothing
30 if (instruction == null) return false;
32 // check firing conditions
33 if (instruction.trigger && trigger <= 0) return false;
34 if (instruction.dataIn != IGNORE && empty) return false;
36 // consume inbound data+token
37 if (instruction.trigger) trigger--;
39 switch(instruction.dataIn) {
49 if (instruction.dataOut) {
50 Port port = instruction.destination.resolve(getShip().getFleet());
51 Log.data(data+"", this, port);
55 throw new RuntimeException("outboxes may not send acks!");