Mercurial > hg > Members > tatsuki > Alice
changeset 5:80375ae09a1f
add update api
author | one |
---|---|
date | Wed, 11 Jan 2012 23:28:02 +0900 |
parents | cd3a8f97ea67 |
children | c78a1cc2cd8f |
files | src/alice/codesegment/InputDataSegment.java src/alice/datasegment/CommandType.java src/alice/datasegment/DataSegmentKey.java src/alice/datasegment/DataSegmentManager.java src/alice/datasegment/LocalDataSegmentManager.java |
diffstat | 5 files changed, 18 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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 {
--- 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,
--- 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(); } }
--- 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<String, DataSegmentKey> dataSegments = new ConcurrentHashMap<String, DataSegmentKey>(); 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); }
--- 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();