Mercurial > hg > Members > tatsuki > Alice
view src/alice/codesegment/OutputDataSegment.java @ 212:b5daccf36104 working
add Receiver state pattern
author | one |
---|---|
date | Wed, 27 Mar 2013 17:30:52 +0900 |
parents | b8f72b378f18 |
children | 3f20b6401823 |
line wrap: on
line source
package alice.codesegment; import java.io.IOException; import org.msgpack.type.Value; import org.msgpack.type.ValueFactory; import alice.datasegment.Command; import alice.datasegment.CommandType; import alice.datasegment.DataSegment; import alice.datasegment.DataSegmentKey; import alice.datasegment.Receiver; import alice.test.codesegment.local.bitonicsort.DataList; public class OutputDataSegment { /** * for local */ public <T> void put(String key, T val,Boolean covertFlag) { if (covertFlag){ put(key, val); } else { DataSegment.getLocal().put(key, val); } } public <T> void update(String key, T val,Boolean covertFlag) { if (covertFlag){ update(key, val); } else { DataSegment.getLocal().update(key, val); } } public void flip(Receiver receiver) { //DataSegment.getLocal().put(receiver.key, receiver.val,receiver.obj); DataSegmentKey key = DataSegment.getLocal().getDataSegmentKey(receiver.data.key); key.runCommand(new Command(CommandType.PUT,null,null, receiver.data.val,receiver.data.obj, 0,0,null,null, "local")); } public void put(String key, Value val) { DataSegment.getLocal().put(key, val); } public void put(String key, String val) { DataSegment.getLocal().put(key, ValueFactory.createRawValue(val)); } public void put(String key, byte[] val) { DataSegment.getLocal().put(key, ValueFactory.createRawValue(val, true)); } public void put(String key, int val) { DataSegment.getLocal().put(key, ValueFactory.createIntegerValue(val)); } public <T> void put(String key, T val) { DataSegment.getLocal().put(key, (Object)val); } public void update(String key, Value val) { DataSegment.getLocal().update(key, val); } public void update(String key, String val) { DataSegment.getLocal().update(key, ValueFactory.createRawValue(val)); } public void update(String key, byte[] val) { DataSegment.getLocal().update(key, ValueFactory.createRawValue(val, true)); } public void update(String key, int val) { DataSegment.getLocal().update(key, ValueFactory.createIntegerValue(val)); } public <T> void update(String key, T val) { DataSegment.getLocal().update(key, (Object)val); } /** * for remote */ public void put(String managerKey, String key, Value val) { DataSegment.get(managerKey).put(key, val); } public void put(String managerKey, String key, String val) { DataSegment.get(managerKey).put(key, ValueFactory.createRawValue(val)); } public void put(String managerKey, String key, byte[] val) { DataSegment.get(managerKey).put(key, ValueFactory.createRawValue(val, true)); } public void put(String managerKey, String key, int val) { DataSegment.get(managerKey).put(key, ValueFactory.createIntegerValue(val)); } public <T> void put(String managerKey, String key, T val) { try { DataSegment.get(managerKey).put(key, SingletonMessage.getInstance().unconvert(val)); } catch (IOException e) { e.printStackTrace(); } } public void update(String managerKey, String key, Value val) { DataSegment.get(managerKey).update(key, val); } public void update(String managerKey, String key, String val) { DataSegment.get(managerKey).update(key, ValueFactory.createRawValue(val)); } public void update(String managerKey, String key, byte[] val) { DataSegment.get(managerKey).update(key, ValueFactory.createRawValue(val, true)); } public void update(String managerKey, String key, int val) { DataSegment.get(managerKey).update(key, ValueFactory.createIntegerValue(val)); } public <T> void update(String managerKey, String key, T val) { try { DataSegment.get(managerKey).update(key, SingletonMessage.getInstance().unconvert(val)); } catch (IOException e) { e.printStackTrace(); } } /** * kill the Alice process after send other messages. * * @param managerKey */ public void finish(String managerKey) { DataSegment.get(managerKey).finish(); } /** * close socket for RemoteDataSegment after send other messages. * * @param managerKey */ public void close(String managerKey) { DataSegment.get(managerKey).close(); } }