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