Mercurial > hg > Members > tatsuki > Alice
annotate src/alice/datasegment/Receiver.java @ 121:bddb8be357f6 working
fix memory leak
author | one |
---|---|
date | Fri, 27 Jul 2012 00:46:01 +0900 |
parents | b01fb5090e28 |
children | d5d9ca4cbe87 |
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 |
121 | 26 private static MessagePack msgpack = new MessagePack(); |
27 | |
33
20c67f673224
change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
28 public Receiver(InputDataSegment ids, CommandType type) { |
18 | 29 this.ids = ids; |
30 this.type = type; | |
19 | 31 ids.regist(); |
18 | 32 } |
33 | |
34 public void setKey(String managerKey, String key) { | |
57 | 35 this.managerKey = managerKey; |
36 this.key = key; | |
18 | 37 setKey(managerKey, key, 0); |
38 } | |
3 | 39 |
18 | 40 public void setKey(String managerKey, String key, int index) { |
41 switch (type) { | |
42 case PEEK: | |
43 ids.peek(this, managerKey, key, index); | |
44 break; | |
45 case TAKE: | |
46 ids.take(this, managerKey, key, index); | |
47 break; | |
100
b01fb5090e28
add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
48 default: |
b01fb5090e28
add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
49 break; |
18 | 50 } |
19 | 51 ids.setKey(); |
18 | 52 } |
53 | |
65 | 54 public void setKey(String key) { |
55 this.key = key; | |
56 setKey(key, 0); | |
57 } | |
58 | |
59 public void setKey(String key, int index) { | |
60 switch (type) { | |
61 case PEEK: | |
62 ids.peek(this, key, index); | |
63 break; | |
64 case TAKE: | |
65 ids.take(this, key, index); | |
66 break; | |
100
b01fb5090e28
add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
67 default: |
b01fb5090e28
add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
68 break; |
65 | 69 } |
70 ids.setKey(); | |
71 } | |
72 | |
30 | 73 public String asString() { |
74 if (val.getType() == ValueType.RAW) { | |
75 return val.asRawValue().getString(); | |
76 } | |
77 return null; | |
78 } | |
79 | |
80 public int asInteger() { | |
81 if (val.getType() == ValueType.INTEGER) { | |
82 return val.asIntegerValue().getInt(); | |
83 } | |
84 return 0; | |
85 } | |
86 | |
88 | 87 public Float asFloat() { |
88 if (val.getType() == ValueType.FLOAT) { | |
89 return val.asFloatValue().getFloat(); | |
90 } | |
91 return 0.0f; | |
92 } | |
93 | |
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
|
94 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
|
95 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
|
96 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
|
97 } 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
|
98 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
|
99 } |
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 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
|
101 } |
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 |
3 | 103 } |