annotate src/alice/datasegment/Receiver.java @ 88:33a19ca88e43 working

Singleton is removed .
author sugi
date Mon, 04 Jun 2012 16:08:53 +0900
parents ca42a2c8ac22
children b01fb5090e28
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
1 package alice.datasegment;
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
2
34
ca079a730d0b added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
3 import java.io.IOException;
ca079a730d0b added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
4
ca079a730d0b added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
5 import org.msgpack.MessagePack;
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
6 import org.msgpack.type.Value;
30
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
7 import org.msgpack.type.ValueType;
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
8
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
9 import alice.codesegment.InputDataSegment;
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
10
57
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
11 /**
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
12 * MessagePack implementation and DataSegment Receiver
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
13 * @author kazz
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
14 *
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
15 */
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
16 public class Receiver {
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
17 public InputDataSegment ids;
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
18 public int index;
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
19 public Value val;
28
98ab26e09a98 Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
20 public String from;
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
21 public CommandType type;
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
22
57
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
23 public String managerKey; // for debugging
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
24 public String key; // for debugging
44
73158dc54c59 fix peek api
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
25
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
26 public Receiver(InputDataSegment ids, CommandType type) {
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
27 this.ids = ids;
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
28 this.type = type;
19
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
29 ids.regist();
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
30 }
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
31
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
32 public void setKey(String managerKey, String key) {
57
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
33 this.managerKey = managerKey;
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
34 this.key = key;
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
35 setKey(managerKey, key, 0);
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
36 }
3
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
37
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
38 public void setKey(String managerKey, String key, int index) {
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
39 switch (type) {
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
40 case PEEK:
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
41 ids.peek(this, managerKey, key, index);
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
42 break;
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
43 case TAKE:
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
44 ids.take(this, managerKey, key, index);
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
45 break;
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
46 }
19
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
47 ids.setKey();
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
48 }
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
49
65
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
50 public void setKey(String key) {
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
51 this.key = key;
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
52 setKey(key, 0);
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
53 }
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
54
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
55 public void setKey(String key, int index) {
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
56 switch (type) {
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
57 case PEEK:
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
58 ids.peek(this, key, index);
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
59 break;
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
60 case TAKE:
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
61 ids.take(this, key, index);
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
62 break;
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
63 }
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
64 ids.setKey();
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
65 }
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
66
30
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
67 public String asString() {
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
68 if (val.getType() == ValueType.RAW) {
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
69 return val.asRawValue().getString();
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
70 }
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
71 return null;
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
72 }
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
73
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
74 public int asInteger() {
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
75 if (val.getType() == ValueType.INTEGER) {
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
76 return val.asIntegerValue().getInt();
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
77 }
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
78 return 0;
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
79 }
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
80
88
33a19ca88e43 Singleton is removed .
sugi
parents: 65
diff changeset
81 public Float asFloat() {
33a19ca88e43 Singleton is removed .
sugi
parents: 65
diff changeset
82 if (val.getType() == ValueType.FLOAT) {
33a19ca88e43 Singleton is removed .
sugi
parents: 65
diff changeset
83 return val.asFloatValue().getFloat();
33a19ca88e43 Singleton is removed .
sugi
parents: 65
diff changeset
84 }
33a19ca88e43 Singleton is removed .
sugi
parents: 65
diff changeset
85 return 0.0f;
33a19ca88e43 Singleton is removed .
sugi
parents: 65
diff changeset
86 }
33a19ca88e43 Singleton is removed .
sugi
parents: 65
diff changeset
87
34
ca079a730d0b added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
88 public <T> T asClass(Class<T> clazz) {
ca079a730d0b added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
89 MessagePack msgpack = new MessagePack();
ca079a730d0b added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
90 try {
ca079a730d0b added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
91 return msgpack.convert(val, clazz);
ca079a730d0b added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
92 } catch (IOException e) {
ca079a730d0b added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
93 e.printStackTrace();
ca079a730d0b added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
94 }
ca079a730d0b added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
95 return null;
ca079a730d0b added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
96 }
ca079a730d0b added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
97
3
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
98 }