345
|
1 package alice.datasegment;
|
|
2
|
|
3
|
|
4 import alice.codesegment.InputDataSegment;
|
|
5
|
|
6 /**
|
|
7 * MessagePack implementation and DataSegment Receiver
|
|
8 * @author kazz
|
|
9 *
|
|
10 */
|
|
11 public class Receiver {
|
417
|
12 private ReceiverData data = new ReceiveRemoteData();
|
|
13 public InputDataSegment ids;
|
|
14 public int index;
|
|
15 public String from;
|
|
16 public CommandType type;
|
|
17 public String managerKey;
|
|
18 public String key;
|
|
19
|
|
20 public Receiver(InputDataSegment ids, CommandType type) {
|
|
21 this.ids = ids;
|
|
22 this.type = type;
|
|
23 ids.register();
|
|
24
|
|
25 }
|
|
26
|
|
27 public void setQuickKey(String managerKey, String key){
|
|
28 setQuickKey(managerKey, key, 0);
|
|
29 }
|
345
|
30
|
417
|
31 public void setQuickKey(String managerKey, String key, int index) {
|
|
32 this.managerKey = managerKey;
|
|
33 this.key = key;
|
|
34 switch (type) {
|
|
35 case PEEK:
|
|
36 ids.quickPeek(this);
|
|
37 break;
|
|
38 case TAKE:
|
|
39 ids.quickTake(this);
|
|
40 break;
|
|
41 default:
|
|
42 break;
|
|
43 }
|
|
44 ids.setKey();
|
|
45 }
|
|
46
|
|
47 public void setKey(String managerKey, String key) {
|
|
48 setKey(managerKey, key, 0);
|
|
49 }
|
345
|
50
|
417
|
51 public void setKey(String managerKey, String key, int index) {
|
|
52 this.managerKey = managerKey;
|
|
53 this.key = key;
|
|
54 this.index = index;
|
|
55 switch (type) {
|
|
56 case PEEK:
|
|
57 ids.peek(this);
|
|
58 break;
|
|
59 case TAKE:
|
|
60 ids.take(this);
|
|
61 break;
|
|
62 default:
|
|
63 break;
|
|
64 }
|
|
65 ids.setKey();
|
|
66 }
|
|
67
|
|
68 public void setKey(String key) {
|
|
69 setKey(key, 0);
|
|
70 }
|
345
|
71
|
417
|
72 public void setKey(String key, int index) {
|
|
73 this.key = key;
|
|
74 this.index = index;
|
|
75 switch (type) {
|
|
76 case PEEK:
|
|
77 ids.peek(this);
|
|
78 break;
|
|
79 case TAKE:
|
|
80 ids.take(this);
|
|
81 break;
|
|
82 default:
|
|
83 break;
|
|
84 }
|
|
85 ids.setKey();
|
|
86 }
|
345
|
87
|
417
|
88 public void setData(ReceiverData r) {
|
|
89 data = r;
|
|
90 }
|
345
|
91
|
417
|
92 public int asInteger() {
|
|
93 return data.asInteger();
|
|
94 }
|
|
95
|
|
96 public String asString() {
|
|
97 return data.asString();
|
|
98 }
|
345
|
99
|
417
|
100 public <T> T asClass(Class<T> clazz) {
|
|
101 return data.asClass(clazz);
|
|
102 }
|
345
|
103
|
417
|
104 public Object getObj() {
|
|
105 return data.getObj();
|
|
106 }
|
|
107
|
|
108 public Object getVal() {
|
|
109 return data.getVal();
|
|
110 }
|
|
111
|
345
|
112 }
|