Mercurial > hg > Members > tatsuki > Alice
annotate src/alice/datasegment/Receiver.java @ 126:669dba7cbb69 working
Use singleton
author | sugi |
---|---|
date | Fri, 03 Aug 2012 19:14:46 +0900 |
parents | d5d9ca4cbe87 |
children | ed78890ed8e9 |
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 |
126 | 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; | |
126 | 10 import alice.codesegment.SingletonMessage; |
18 | 11 |
57 | 12 /** |
13 * MessagePack implementation and DataSegment Receiver | |
14 * @author kazz | |
15 * | |
16 */ | |
33
20c67f673224
change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
17 public class Receiver { |
18 | 18 public InputDataSegment ids; |
19 public int index; | |
20 public Value val; | |
28
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
21 public String from; |
18 | 22 public CommandType type; |
23 | |
57 | 24 public String managerKey; // for debugging |
25 public String key; // for debugging | |
44 | 26 |
126 | 27 //private static MessagePack MSGPACK = new MessagePack(); |
121 | 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 | |
35 public void setKey(String managerKey, String key) { | |
57 | 36 this.managerKey = managerKey; |
37 this.key = key; | |
18 | 38 setKey(managerKey, key, 0); |
39 } | |
3 | 40 |
18 | 41 public void setKey(String managerKey, String key, int index) { |
42 switch (type) { | |
43 case PEEK: | |
44 ids.peek(this, managerKey, key, index); | |
45 break; | |
46 case TAKE: | |
47 ids.take(this, managerKey, key, index); | |
48 break; | |
100
b01fb5090e28
add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
49 default: |
b01fb5090e28
add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
50 break; |
18 | 51 } |
19 | 52 ids.setKey(); |
18 | 53 } |
54 | |
65 | 55 public void setKey(String key) { |
56 this.key = key; | |
57 setKey(key, 0); | |
58 } | |
59 | |
60 public void setKey(String key, int index) { | |
61 switch (type) { | |
62 case PEEK: | |
63 ids.peek(this, key, index); | |
64 break; | |
65 case TAKE: | |
66 ids.take(this, key, index); | |
67 break; | |
100
b01fb5090e28
add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
68 default: |
b01fb5090e28
add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
69 break; |
65 | 70 } |
71 ids.setKey(); | |
72 } | |
73 | |
30 | 74 public String asString() { |
75 if (val.getType() == ValueType.RAW) { | |
76 return val.asRawValue().getString(); | |
77 } | |
78 return null; | |
79 } | |
80 | |
81 public int asInteger() { | |
82 if (val.getType() == ValueType.INTEGER) { | |
83 return val.asIntegerValue().getInt(); | |
84 } | |
85 return 0; | |
86 } | |
87 | |
88 | 88 public Float asFloat() { |
89 if (val.getType() == ValueType.FLOAT) { | |
90 return val.asFloatValue().getFloat(); | |
91 } | |
92 return 0.0f; | |
93 } | |
94 | |
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
|
95 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
|
96 try { |
126 | 97 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
|
98 } 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
|
99 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
|
100 } |
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
|
101 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
|
102 } |
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
|
103 |
3 | 104 } |