annotate src/alice/datasegment/LocalDataSegmentManager.java @ 58:ebdcab7b9b04

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