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