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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
1 package alice.datasegment;
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
3 import org.msgpack.type.Value;
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
4
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
5 import alice.codesegment.CodeSegment;
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
6 import alice.datasegment.CommandType;
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
7
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
8 public class LocalDataSegmentManager extends DataSegmentManager {
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
9
6
c78a1cc2cd8f implements Reply
one
parents: 5
diff changeset
10 public LocalDataSegmentManager() {
c78a1cc2cd8f implements Reply
one
parents: 5
diff changeset
11 new Thread(replyThread).start();
c78a1cc2cd8f implements Reply
one
parents: 5
diff changeset
12 }
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
13
13
30f97d776a3e implements Alice daemon
one
parents: 12
diff changeset
14 public DataSegmentKey getDataSegmentKey(String key) {
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
15 DataSegmentKey newDataSegmentKey = new DataSegmentKey();
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
16 DataSegmentKey dataSegmentKey = dataSegments.putIfAbsent(key, newDataSegmentKey);
8
78b415d019de Local DS and CS work! maybe...
one
parents: 7
diff changeset
17 if (dataSegmentKey == null) {
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
18 newDataSegmentKey.runKeyThread();
8
78b415d019de Local DS and CS work! maybe...
one
parents: 7
diff changeset
19 dataSegmentKey = newDataSegmentKey;
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
20 }
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
21 return dataSegmentKey;
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
22 }
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
23
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
24 @Override
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
25 public void put(String key, Value val) {
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
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
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
28 }
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
29
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
30 @Override
5
80375ae09a1f add update api
one
parents: 3
diff changeset
31 public void update(String key, Value val) {
80375ae09a1f add update api
one
parents: 3
diff changeset
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
80375ae09a1f add update api
one
parents: 3
diff changeset
34 }
80375ae09a1f add update api
one
parents: 3
diff changeset
35
80375ae09a1f add update api
one
parents: 3
diff changeset
36 @Override
7
352eb19d837d implements reply of LocalDataSegment
one
parents: 6
diff changeset
37 public void take(String argKey, String key, int index, CodeSegment cs) {
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
38 DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
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
c78a1cc2cd8f implements Reply
one
parents: 5
diff changeset
41 seqHash.put(seq, cmd);
c78a1cc2cd8f implements Reply
one
parents: 5
diff changeset
42 dataSegmentKey.addCommand(cmd);
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
43 }
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
44
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
45 @Override
7
352eb19d837d implements reply of LocalDataSegment
one
parents: 6
diff changeset
46 public void peek(String argKey, String key, int index, CodeSegment cs) {
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
47 DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
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
c78a1cc2cd8f implements Reply
one
parents: 5
diff changeset
50 seqHash.put(seq, cmd);
c78a1cc2cd8f implements Reply
one
parents: 5
diff changeset
51 dataSegmentKey.addCommand(cmd);
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
52 }
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
53
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
54 @Override
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
55 public void remove(String key) {
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
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
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
58 }
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
59
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
60 }