Mercurial > hg > Members > tatsuki > Alice
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 |
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 |
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 | 6 import org.msgpack.type.Value; |
30 | 7 import org.msgpack.type.ValueType; |
18 | 8 |
9 import alice.codesegment.InputDataSegment; | |
10 | |
57 | 11 /** |
12 * MessagePack implementation and DataSegment Receiver | |
13 * @author kazz | |
14 * | |
15 */ | |
33
20c67f673224
change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
16 public class Receiver { |
18 | 17 public InputDataSegment ids; |
18 public int index; | |
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 | 21 public CommandType type; |
22 | |
57 | 23 public String managerKey; // for debugging |
24 public String key; // for debugging | |
44 | 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 | 27 this.ids = ids; |
28 this.type = type; | |
19 | 29 ids.regist(); |
18 | 30 } |
31 | |
32 public void setKey(String managerKey, String key) { | |
57 | 33 this.managerKey = managerKey; |
34 this.key = key; | |
18 | 35 setKey(managerKey, key, 0); |
36 } | |
3 | 37 |
18 | 38 public void setKey(String managerKey, String key, int index) { |
39 switch (type) { | |
40 case PEEK: | |
41 ids.peek(this, managerKey, key, index); | |
42 break; | |
43 case TAKE: | |
44 ids.take(this, managerKey, key, index); | |
45 break; | |
46 } | |
19 | 47 ids.setKey(); |
18 | 48 } |
49 | |
65 | 50 public void setKey(String key) { |
51 this.key = key; | |
52 setKey(key, 0); | |
53 } | |
54 | |
55 public void setKey(String key, int index) { | |
56 switch (type) { | |
57 case PEEK: | |
58 ids.peek(this, key, index); | |
59 break; | |
60 case TAKE: | |
61 ids.take(this, key, index); | |
62 break; | |
63 } | |
64 ids.setKey(); | |
65 } | |
66 | |
30 | 67 public String asString() { |
68 if (val.getType() == ValueType.RAW) { | |
69 return val.asRawValue().getString(); | |
70 } | |
71 return null; | |
72 } | |
73 | |
74 public int asInteger() { | |
75 if (val.getType() == ValueType.INTEGER) { | |
76 return val.asIntegerValue().getInt(); | |
77 } | |
78 return 0; | |
79 } | |
80 | |
88 | 81 public Float asFloat() { |
82 if (val.getType() == ValueType.FLOAT) { | |
83 return val.asFloatValue().getFloat(); | |
84 } | |
85 return 0.0f; | |
86 } | |
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 | 98 } |