package com.hmsoft.common.bizlogic;

import com.hmsoft.common.bizinf.IExecuteLogic;
import com.hmsoft.remote.rmi.exception.RemotingException;
import com.hmsoft.remote.rmi.future.IFuture;
import com.hmsoft.remote.rmi.future.TransFuture;
import com.hmsoft.remote.rmi.model.Request;
import com.hmsoft.remote.rmi.transport.NettyChannel;

/**
 * 
 * @author zq
 *
 */
public class RequestLogic implements IExecuteLogic {

	private final int TIME_OUT = 3000;
	private Request req;
	private NettyChannel channel;
	
	public RequestLogic(final Request req, final NettyChannel channel) {
		this.req = req;
		this.channel = channel;
	}
	
	@Override
	public Object execute() throws RemotingException {
        IFuture future = new TransFuture(this.channel, req, TIME_OUT);
        try {
			this.channel.send(req, false);
			return future.get();
		} catch (RemotingException e) {
			throw e;
		}
	}

}
