annotate src/alice/codesegment/InputDataSegment.java @ 218:d50cddf64396 working

TestRemoteAlice works
author sugi
date Wed, 27 Mar 2013 20:35:08 +0900
parents b5daccf36104
children 913ee9dfec4f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
1 package alice.codesegment;
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
2
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
3 import java.util.concurrent.atomic.AtomicInteger;
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
4
202
7f47231ef509 add new flip API
sugi
parents: 199
diff changeset
5 import alice.datasegment.Command;
32
2bfb796b0fa1 change method to create DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
6 import alice.datasegment.CommandType;
3
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
7 import alice.datasegment.DataSegment;
212
b5daccf36104 add Receiver state pattern
one
parents: 209
diff changeset
8 import alice.datasegment.ReceiveRemoteData;
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
9 import alice.datasegment.Receiver;
3
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
10
57
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
11 /**
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
12 * InputDataSegment Manager
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
13 * keep tracking unbound/bound count
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
14 * @author kazz
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
15 *
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
16 */
3
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
17 public class InputDataSegment {
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
18
119
f84e1684c6be put NULL in CS
sugi
parents: 65
diff changeset
19 public CodeSegment cs;
57
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
20 private AtomicInteger count = new AtomicInteger(1); // 1 for no input data segments
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
21 private AtomicInteger keyCount = new AtomicInteger(0); // number of DataSegments
3
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
22
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
23 public InputDataSegment(CodeSegment cs) {
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
24 this.cs = cs;
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
25 }
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
26
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
27 public void peek(Receiver receiver, String managerKey, String key) {
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
28 peek(receiver, managerKey, key, 0);
3
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
29 }
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
30
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
31 public void peek(Receiver receiver, String managerKey, String key, int index) {
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
32 DataSegment.get(managerKey).peek(receiver, key, index, cs);
3
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
33 }
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
34
65
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
35 public void peek(Receiver receiver, String key) {
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
36 peek(receiver, key, 0);
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
37 }
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
38
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
39 public void peek(Receiver receiver, String key, int index) {
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
40 DataSegment.getLocal().peek(receiver, key, index, cs);
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
41 }
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
42
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
43 public void take(Receiver receiver, String managerKey, String key) {
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
44 take(receiver, managerKey, key, 0);
3
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
45 }
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
46
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
47 public void take(Receiver receiver, String managerKey, String key, int index) {
18
72dd27d952b0 change InputDataSegment API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
48 DataSegment.get(managerKey).take(receiver, key, index, cs);
3
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
49 }
7
352eb19d837d implements reply of LocalDataSegment
one
parents: 5
diff changeset
50
65
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
51 public void take(Receiver receiver, String key) {
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
52 take(receiver, key, 0);
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
53 }
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
54
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
55 public void take(Receiver receiver, String key, int index) {
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
56 DataSegment.getLocal().take(receiver, key, index, cs);
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
57 }
ca42a2c8ac22 add local access api
kazz
parents: 57
diff changeset
58
209
96110f25adcc add new flip API
sugi
parents: 205
diff changeset
59 public void reply(Receiver receiver, Command reply) {
96110f25adcc add new flip API
sugi
parents: 205
diff changeset
60 receiver.index = reply.index;
96110f25adcc add new flip API
sugi
parents: 205
diff changeset
61 receiver.from = reply.reverseKey;
218
d50cddf64396 TestRemoteAlice works
sugi
parents: 212
diff changeset
62 if (reply.reverseKey==null){
d50cddf64396 TestRemoteAlice works
sugi
parents: 212
diff changeset
63 receiver.setData(new ReceiveRemoteData(reply.val));
d50cddf64396 TestRemoteAlice works
sugi
parents: 212
diff changeset
64 } else if (!reply.reverseKey.equals("local")) {
212
b5daccf36104 add Receiver state pattern
one
parents: 209
diff changeset
65 receiver.setData(new ReceiveRemoteData(reply.val));
b5daccf36104 add Receiver state pattern
one
parents: 209
diff changeset
66 } else {
218
d50cddf64396 TestRemoteAlice works
sugi
parents: 212
diff changeset
67 receiver.setData(new ReceiveLocalData(reply.obj));
212
b5daccf36104 add Receiver state pattern
one
parents: 209
diff changeset
68 }
19
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
69 receive();
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
70 }
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
71
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
72 public void regist() {
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
73 count.getAndIncrement();
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
74 keyCount.getAndIncrement();
9
22afbb2919f1 execute() api
one
parents: 8
diff changeset
75 }
22afbb2919f1 execute() api
one
parents: 8
diff changeset
76
19
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
77 public void setKey() {
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
78 if (keyCount.decrementAndGet() == 0) {
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
79 receive();
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
80 }
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
81 }
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
82
e7867328a2fb change execute() API
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 18
diff changeset
83 public void receive() {
8
78b415d019de Local DS and CS work! maybe...
one
parents: 7
diff changeset
84 if (count.decrementAndGet() == 0) {
57
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
85 CodeSegmentManager.submit(cs);
8
78b415d019de Local DS and CS work! maybe...
one
parents: 7
diff changeset
86 }
78b415d019de Local DS and CS work! maybe...
one
parents: 7
diff changeset
87 }
32
2bfb796b0fa1 change method to create DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
88
57
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
89 /**
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
90 * InputDataSegment factory
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
91 * @param type PEEK or TAKE
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
92 * @return Receiver of DataSegment reply
7fa9ddb31f64 add comment
one
parents: 44
diff changeset
93 */
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
94 public Receiver create(CommandType type) {
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
95 return new Receiver(this, type);
32
2bfb796b0fa1 change method to create DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
96 }
3
91057e15065f add DataSegment API and CodeSegment
one
parents:
diff changeset
97 }