annotate src/alice/datasegment/LocalDataSegmentManager.java @ 41:f9334781344a

add close api
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Thu, 02 Feb 2012 10:48:39 +0900
parents 20616fe4d28a
children 17f88fd202ae
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
39
3155337e754e add logger
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
3 import org.apache.log4j.Logger;
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
4 import org.msgpack.type.Value;
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
5
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
6 import alice.codesegment.CodeSegment;
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
7 import alice.datasegment.CommandType;
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
8
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
9 public class LocalDataSegmentManager extends DataSegmentManager {
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
10
28
98ab26e09a98 Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
11 public String reverseKey = "local";
98ab26e09a98 Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
12
39
3155337e754e add logger
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
13 private Logger logger = Logger.getLogger("local");
3155337e754e add logger
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
14
6
c78a1cc2cd8f implements Reply
one
parents: 5
diff changeset
15 public LocalDataSegmentManager() {
20
0bb03861b5cd set name to Thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
16 new Thread(replyThread, "LocalDataSegmentManager").start();
6
c78a1cc2cd8f implements Reply
one
parents: 5
diff changeset
17 }
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
18
13
30f97d776a3e implements Alice daemon
one
parents: 12
diff changeset
19 public DataSegmentKey getDataSegmentKey(String key) {
16
433e601a8e28 network bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
20 if (key == null) {
433e601a8e28 network bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
21 return null;
433e601a8e28 network bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
22 }
20
0bb03861b5cd set name to Thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
23 DataSegmentKey newDataSegmentKey = new DataSegmentKey(key);
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
24 DataSegmentKey dataSegmentKey = dataSegments.putIfAbsent(key, newDataSegmentKey);
8
78b415d019de Local DS and CS work! maybe...
one
parents: 7
diff changeset
25 if (dataSegmentKey == null) {
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
26 newDataSegmentKey.runKeyThread();
8
78b415d019de Local DS and CS work! maybe...
one
parents: 7
diff changeset
27 dataSegmentKey = newDataSegmentKey;
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
28 }
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
29 return dataSegmentKey;
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
30 }
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
31
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
32 @Override
40
20616fe4d28a add log viewer
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
33 public void put(String key, Value val, CodeSegment cs) {
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
34 DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
40
20616fe4d28a add log viewer
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
35 Command cmd = new Command(CommandType.PUT, null, key, val, 0, 0, replyQueue, cs, reverseKey);
39
3155337e754e add logger
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
36 dataSegmentKey.addCommand(cmd);
40
20616fe4d28a add log viewer
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
37 logger.debug(cmd.getCommandString());
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
38 }
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
39
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
40 @Override
40
20616fe4d28a add log viewer
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
41 public void update(String key, Value val, CodeSegment cs) {
5
80375ae09a1f add update api
one
parents: 3
diff changeset
42 DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
40
20616fe4d28a add log viewer
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
43 Command cmd = new Command(CommandType.UPDATE, null, key, val, 0, 0, replyQueue, cs, reverseKey);
39
3155337e754e add logger
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
44 dataSegmentKey.addCommand(cmd);
40
20616fe4d28a add log viewer
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
45 logger.debug(cmd.getCommandString());
5
80375ae09a1f add update api
one
parents: 3
diff changeset
46 }
80375ae09a1f add update api
one
parents: 3
diff changeset
47
80375ae09a1f add update api
one
parents: 3
diff changeset
48 @Override
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
49 public void take(Receiver receiver, String key, int index, CodeSegment cs) {
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
50 DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
51 int seq = this.seq.getAndIncrement();
40
20616fe4d28a add log viewer
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
52 Command cmd = new Command(CommandType.TAKE, receiver, key, null, index, seq, replyQueue, cs, null);
6
c78a1cc2cd8f implements Reply
one
parents: 5
diff changeset
53 seqHash.put(seq, cmd);
c78a1cc2cd8f implements Reply
one
parents: 5
diff changeset
54 dataSegmentKey.addCommand(cmd);
40
20616fe4d28a add log viewer
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
55 logger.debug(cmd.getCommandString());
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
56 }
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
57
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
58 @Override
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
59 public void peek(Receiver receiver, String key, int index, CodeSegment cs) {
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
60 DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
61 int seq = this.seq.getAndIncrement();
40
20616fe4d28a add log viewer
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
62 Command cmd = new Command(CommandType.PEEK, receiver, key, null, index, seq, replyQueue, cs, null);
6
c78a1cc2cd8f implements Reply
one
parents: 5
diff changeset
63 seqHash.put(seq, cmd);
c78a1cc2cd8f implements Reply
one
parents: 5
diff changeset
64 dataSegmentKey.addCommand(cmd);
40
20616fe4d28a add log viewer
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
65 logger.debug(cmd.getCommandString());
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
66 }
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
67
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
68 @Override
3
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
69 public void remove(String key) {
91057e15065f add DataSegment API and CodeSegment
one
parents: 2
diff changeset
70 DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
40
20616fe4d28a add log viewer
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
71 Command cmd = new Command(CommandType.REMOVE, null, key, null, 0, 0, replyQueue, null, null);
39
3155337e754e add logger
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
72 dataSegmentKey.addCommand(cmd);
40
20616fe4d28a add log viewer
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 39
diff changeset
73 logger.debug(cmd.getCommandString());
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
74 }
30
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
75
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
76 @Override public void finish() {
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
77 System.exit(0);
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
78 }
41
f9334781344a add close api
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
79
f9334781344a add close api
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
80 @Override
f9334781344a add close api
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
81 public void close() {
f9334781344a add close api
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
82
f9334781344a add close api
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 40
diff changeset
83 }
30
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
84
2
f71eabb1df2a create outline of DataSegment model
one
parents:
diff changeset
85 }