Mercurial > hg > Members > tatsuki > Alice
changeset 57:7fa9ddb31f64
add comment
author | one |
---|---|
date | Wed, 08 Feb 2012 16:07:33 +0900 |
parents | 17f88fd202ae |
children | ebdcab7b9b04 |
files | src/alice/codesegment/CodeSegmentManager.java src/alice/codesegment/InputDataSegment.java src/alice/datasegment/CommandType.java src/alice/datasegment/DataSegmentKey.java src/alice/datasegment/LocalDataSegmentManager.java src/alice/datasegment/Receiver.java src/alice/test/codesegment/local/StartCodeSegment.java src/alice/test/codesegment/local/TestCodeSegment.java |
diffstat | 8 files changed, 49 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/codesegment/CodeSegmentManager.java Wed Feb 08 14:31:16 2012 +0900 +++ b/src/alice/codesegment/CodeSegmentManager.java Wed Feb 08 16:07:33 2012 +0900 @@ -43,5 +43,13 @@ public static CodeSegmentManager get() { return instance; } + + public static void submit(CodeSegment cs) { + try { + CodeSegmentManager.get().readyQueue.put(cs); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } }
--- a/src/alice/codesegment/InputDataSegment.java Wed Feb 08 14:31:16 2012 +0900 +++ b/src/alice/codesegment/InputDataSegment.java Wed Feb 08 16:07:33 2012 +0900 @@ -7,11 +7,17 @@ import alice.datasegment.DataSegmentValue; import alice.datasegment.Receiver; +/** + * InputDataSegment Manager + * keep tracking unbound/bound count + * @author kazz + * + */ public class InputDataSegment { private CodeSegment cs; - private AtomicInteger count = new AtomicInteger(1); // for no input data segments - private AtomicInteger keyCount = new AtomicInteger(0); + private AtomicInteger count = new AtomicInteger(1); // 1 for no input data segments + private AtomicInteger keyCount = new AtomicInteger(0); // number of DataSegments public InputDataSegment(CodeSegment cs) { this.cs = cs; @@ -53,14 +59,15 @@ public void receive() { if (count.decrementAndGet() == 0) { - try { - CodeSegmentManager.get().readyQueue.put(cs); - } catch (InterruptedException e) { - e.printStackTrace(); - } + CodeSegmentManager.submit(cs); } } + /** + * InputDataSegment factory + * @param type PEEK or TAKE + * @return Receiver of DataSegment reply + */ public Receiver create(CommandType type) { return new Receiver(this, type); }
--- a/src/alice/datasegment/CommandType.java Wed Feb 08 14:31:16 2012 +0900 +++ b/src/alice/datasegment/CommandType.java Wed Feb 08 16:07:33 2012 +0900 @@ -4,7 +4,7 @@ public enum CommandType { PUT, - UPDATE, + UPDATE, // remove a DataSegment value and put PEEK, TAKE, REMOVE,
--- a/src/alice/datasegment/DataSegmentKey.java Wed Feb 08 14:31:16 2012 +0900 +++ b/src/alice/datasegment/DataSegmentKey.java Wed Feb 08 16:07:33 2012 +0900 @@ -7,6 +7,11 @@ import alice.datasegment.Command; +/** + * Synchronized DataSegment for each DataSegment key + * @author kazz + * + */ public class DataSegmentKey { private String key;
--- a/src/alice/datasegment/LocalDataSegmentManager.java Wed Feb 08 14:31:16 2012 +0900 +++ b/src/alice/datasegment/LocalDataSegmentManager.java Wed Feb 08 16:07:33 2012 +0900 @@ -38,7 +38,11 @@ dataSegmentKey.addCommand(cmd); logger.debug(cmd.getCommandString()); } - + + + /** + * Enqueue update command to the queue of each DataSegment key + */ @Override public void update(String key, Value val, CodeSegment cs) { DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
--- a/src/alice/datasegment/Receiver.java Wed Feb 08 14:31:16 2012 +0900 +++ b/src/alice/datasegment/Receiver.java Wed Feb 08 16:07:33 2012 +0900 @@ -8,6 +8,11 @@ import alice.codesegment.InputDataSegment; +/** + * MessagePack implementation and DataSegment Receiver + * @author kazz + * + */ public class Receiver { public InputDataSegment ids; public int index; @@ -15,8 +20,8 @@ public String from; public CommandType type; - public String managerKey;// - public String key;// + public String managerKey; // for debugging + public String key; // for debugging public Receiver(InputDataSegment ids, CommandType type) { this.ids = ids; @@ -25,8 +30,8 @@ } public void setKey(String managerKey, String key) { - this.managerKey = managerKey;// - this.key = key;// + this.managerKey = managerKey; + this.key = key; setKey(managerKey, key, 0); }
--- a/src/alice/test/codesegment/local/StartCodeSegment.java Wed Feb 08 14:31:16 2012 +0900 +++ b/src/alice/test/codesegment/local/StartCodeSegment.java Wed Feb 08 16:07:33 2012 +0900 @@ -9,10 +9,12 @@ System.out.println("run StartCodeSegment"); TestCodeSegment cs = new TestCodeSegment(); - cs.arg1.setKey("local", "key1"); + cs.arg1.setKey("local", "key1"); // unbound datasegment key1 is created and connect to cs. + // cs is waiting for local.key1 System.out.println("create TestCodeSegment"); - ods.update("local", "key1", "String data"); - } + ods.update("local", "key1", "String data"); // bind string data to datasegment local.key1 + // this startup TestCodeSegment. + } }
--- a/src/alice/test/codesegment/local/TestCodeSegment.java Wed Feb 08 14:31:16 2012 +0900 +++ b/src/alice/test/codesegment/local/TestCodeSegment.java Wed Feb 08 16:07:33 2012 +0900 @@ -6,6 +6,7 @@ public class TestCodeSegment extends CodeSegment { + // create input datasegment arg1 Receiver arg1 = ids.create(CommandType.PEEK); @Override @@ -22,6 +23,7 @@ TestCodeSegment cs = new TestCodeSegment(); cs.arg1.setKey("local", "key1", arg1.index); + // DataSegment.get("local").update ods.update("local", "key1", "String data"); }