Mercurial > hg > Members > tatsuki > Alice
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 |
rev | line source |
---|---|
3 | 1 package alice.datasegment; |
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 | 5 import org.msgpack.type.ArrayValue; |
18 | 6 import org.msgpack.type.Value; |
188 | 7 import org.msgpack.type.ValueFactory; |
30 | 8 import org.msgpack.type.ValueType; |
18 | 9 |
10 import alice.codesegment.InputDataSegment; | |
126 | 11 import alice.codesegment.SingletonMessage; |
18 | 12 |
57 | 13 /** |
14 * MessagePack implementation and DataSegment Receiver | |
15 * @author kazz | |
16 * | |
17 */ | |
33
20c67f673224
change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
18 public class Receiver { |
18 | 19 public InputDataSegment ids; |
20 public int index; | |
21 public Value val; | |
190 | 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 | 24 public CommandType type; |
25 | |
57 | 26 public String managerKey; // for debugging |
27 public String key; // for debugging | |
44 | 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 | 30 this.ids = ids; |
31 this.type = type; | |
19 | 32 ids.regist(); |
18 | 33 } |
34 | |
188 | 35 // for same key |
36 | |
37 public void flip(Value val){ | |
38 DataSegment.getLocal().flip(this.key, val); | |
39 } | |
40 | |
41 public void flip(int val){ | |
42 DataSegment.getLocal().flip(this.key, ValueFactory.createIntegerValue(val)); | |
43 } | |
44 | |
45 public void flip(String val){ | |
46 DataSegment.getLocal().flip(this.key, ValueFactory.createRawValue(val)); | |
47 } | |
48 | |
49 public void flip(byte[] val){ | |
50 DataSegment.getLocal().flip(this.key, ValueFactory.createRawValue(val, true)); | |
51 } | |
52 | |
53 public <T> void flip(T val) { | |
54 try { | |
55 DataSegment.getLocal().flip(this.key, SingletonMessage.getInstance().unconvert(val)); | |
56 } catch (IOException e) { | |
57 e.printStackTrace(); | |
58 } | |
59 } | |
60 | |
18 | 61 public void setKey(String managerKey, String key) { |
57 | 62 this.managerKey = managerKey; |
18 | 63 setKey(managerKey, key, 0); |
64 } | |
3 | 65 |
18 | 66 public void setKey(String managerKey, String key, int index) { |
176 | 67 this.key = key; |
18 | 68 switch (type) { |
69 case PEEK: | |
70 ids.peek(this, managerKey, key, index); | |
71 break; | |
72 case TAKE: | |
73 ids.take(this, managerKey, key, index); | |
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 | 77 } |
19 | 78 ids.setKey(); |
18 | 79 } |
80 | |
65 | 81 public void setKey(String key) { |
82 setKey(key, 0); | |
83 } | |
84 | |
85 public void setKey(String key, int index) { | |
176 | 86 this.key = key; |
65 | 87 switch (type) { |
88 case PEEK: | |
89 ids.peek(this, key, index); | |
90 break; | |
91 case TAKE: | |
92 ids.take(this, key, index); | |
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 | 96 } |
97 ids.setKey(); | |
98 } | |
99 | |
30 | 100 public String asString() { |
101 if (val.getType() == ValueType.RAW) { | |
102 return val.asRawValue().getString(); | |
103 } | |
104 return null; | |
105 } | |
106 | |
107 public int asInteger() { | |
108 if (val.getType() == ValueType.INTEGER) { | |
109 return val.asIntegerValue().getInt(); | |
110 } | |
111 return 0; | |
112 } | |
113 | |
88 | 114 public Float asFloat() { |
115 if (val.getType() == ValueType.FLOAT) { | |
116 return val.asFloatValue().getFloat(); | |
117 } | |
118 return 0.0f; | |
119 } | |
120 | |
152 | 121 public ArrayValue asArray(){ |
122 if (val.getType() == ValueType.ARRAY){ | |
123 return val.asArrayValue(); | |
124 } | |
125 return null; | |
126 } | |
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 | 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 | 137 } |