Mercurial > hg > Database > Alice
view src/alice/datasegment/LocalDataSegmentManager.java @ 14:e3f1b21718b0
implements RemoteDataSegment
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 15 Jan 2012 00:56:25 +0900 |
parents | 30f97d776a3e |
children | 433e601a8e28 |
line wrap: on
line source
package alice.datasegment; import org.msgpack.type.Value; import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; public class LocalDataSegmentManager extends DataSegmentManager { public LocalDataSegmentManager() { new Thread(replyThread).start(); } public DataSegmentKey getDataSegmentKey(String key) { DataSegmentKey newDataSegmentKey = new DataSegmentKey(); DataSegmentKey dataSegmentKey = dataSegments.putIfAbsent(key, newDataSegmentKey); if (dataSegmentKey == null) { newDataSegmentKey.runKeyThread(); dataSegmentKey = newDataSegmentKey; } return dataSegmentKey; } @Override public void put(String key, Value val) { DataSegmentKey dataSegmentKey = getDataSegmentKey(key); dataSegmentKey.addCommand(new Command(CommandType.PUT, null, null, val, 0, 0, replyQueue, null)); } @Override public void update(String key, Value val) { DataSegmentKey dataSegmentKey = getDataSegmentKey(key); dataSegmentKey.addCommand(new Command(CommandType.UPDATE, null, null, val, 0, 0, replyQueue, null)); } @Override public void take(String argKey, String key, int index, CodeSegment cs) { DataSegmentKey dataSegmentKey = getDataSegmentKey(key); int seq = this.seq.getAndIncrement(); Command cmd = new Command(CommandType.TAKE, argKey, null, null, index, seq, replyQueue, cs); seqHash.put(seq, cmd); dataSegmentKey.addCommand(cmd); } @Override public void peek(String argKey, String key, int index, CodeSegment cs) { DataSegmentKey dataSegmentKey = getDataSegmentKey(key); int seq = this.seq.getAndIncrement(); Command cmd = new Command(CommandType.PEEK, argKey, null, null, index, seq, replyQueue, cs); seqHash.put(seq, cmd); dataSegmentKey.addCommand(cmd); } @Override public void remove(String key) { DataSegmentKey dataSegmentKey = getDataSegmentKey(key); dataSegmentKey.addCommand(new Command(CommandType.REMOVE, null, null, null, 0, 0, replyQueue, null)); } }