fleeterpreter-countership
authormpierson <mpierson@eecs.berkeley.edu>
Sat, 9 Dec 2006 04:15:02 +0000 (05:15 +0100)
committermpierson <mpierson@eecs.berkeley.edu>
Sat, 9 Dec 2006 04:15:02 +0000 (05:15 +0100)
src/edu/berkeley/fleet/ships/CounterShip.java [new file with mode: 0644]
src/edu/berkeley/fleet/ships/FetchShip.java

diff --git a/src/edu/berkeley/fleet/ships/CounterShip.java b/src/edu/berkeley/fleet/ships/CounterShip.java
new file mode 100644 (file)
index 0000000..70f4901
--- /dev/null
@@ -0,0 +1,44 @@
+package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.*;
+
+import java.util.*;
+import java.io.*;
+
+public class CounterShip extends Ship {
+
+    private int count = -1;
+    private int loaded = 0;
+
+    TokenOutbox zero     = new TokenOutbox(this, "zero");
+    TokenOutbox positive = new TokenOutbox(this, "positive");
+    DataInbox    load     = new DataInbox(this, "load");
+    TokenInbox  ask      = new TokenInbox(this, "ask");
+
+    public CounterShip(Fleet fleet, String name) {
+        super(fleet, name);
+    }
+
+    public void service() {
+        if (!zero.readyForTokenFromShip()) return;
+        if (!positive.readyForTokenFromShip()) return;
+        if (load.dataReadyForShip()) {
+           if(loaded == 0) {
+               count = load.removeDataForShip();
+               loaded = 1;
+           }
+        }
+        if (ask.tokenReadyForShip()) {
+           if(loaded == 1) {
+               ask.removeTokenForShip();
+               if (count > 0) {
+                   count--;
+                   positive.addTokenFromShip();
+               } else if (count<=0) {
+                   zero.addTokenFromShip();
+                   loaded = 0;
+               }
+           }
+        }
+    }
+
+}
index 33ce950..fc21c93 100644 (file)
@@ -24,7 +24,7 @@ public class FetchShip extends Ship {
         CodeBag cb = CodeBag.getCodeBagByDescriptor(cbd);
         if (revoke.tokenReadyForShip()) {
             revoke.removeTokenForShip();
-            Log.print("revoking codebag: " + cb);
+            Log.print("revoking codebag: " + cb + "\n");
         } else {
             release.removeTokenForShip();
             if (cb==null)