Mercurial > hg > Members > tatsuki > Alice
changeset 19:e7867328a2fb
change execute() API
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 15 Jan 2012 17:57:05 +0900 |
parents | 72dd27d952b0 |
children | 0bb03861b5cd |
files | src/alice/codesegment/CodeSegment.java src/alice/codesegment/InputDataSegment.java src/alice/datasegment/DataSegmentReceiver.java src/alice/test/codesegment/RemoteIncrement.java src/alice/test/codesegment/RemoteStartCodeSegment.java src/alice/test/codesegment/StartCodeSegment.java src/alice/test/codesegment/TestCodeSegment.java src/alice/test/codesegment/TestLocalAlice.java src/alice/test/codesegment/TestRemoteAlice.java |
diffstat | 9 files changed, 23 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/codesegment/CodeSegment.java Sun Jan 15 16:03:11 2012 +0900 +++ b/src/alice/codesegment/CodeSegment.java Sun Jan 15 17:57:05 2012 +0900 @@ -7,6 +7,10 @@ public InputDataSegment ids = new InputDataSegment(this); public OutputDataSegment ods = new OutputDataSegment(); + public void execute() { + ids.receive(); + } + public abstract void run(); }
--- a/src/alice/codesegment/InputDataSegment.java Sun Jan 15 16:03:11 2012 +0900 +++ b/src/alice/codesegment/InputDataSegment.java Sun Jan 15 17:57:05 2012 +0900 @@ -9,7 +9,8 @@ public class InputDataSegment { private CodeSegment cs; - private AtomicInteger count = new AtomicInteger(1); // for execute() + private AtomicInteger count = new AtomicInteger(1); // for no input data segments + private AtomicInteger keyCount = new AtomicInteger(0); public InputDataSegment(CodeSegment cs) { this.cs = cs; @@ -21,7 +22,6 @@ public void peek(DataSegmentReceiver receiver, String managerKey, String key, int index) { DataSegment.get(managerKey).peek(receiver, key, index, cs); - count.getAndIncrement(); } public void take(DataSegmentReceiver receiver, String managerKey, String key) { @@ -30,16 +30,26 @@ public void take(DataSegmentReceiver receiver, String managerKey, String key, int index) { DataSegment.get(managerKey).take(receiver, key, index, cs); - count.getAndIncrement(); } public void reply(DataSegmentReceiver receiver, DataSegmentValue val) { receiver.index = val.index; receiver.val = val.val; - execute(); + receive(); + } + + public void regist() { + count.getAndIncrement(); + keyCount.getAndIncrement(); } - public void execute() { + public void setKey() { + if (keyCount.decrementAndGet() == 0) { + receive(); + } + } + + public void receive() { if (count.decrementAndGet() == 0) { try { CodeSegmentManager.get().readyQueue.put(cs);
--- a/src/alice/datasegment/DataSegmentReceiver.java Sun Jan 15 16:03:11 2012 +0900 +++ b/src/alice/datasegment/DataSegmentReceiver.java Sun Jan 15 17:57:05 2012 +0900 @@ -14,6 +14,7 @@ public DataSegmentReceiver(InputDataSegment ids, CommandType type) { this.ids = ids; this.type = type; + ids.regist(); } public void setKey(String managerKey, String key) { @@ -29,6 +30,7 @@ ids.take(this, managerKey, key, index); break; } + ids.setKey(); } }
--- a/src/alice/test/codesegment/RemoteIncrement.java Sun Jan 15 16:03:11 2012 +0900 +++ b/src/alice/test/codesegment/RemoteIncrement.java Sun Jan 15 17:57:05 2012 +0900 @@ -18,7 +18,6 @@ RemoteIncrement cs = new RemoteIncrement(); cs.num.setKey("remote", "num"); - cs.ids.execute(); ods.put("local", "num", ValueFactory.createIntegerValue(num)); }
--- a/src/alice/test/codesegment/RemoteStartCodeSegment.java Sun Jan 15 16:03:11 2012 +0900 +++ b/src/alice/test/codesegment/RemoteStartCodeSegment.java Sun Jan 15 17:57:05 2012 +0900 @@ -11,7 +11,6 @@ public void run() { RemoteIncrement cs = new RemoteIncrement(); cs.num.setKey("remote", "num"); - cs.ids.execute(); Value num = ValueFactory.createIntegerValue(0); ods.put("local", "num", num);
--- a/src/alice/test/codesegment/StartCodeSegment.java Sun Jan 15 16:03:11 2012 +0900 +++ b/src/alice/test/codesegment/StartCodeSegment.java Sun Jan 15 17:57:05 2012 +0900 @@ -13,7 +13,6 @@ TestCodeSegment cs = new TestCodeSegment(); cs.arg1.setKey("local", "key1"); - cs.ids.execute(); System.out.println("create TestCodeSegment"); Value val = ValueFactory.createRawValue("String data");
--- a/src/alice/test/codesegment/TestCodeSegment.java Sun Jan 15 16:03:11 2012 +0900 +++ b/src/alice/test/codesegment/TestCodeSegment.java Sun Jan 15 17:57:05 2012 +0900 @@ -24,7 +24,6 @@ TestCodeSegment cs = new TestCodeSegment(); cs.arg1.setKey("local", "key1", arg1.index); - cs.ids.execute(); Value val = ValueFactory.createRawValue("String data"); ods.update("local", "key1", val);
--- a/src/alice/test/codesegment/TestLocalAlice.java Sun Jan 15 16:03:11 2012 +0900 +++ b/src/alice/test/codesegment/TestLocalAlice.java Sun Jan 15 17:57:05 2012 +0900 @@ -1,11 +1,8 @@ package alice.test.codesegment; -import alice.codesegment.CodeSegment; - public class TestLocalAlice { public static void main(String args[]) { - CodeSegment cs = new StartCodeSegment(); - cs.ids.execute(); + new StartCodeSegment().execute(); } }
--- a/src/alice/test/codesegment/TestRemoteAlice.java Sun Jan 15 16:03:11 2012 +0900 +++ b/src/alice/test/codesegment/TestRemoteAlice.java Sun Jan 15 17:57:05 2012 +0900 @@ -4,7 +4,6 @@ import java.net.InetSocketAddress; import java.nio.channels.SocketChannel; -import alice.codesegment.CodeSegment; import alice.daemon.AliceDaemon; import alice.daemon.Config; import alice.daemon.Connection; @@ -44,8 +43,7 @@ } } while (connect); - CodeSegment cs = new RemoteStartCodeSegment(); - cs.ids.execute(); + new RemoteStartCodeSegment().execute(); } }