annotate src/alice/datasegment/LocalDataSegmentManager.java @ 67:2afbb6404840

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