annotate src/alice/datasegment/Receiver.java @ 190:a85ff8dc16c1 working

add Object data
author one
date Thu, 07 Mar 2013 21:27:00 +0900
parents 38d6a10be9c6
children b4ca7f75e6b2
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
152
b23581a5243c minor change
sugi
parents: 138
diff changeset
5 import org.msgpack.type.ArrayValue;
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
6 import org.msgpack.type.Value;
188
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
7 import org.msgpack.type.ValueFactory;
30
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
8 import org.msgpack.type.ValueType;
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
9
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
10 import alice.codesegment.InputDataSegment;
126
669dba7cbb69 Use singleton
sugi
parents: 122
diff changeset
11 import alice.codesegment.SingletonMessage;
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
12
57
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
13 /**
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
14 * MessagePack implementation and DataSegment Receiver
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
15 * @author kazz
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
16 *
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
17 */
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
18 public class Receiver {
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
19 public InputDataSegment ids;
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
20 public int index;
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
21 public Value val;
190
a85ff8dc16c1 add Object data
one
parents: 188
diff changeset
22 public Object obj;
28
98ab26e09a98 Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
23 public String from;
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
24 public CommandType type;
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
25
57
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
26 public String managerKey; // for debugging
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
27 public String key; // for debugging
44
73158dc54c59 fix peek api
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
28
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 30
diff changeset
29 public Receiver(InputDataSegment ids, CommandType type) {
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
30 this.ids = ids;
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
31 this.type = type;
19
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
32 ids.regist();
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
33 }
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
34
188
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
35 // for same key
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
36
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
37 public void flip(Value val){
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
38 DataSegment.getLocal().flip(this.key, val);
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
39 }
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
40
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
41 public void flip(int val){
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
42 DataSegment.getLocal().flip(this.key, ValueFactory.createIntegerValue(val));
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
43 }
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
44
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
45 public void flip(String val){
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
46 DataSegment.getLocal().flip(this.key, ValueFactory.createRawValue(val));
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
47 }
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
48
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
49 public void flip(byte[] val){
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
50 DataSegment.getLocal().flip(this.key, ValueFactory.createRawValue(val, true));
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
51 }
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
52
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
53 public <T> void flip(T val) {
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
54 try {
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
55 DataSegment.getLocal().flip(this.key, SingletonMessage.getInstance().unconvert(val));
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
56 } catch (IOException e) {
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
57 e.printStackTrace();
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
58 }
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
59 }
38d6a10be9c6 add FLIP API in Receiver class
e095732
parents: 176
diff changeset
60
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
61 public void setKey(String managerKey, String key) {
57
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
62 this.managerKey = managerKey;
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
63 setKey(managerKey, key, 0);
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
64 }
3
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
65
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
66 public void setKey(String managerKey, String key, int index) {
176
4658bf530834 remove ant warning
e095732
parents: 152
diff changeset
67 this.key = key;
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
68 switch (type) {
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
69 case PEEK:
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
70 ids.peek(this, managerKey, key, index);
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
71 break;
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
72 case TAKE:
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
73 ids.take(this, managerKey, key, index);
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
74 break;
100
b01fb5090e28 add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
75 default:
b01fb5090e28 add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
76 break;
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
77 }
19
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
78 ids.setKey();
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
79 }
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
80
65
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
81 public void setKey(String key) {
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
82 setKey(key, 0);
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
83 }
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
84
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
85 public void setKey(String key, int index) {
176
4658bf530834 remove ant warning
e095732
parents: 152
diff changeset
86 this.key = key;
65
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
87 switch (type) {
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
88 case PEEK:
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
89 ids.peek(this, key, index);
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
90 break;
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
91 case TAKE:
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
92 ids.take(this, key, index);
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
93 break;
100
b01fb5090e28 add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
94 default:
b01fb5090e28 add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
95 break;
65
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
96 }
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
97 ids.setKey();
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
98 }
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
99
30
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
100 public String asString() {
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
101 if (val.getType() == ValueType.RAW) {
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
102 return val.asRawValue().getString();
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
103 }
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
104 return null;
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
105 }
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
106
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
107 public int asInteger() {
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
108 if (val.getType() == ValueType.INTEGER) {
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
109 return val.asIntegerValue().getInt();
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
110 }
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
111 return 0;
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
112 }
b5a21baf0b07 implements RingTopology
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
113
88
33a19ca88e43 Singleton is removed .
sugi
parents: 65
diff changeset
114 public Float asFloat() {
33a19ca88e43 Singleton is removed .
sugi
parents: 65
diff changeset
115 if (val.getType() == ValueType.FLOAT) {
33a19ca88e43 Singleton is removed .
sugi
parents: 65
diff changeset
116 return val.asFloatValue().getFloat();
33a19ca88e43 Singleton is removed .
sugi
parents: 65
diff changeset
117 }
33a19ca88e43 Singleton is removed .
sugi
parents: 65
diff changeset
118 return 0.0f;
33a19ca88e43 Singleton is removed .
sugi
parents: 65
diff changeset
119 }
33a19ca88e43 Singleton is removed .
sugi
parents: 65
diff changeset
120
152
b23581a5243c minor change
sugi
parents: 138
diff changeset
121 public ArrayValue asArray(){
b23581a5243c minor change
sugi
parents: 138
diff changeset
122 if (val.getType() == ValueType.ARRAY){
b23581a5243c minor change
sugi
parents: 138
diff changeset
123 return val.asArrayValue();
b23581a5243c minor change
sugi
parents: 138
diff changeset
124 }
b23581a5243c minor change
sugi
parents: 138
diff changeset
125 return null;
b23581a5243c minor change
sugi
parents: 138
diff changeset
126 }
b23581a5243c minor change
sugi
parents: 138
diff changeset
127
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
128 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
129 try {
126
669dba7cbb69 Use singleton
sugi
parents: 122
diff changeset
130 return SingletonMessage.getInstance().convert(val, clazz);
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
131 } 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
132 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
133 }
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
134 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
135 }
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
136
3
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
137 }