# HG changeset patch # User one # Date 1326292082 -32400 # Node ID 80375ae09a1faf532a2445598593b8ca39bece8f # Parent cd3a8f97ea671745a6108358ee5c3714fb1d7b07 add update api diff -r cd3a8f97ea67 -r 80375ae09a1f src/alice/codesegment/InputDataSegment.java --- a/src/alice/codesegment/InputDataSegment.java Wed Jan 11 00:53:30 2012 +0900 +++ b/src/alice/codesegment/InputDataSegment.java Wed Jan 11 23:28:02 2012 +0900 @@ -4,7 +4,6 @@ import java.util.concurrent.atomic.AtomicInteger; import alice.datasegment.DataSegment; -import alice.datasegment.DataSegmentManager; import alice.datasegment.DataSegmentValue; public class InputDataSegment { diff -r cd3a8f97ea67 -r 80375ae09a1f src/alice/datasegment/CommandType.java --- a/src/alice/datasegment/CommandType.java Wed Jan 11 00:53:30 2012 +0900 +++ b/src/alice/datasegment/CommandType.java Wed Jan 11 23:28:02 2012 +0900 @@ -2,6 +2,7 @@ public enum CommandType { PUT, + UPDATE, PEEK, TAKE, REMOVE, diff -r cd3a8f97ea67 -r 80375ae09a1f src/alice/datasegment/DataSegmentKey.java --- a/src/alice/datasegment/DataSegmentKey.java Wed Jan 11 00:53:30 2012 +0900 +++ b/src/alice/datasegment/DataSegmentKey.java Wed Jan 11 23:28:02 2012 +0900 @@ -30,6 +30,10 @@ try { Command cmd = cmdQueue.take(); switch (cmd.cmdType) { + case UPDATE: + if (dataList.size() != 0) { + dataList.remove(0); + } case PUT: int index = tailIndex.getAndIncrement(); dataList.add(new DataSegmentValue(index, cmd.val)); @@ -59,14 +63,19 @@ waitList.add(cmd); break; } + boolean waitFlag = true; for (DataSegmentValue data : dataList) { if (data.index > cmd.index) { // TODO: make and send reply msg - + + dataList.remove(data); + waitFlag = false; break; } } + if (waitFlag) + waitList.add(cmd); break; case REMOVE: // TODO: implements later @@ -74,7 +83,6 @@ default: } } catch (InterruptedException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } diff -r cd3a8f97ea67 -r 80375ae09a1f src/alice/datasegment/DataSegmentManager.java --- a/src/alice/datasegment/DataSegmentManager.java Wed Jan 11 00:53:30 2012 +0900 +++ b/src/alice/datasegment/DataSegmentManager.java Wed Jan 11 23:28:02 2012 +0900 @@ -9,6 +9,7 @@ ConcurrentHashMap dataSegments = new ConcurrentHashMap(); public abstract void put(String key, Value val); + public abstract void update(String key, Value val); public void take(String key, CodeSegment cs) { take(key, 0, cs); } diff -r cd3a8f97ea67 -r 80375ae09a1f src/alice/datasegment/LocalDataSegmentManager.java --- a/src/alice/datasegment/LocalDataSegmentManager.java Wed Jan 11 00:53:30 2012 +0900 +++ b/src/alice/datasegment/LocalDataSegmentManager.java Wed Jan 11 23:28:02 2012 +0900 @@ -27,6 +27,12 @@ } @Override + public void update(String key, Value val) { + DataSegmentKey dataSegmentKey = getDataSegmentKey(key); + dataSegmentKey.addCommand(new Command(CommandType.UPDATE, val, 0, null, 0)); + } + + @Override public void take(String key, int index, CodeSegment cs) { DataSegmentKey dataSegmentKey = getDataSegmentKey(key); int seq = this.seq.getAndIncrement();