Mercurial > hg > Members > tatsuki > Alice
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 |
rev | line source |
---|---|
3 | 1 package alice.codesegment; |
2 | |
3 import java.util.concurrent.atomic.AtomicInteger; | |
4 | |
202 | 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 | 7 import alice.datasegment.DataSegment; |
212 | 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 | 10 |
57 | 11 /** |
12 * InputDataSegment Manager | |
13 * keep tracking unbound/bound count | |
14 * @author kazz | |
15 * | |
16 */ | |
3 | 17 public class InputDataSegment { |
18 | |
119 | 19 public CodeSegment cs; |
57 | 20 private AtomicInteger count = new AtomicInteger(1); // 1 for no input data segments |
21 private AtomicInteger keyCount = new AtomicInteger(0); // number of DataSegments | |
3 | 22 |
23 public InputDataSegment(CodeSegment cs) { | |
24 this.cs = cs; | |
25 } | |
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 | 28 peek(receiver, managerKey, key, 0); |
3 | 29 } |
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 | 32 DataSegment.get(managerKey).peek(receiver, key, index, cs); |
3 | 33 } |
34 | |
65 | 35 public void peek(Receiver receiver, String key) { |
36 peek(receiver, key, 0); | |
37 } | |
38 | |
39 public void peek(Receiver receiver, String key, int index) { | |
40 DataSegment.getLocal().peek(receiver, key, index, cs); | |
41 } | |
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 | 44 take(receiver, managerKey, key, 0); |
3 | 45 } |
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 | 48 DataSegment.get(managerKey).take(receiver, key, index, cs); |
3 | 49 } |
7 | 50 |
65 | 51 public void take(Receiver receiver, String key) { |
52 take(receiver, key, 0); | |
53 } | |
54 | |
55 public void take(Receiver receiver, String key, int index) { | |
56 DataSegment.getLocal().take(receiver, key, index, cs); | |
57 } | |
58 | |
209 | 59 public void reply(Receiver receiver, Command reply) { |
60 receiver.index = reply.index; | |
61 receiver.from = reply.reverseKey; | |
218 | 62 if (reply.reverseKey==null){ |
63 receiver.setData(new ReceiveRemoteData(reply.val)); | |
64 } else if (!reply.reverseKey.equals("local")) { | |
212 | 65 receiver.setData(new ReceiveRemoteData(reply.val)); |
66 } else { | |
218 | 67 receiver.setData(new ReceiveLocalData(reply.obj)); |
212 | 68 } |
19 | 69 receive(); |
70 } | |
71 | |
72 public void regist() { | |
73 count.getAndIncrement(); | |
74 keyCount.getAndIncrement(); | |
9 | 75 } |
76 | |
19 | 77 public void setKey() { |
78 if (keyCount.decrementAndGet() == 0) { | |
79 receive(); | |
80 } | |
81 } | |
82 | |
83 public void receive() { | |
8 | 84 if (count.decrementAndGet() == 0) { |
57 | 85 CodeSegmentManager.submit(cs); |
8 | 86 } |
87 } | |
32
2bfb796b0fa1
change method to create DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
88 |
57 | 89 /** |
90 * InputDataSegment factory | |
91 * @param type PEEK or TAKE | |
92 * @return Receiver of DataSegment reply | |
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 | 97 } |