Mercurial > hg > Database > Alice
view src/alice/codesegment/InputDataSegment.java @ 202:7f47231ef509 working
add new flip API
author | sugi |
---|---|
date | Mon, 25 Mar 2013 17:46:07 +0900 |
parents | 15b68b65f8a4 |
children | 28469b1671e7 |
line wrap: on
line source
package alice.codesegment; import java.util.concurrent.atomic.AtomicInteger; import org.msgpack.type.Value; import alice.datasegment.Command; import alice.datasegment.CommandType; import alice.datasegment.DataSegment; import alice.datasegment.DataSegmentValue; import alice.datasegment.Receiver; /** * InputDataSegment Manager * keep tracking unbound/bound count * @author kazz * */ public class InputDataSegment { public CodeSegment cs; private AtomicInteger count = new AtomicInteger(1); // 1 for no input data segments private AtomicInteger keyCount = new AtomicInteger(0); // number of DataSegments private Command cmd; public InputDataSegment(CodeSegment cs) { this.cs = cs; } public void peek(Receiver receiver, String managerKey, String key) { peek(receiver, managerKey, key, 0); } public void peek(Receiver receiver, String managerKey, String key, int index) { DataSegment.get(managerKey).peek(receiver, key, index, cs); } public void peek(Receiver receiver, String key) { peek(receiver, key, 0); } public void peek(Receiver receiver, String key, int index) { DataSegment.getLocal().peek(receiver, key, index, cs); } public void take(Receiver receiver, String managerKey, String key) { take(receiver, managerKey, key, 0); } public void take(Receiver receiver, String managerKey, String key, int index) { DataSegment.get(managerKey).take(receiver, key, index, cs); } public void take(Receiver receiver, String key) { take(receiver, key, 0); } public void take(Receiver receiver, String key, int index) { DataSegment.getLocal().take(receiver, key, index, cs); } public void flip(CommandType type, String key, Value val,Object obj) { cmd.setElement(type, key, val, obj); DataSegment.getLocal().flip(cmd); } public void reply(Receiver receiver, DataSegmentValue val) { receiver.index = val.index; receiver.val = val.val; receiver.from = val.from; receiver.obj = val.obj; receive(); } public void regist() { count.getAndIncrement(); keyCount.getAndIncrement(); } public void setKey() { if (keyCount.decrementAndGet() == 0) { receive(); } } public void receive() { if (count.decrementAndGet() == 0) { CodeSegmentManager.submit(cs); } } /** * InputDataSegment factory * @param type PEEK or TAKE * @return Receiver of DataSegment reply */ public Receiver create(CommandType type) { return new Receiver(this, type); } public void setCommand(Command cmd) { this.cmd = cmd; } public void reply(Receiver receiver, int index, Value val, Object obj, String reverseKey) { // TODO Auto-generated method stub } }