Mercurial > hg > Database > Alice
view src/main/java/alice/codesegment/OutputDataSegment.java @ 527:bfec2c3ff1b8 dispose
change unzip
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 30 Apr 2015 18:14:02 +0900 |
parents | 928907206d21 |
children | 4aeebea0c9b5 |
line wrap: on
line source
package alice.codesegment; import alice.datasegment.CommandType; import alice.datasegment.DataSegment; import alice.datasegment.ReceiveData; import alice.datasegment.Receiver; import alice.datasegment.SendOption; public class OutputDataSegment { private boolean compressFlag = false;//圧縮するかどうか /** * for local */ /** * input→ds変更→outputのときコピーを防ぐ */ public void flip(Receiver receiver) { if (receiver.isCompressed()){ DataSegment.getCompressedLocal().put(receiver.key, receiver.getReceiveData(), null); } else { DataSegment.getLocal().put(receiver.key, receiver.getReceiveData(), null); } } public void flip(Receiver receiver, CommandType type) { switch (type) { case PUT: if (receiver.isCompressed()){ DataSegment.getCompressedLocal().put(receiver.key, receiver.getReceiveData(), null);//localなら全部false。 } else { DataSegment.getLocal().put(receiver.key, receiver.getReceiveData(), null); } break; case UPDATE: if (receiver.isCompressed()){ DataSegment.getCompressedLocal().update(receiver.key, receiver.getReceiveData(), null); } else { DataSegment.getLocal().update(receiver.key, receiver.getReceiveData(), null); } break; default: break; } } public void put(String key, ReceiveData rData) { DataSegment.getLocal().put(key, rData, null); } public void put(String key, Object val) { ReceiveData rData = new ReceiveData(val); DataSegment.getLocal().put(key, rData, new SendOption(false, false)); } public void put(String key, Object val, boolean cFlag) {///追加 ReceiveData rData = new ReceiveData(val); DataSegment.getLocal().put(key, rData, new SendOption(false, cFlag)); } public void update(String key, Object val) { ReceiveData rData = new ReceiveData(val); DataSegment.getLocal().update(key, rData, new SendOption(false, false)); } public void update(String key, Object val, boolean cFlag) {///追加 ReceiveData rData = new ReceiveData(val); DataSegment.getLocal().update(key, rData, new SendOption(false, cFlag)); } /** * for remote */ public void put(String managerKey, String key, ReceiveData rData) { if (!managerKey.equals("local") && DataSegment.contains(managerKey)){ SendOption option = new SendOption(false, rData.compressed()); //SendOption option = new SendOption(false, compressFlag); if (rData.compressed()){ DataSegment.get(managerKey + "!").put(key, rData, option); } else { DataSegment.get(managerKey).put(key, rData, option); } } else { put(key, rData); } } public void put(String managerKey, String key, Object val) { put(managerKey, key, val, false); } public void put(String managerKey, String key, Object val, boolean cFlag) {//追加 System.out.println("in PUT"); ReceiveData rData = new ReceiveData(val); SendOption option = new SendOption(false, cFlag); //rData.setCompressFlag(cFlag); if (!managerKey.equals("local") && DataSegment.contains(managerKey)){///if remote if (cFlag){ DataSegment.get(managerKey + "!").put(key, rData, option); } else { DataSegment.get(managerKey).put(key, rData, option); } } else {// if local if (cFlag){ DataSegment.getCompressedLocal().put(key, rData, option); } else { put(key, val); } } } public void quickPut(String managerKey, String key, ReceiveData rData) { if (!managerKey.equals("local") && DataSegment.contains(managerKey)){ SendOption option = new SendOption(true, false); if (rData.compressed()){ DataSegment.get(managerKey + "!").put(key, rData, option); } else { DataSegment.get(managerKey).put(key, rData, option); } } else { put(key, rData); } } public void quickPut(String managerKey, String key, Object val) { quickPut(managerKey, key, val, false); } public void quickPut(String managerKey, String key, Object val, boolean cFlag) {//追加 if (!managerKey.equals("local") && DataSegment.contains(managerKey)){ ReceiveData rData = new ReceiveData(val); SendOption option = new SendOption(true, cFlag); //rData.setCompressFlag(cFlag); if (cFlag){ DataSegment.get(managerKey + "!").put(key, rData, option); } else { DataSegment.get(managerKey).put(key, rData, option); } } else { put(key, val); } } public void update(String managerKey, String key, ReceiveData rData) { if (!managerKey.equals("local") && DataSegment.contains(managerKey)){ SendOption option = new SendOption(false, rData.compressed()); if (rData.compressed()){ DataSegment.get(managerKey + "!").update(key, rData, option); } else { DataSegment.get(managerKey).update(key, rData, option); } } else { update(key, rData); } } public void update(String managerKey, String key, Object val) { update(managerKey, key, val, false); } public void update(String managerKey, String key, Object val, boolean cFlag) {//追加 ReceiveData rData = new ReceiveData(val); SendOption option = new SendOption(false, cFlag); //rData.setCompressFlag(cFlag); if (!managerKey.equals("local") && DataSegment.contains(managerKey)){///if remote if (cFlag){ DataSegment.get(managerKey + "!").update(key, rData, option); } else { DataSegment.get(managerKey).update(key, rData, option); } } else {// if local if (cFlag){ DataSegment.getCompressedLocal().update(key, rData, option); } else { update(key, val); } } } public void quickUpdate(String managerKey, String key, ReceiveData rData) { if (!managerKey.equals("local") && DataSegment.contains(managerKey)){ SendOption option = new SendOption(true, rData.compressed()); if (rData.compressed()){ DataSegment.get(managerKey + "!").update(key, rData, option); } else { DataSegment.get(managerKey).update(key, rData, option); } } else { update(key, rData); } } public void quickUpdate(String managerKey, String key, Object val) { quickUpdate(managerKey, key, val, false); } public void quickUpdate(String managerKey, String key, Object val, boolean cFlag) {//追加 if (!managerKey.equals("local") && DataSegment.contains(managerKey)){ ReceiveData rData = new ReceiveData(val); SendOption option = new SendOption(true, cFlag); //rData.setCompressFlag(cFlag); if (cFlag){ DataSegment.get(managerKey + "!").update(key, rData, option); } else { DataSegment.get(managerKey).update(key, rData, option); } } else { update(key, val); } } /** * kill the Alice process after send other messages. * * @param managerKey */ public void finish(String managerKey) { if (DataSegment.contains(managerKey)) DataSegment.get(managerKey).finish(); } /** * close socket for RemoteDataSegment after send other messages. * * @param managerKey */ public void close(String managerKey) { if (DataSegment.contains(managerKey)) DataSegment.get(managerKey).close(); } /** * "key" is not remote DataSegment's key. * "Ping Response" return in this "key" * * @param managerKey * @param returnKey */ public void ping(String managerKey, String returnKey) { if (DataSegment.contains(managerKey)) DataSegment.get(managerKey).ping(returnKey); } public boolean compressFlag() { return compressFlag; } public void setCompressFlag(boolean cFlag) { compressFlag = cFlag; } }