Mercurial > hg > Members > tatsuki > Alice
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 |
rev | line source |
---|---|
2 | 1 package alice.datasegment; |
2 | |
56 | 3 import java.util.concurrent.ConcurrentHashMap; |
4 | |
67 | 5 //import org.apache.log4j.Logger; |
2 | 6 import org.msgpack.type.Value; |
7 | |
3 | 8 import alice.codesegment.CodeSegment; |
9 | |
2 | 10 public class LocalDataSegmentManager extends DataSegmentManager { |
11 | |
56 | 12 private String reverseKey = "local"; |
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 | 15 // private Logger logger = Logger.getLogger("local"); |
39 | 16 |
6 | 17 public LocalDataSegmentManager() { |
20 | 18 new Thread(replyThread, "LocalDataSegmentManager").start(); |
6 | 19 } |
3 | 20 |
13 | 21 public DataSegmentKey getDataSegmentKey(String key) { |
64 | 22 DataSegmentKey dsKey = dataSegments.get(key); |
63 | 23 if (dsKey != null) |
24 return dsKey; | |
25 if (key == null) | |
16 | 26 return null; |
20 | 27 DataSegmentKey newDataSegmentKey = new DataSegmentKey(key); |
3 | 28 DataSegmentKey dataSegmentKey = dataSegments.putIfAbsent(key, newDataSegmentKey); |
8 | 29 if (dataSegmentKey == null) { |
3 | 30 newDataSegmentKey.runKeyThread(); |
8 | 31 dataSegmentKey = newDataSegmentKey; |
3 | 32 } |
33 return dataSegmentKey; | |
34 } | |
35 | |
2 | 36 @Override |
40 | 37 public void put(String key, Value val, CodeSegment cs) { |
3 | 38 DataSegmentKey dataSegmentKey = getDataSegmentKey(key); |
40 | 39 Command cmd = new Command(CommandType.PUT, null, key, val, 0, 0, replyQueue, cs, reverseKey); |
39 | 40 dataSegmentKey.addCommand(cmd); |
66 | 41 // logger.debug(cmd.getCommandString()); |
2 | 42 } |
57 | 43 |
44 | |
45 /** | |
46 * Enqueue update command to the queue of each DataSegment key | |
47 */ | |
2 | 48 @Override |
40 | 49 public void update(String key, Value val, CodeSegment cs) { |
5 | 50 DataSegmentKey dataSegmentKey = getDataSegmentKey(key); |
40 | 51 Command cmd = new Command(CommandType.UPDATE, null, key, val, 0, 0, replyQueue, cs, reverseKey); |
39 | 52 dataSegmentKey.addCommand(cmd); |
66 | 53 // logger.debug(cmd.getCommandString()); |
5 | 54 } |
55 | |
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 | 58 DataSegmentKey dataSegmentKey = getDataSegmentKey(key); |
59 int seq = this.seq.getAndIncrement(); | |
40 | 60 Command cmd = new Command(CommandType.TAKE, receiver, key, null, index, seq, replyQueue, cs, null); |
6 | 61 seqHash.put(seq, cmd); |
62 dataSegmentKey.addCommand(cmd); | |
66 | 63 // logger.debug(cmd.getCommandString()); |
2 | 64 } |
65 | |
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 | 68 DataSegmentKey dataSegmentKey = getDataSegmentKey(key); |
69 int seq = this.seq.getAndIncrement(); | |
40 | 70 Command cmd = new Command(CommandType.PEEK, receiver, key, null, index, seq, replyQueue, cs, null); |
58 | 71 seqHash.put(seq, cmd); // waiting for PUT or UPDATE at unique sequence number |
6 | 72 dataSegmentKey.addCommand(cmd); |
66 | 73 // logger.debug(cmd.getCommandString()); |
2 | 74 } |
75 | |
76 @Override | |
3 | 77 public void remove(String key) { |
78 DataSegmentKey dataSegmentKey = getDataSegmentKey(key); | |
40 | 79 Command cmd = new Command(CommandType.REMOVE, null, key, null, 0, 0, replyQueue, null, null); |
39 | 80 dataSegmentKey.addCommand(cmd); |
66 | 81 // logger.debug(cmd.getCommandString()); |
2 | 82 } |
30 | 83 |
84 @Override public void finish() { | |
85 System.exit(0); | |
86 } | |
41 | 87 |
88 @Override | |
89 public void close() { | |
90 | |
91 } | |
30 | 92 |
2 | 93 } |