Mercurial > hg > Database > Alice
annotate 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 |
rev | line source |
---|---|
2 | 1 package alice.datasegment; |
2 | |
3 import org.msgpack.type.Value; | |
4 | |
3 | 5 import alice.codesegment.CodeSegment; |
6 import alice.datasegment.CommandType; | |
7 | |
2 | 8 public class LocalDataSegmentManager extends DataSegmentManager { |
9 | |
6 | 10 public LocalDataSegmentManager() { |
11 new Thread(replyThread).start(); | |
12 } | |
3 | 13 |
13 | 14 public DataSegmentKey getDataSegmentKey(String key) { |
3 | 15 DataSegmentKey newDataSegmentKey = new DataSegmentKey(); |
16 DataSegmentKey dataSegmentKey = dataSegments.putIfAbsent(key, newDataSegmentKey); | |
8 | 17 if (dataSegmentKey == null) { |
3 | 18 newDataSegmentKey.runKeyThread(); |
8 | 19 dataSegmentKey = newDataSegmentKey; |
3 | 20 } |
21 return dataSegmentKey; | |
22 } | |
23 | |
2 | 24 @Override |
25 public void put(String key, Value val) { | |
3 | 26 DataSegmentKey dataSegmentKey = getDataSegmentKey(key); |
14
e3f1b21718b0
implements RemoteDataSegment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
27 dataSegmentKey.addCommand(new Command(CommandType.PUT, null, null, val, 0, 0, replyQueue, null)); |
2 | 28 } |
29 | |
30 @Override | |
5 | 31 public void update(String key, Value val) { |
32 DataSegmentKey dataSegmentKey = getDataSegmentKey(key); | |
14
e3f1b21718b0
implements RemoteDataSegment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
33 dataSegmentKey.addCommand(new Command(CommandType.UPDATE, null, null, val, 0, 0, replyQueue, null)); |
5 | 34 } |
35 | |
36 @Override | |
7 | 37 public void take(String argKey, String key, int index, CodeSegment cs) { |
3 | 38 DataSegmentKey dataSegmentKey = getDataSegmentKey(key); |
39 int seq = this.seq.getAndIncrement(); | |
14
e3f1b21718b0
implements RemoteDataSegment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
40 Command cmd = new Command(CommandType.TAKE, argKey, null, null, index, seq, replyQueue, cs); |
6 | 41 seqHash.put(seq, cmd); |
42 dataSegmentKey.addCommand(cmd); | |
2 | 43 } |
44 | |
45 @Override | |
7 | 46 public void peek(String argKey, String key, int index, CodeSegment cs) { |
3 | 47 DataSegmentKey dataSegmentKey = getDataSegmentKey(key); |
48 int seq = this.seq.getAndIncrement(); | |
14
e3f1b21718b0
implements RemoteDataSegment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
49 Command cmd = new Command(CommandType.PEEK, argKey, null, null, index, seq, replyQueue, cs); |
6 | 50 seqHash.put(seq, cmd); |
51 dataSegmentKey.addCommand(cmd); | |
2 | 52 } |
53 | |
54 @Override | |
3 | 55 public void remove(String key) { |
56 DataSegmentKey dataSegmentKey = getDataSegmentKey(key); | |
14
e3f1b21718b0
implements RemoteDataSegment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
57 dataSegmentKey.addCommand(new Command(CommandType.REMOVE, null, null, null, 0, 0, replyQueue, null)); |
2 | 58 } |
59 | |
60 } |