view src/main/java/alice/datasegment/Command.java @ 345:8f71c3e6f11d

Change directory structure Maven standard
author sugi
date Wed, 16 Apr 2014 18:26:07 +0900
parents
children aefbe41fcf12
line wrap: on
line source

package alice.datasegment;

import java.io.IOException;
import java.util.concurrent.BlockingQueue;
import org.msgpack.type.Value;

import alice.codesegment.CodeSegment;
import alice.codesegment.SingletonMessage;
import alice.daemon.CommandMessage;
import alice.daemon.Connection;

public class Command {
	public CommandType type;
	public String key;
	public Receiver receiver;
	public Value val;
	public int index;
	public int seq;
	public Connection connection; // for remote
	public BlockingQueue<Command> replyQueue;
	public CodeSegment cs;
	public String reverseKey;
	public Object obj;
	public boolean flag;

	public Command(CommandType cmdType, Receiver receiver, String key, Value val, int index, int seq, BlockingQueue<Command> replyQueue, CodeSegment cs, String reverseKey) {
		this.type = cmdType;
		this.receiver = receiver;
		this.key = key;
		this.val = val;
		this.index = index;
		this.seq = seq;
		this.replyQueue = replyQueue;
		this.cs = cs;
		this.reverseKey = reverseKey;
		this.flag = false;
	}
	
	public Command(CommandType cmdType, Receiver receiver, String key, Value val, int index, int seq, BlockingQueue<Command> replyQueue, CodeSegment cs, String reverseKey, boolean flag) {
		this.type = cmdType;
		this.receiver = receiver;
		this.key = key;
		this.val = val;
		this.index = index;
		this.seq = seq;
		this.replyQueue = replyQueue;
		this.cs = cs;
		this.reverseKey = reverseKey;
		this.flag = flag;
	}
	
	public Command(CommandType cmdType, Receiver receiver, String key, Value val, int index, int seq, Connection connection, CodeSegment cs, String reverseKey, boolean flag) {
		this.type = cmdType;
		this.receiver = receiver;
		this.key = key;
		this.val = val;
		this.index = index;
		this.seq = seq;
		this.connection = connection;
		this.cs = cs;
		this.reverseKey = reverseKey;
		this.flag = flag;
	}
	
	public Command(CommandType cmdType, Receiver receiver, String key, Object obj, int index, int seq, BlockingQueue<Command> replyQueue, CodeSegment cs, String reverseKey) {
		this.type = cmdType;
		this.receiver = receiver;
		this.key = key;
		this.obj = obj;
		this.index = index;
		this.seq = seq;
		this.replyQueue = replyQueue;
		this.cs = cs;
		this.reverseKey = reverseKey;
		this.flag = false;
	}
	
	public Command(CommandType cmdType, Receiver receiver, String key, Value val, Object obj, int index, int seq, BlockingQueue<Command> replyQueue, CodeSegment cs, String reverseKey) {
		this.type = cmdType;
		this.receiver = receiver;
		this.key = key;
		this.val = val;
		this.obj = obj;
		this.index = index;
		this.seq = seq;
		this.replyQueue = replyQueue;
		this.cs = cs;
		this.reverseKey = reverseKey;
		this.flag = false;
	}
	
	public String getCommandString() {
		String csName = "null";
		if (cs != null) {
			csName = cs.toString();
		}
		return this.type + "\t" + key + "\t" + val + "\tindex=" + index + "\tcs=" + csName;
	}
	public CommandMessage convert() {
		if (val==null&&obj!=null){
			try {
				this.val = SingletonMessage.getInstance().unconvert(obj);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return new CommandMessage(type.id, index, seq, key, val, flag);
	}
	
}