view src/alice/codesegment/OutputDataSegment.java @ 195:b4ca7f75e6b2 working

add put , Update API (no convert to value)
author e095732
date Tue, 12 Mar 2013 00:49:19 +0900
parents a8b0d44bbe68
children 15b68b65f8a4
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.DataSegment;

public class OutputDataSegment {
	
	/**
	 * for local
	 */
	public <T> void put(String key, T val,Boolean flag) {
		if (flag){ 
			put(key, val);
		} else {
			DataSegment.getLocal().put(key, val);
		}
	}
	
	public <T> void update(String key, T val,Boolean flag) {
		if (flag){ 
			update(key, val);
		} else {
			DataSegment.getLocal().update(key, val);
		}
	}
	
	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) {
		try {
			DataSegment.getLocal().put(key, SingletonMessage.getInstance().unconvert(val));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	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) {
		try {
			DataSegment.getLocal().update(key, SingletonMessage.getInstance().unconvert(val));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	/**
	 * 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();
	}

}