package com.eactive.eai.common.routing.pool;

import java.util.Properties;

import org.apache.commons.lang.time.StopWatch;

import com.eactive.eai.common.message.EAIMessage;
import com.eactive.eai.common.routing.RemoteProxyClient;
import com.eactive.eai.common.routing.RouteKeys;
import com.eactive.eai.common.util.Logger;

public class PublishThread implements Runnable {
	static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
	private java.util.Properties callProp;
	private com.eactive.eai.common.message.EAIMessage eaiMessage;
	
	public PublishThread(Properties callProp, EAIMessage eaiMessage) {
		this.callProp = callProp;
		this.eaiMessage = eaiMessage;
	}
	
	public void run(){
		// RemoteProxyClient로 Remote의 EJB 호출
		StopWatch stopWatch = new StopWatch();
		stopWatch.start();
		if (logger.isInfo()) {
			logger.info("PublishThread] RemoteProxyClient call - " + callProp.getProperty(RouteKeys.REMOTE_CONTAINER_ID) + " "
					+ callProp.getProperty(RouteKeys.REMOTE_CALL_URL));
		}

		try {
			RemoteProxyClient.callProxyBean(eaiMessage, callProp);
		} catch (Exception e) {
			if (logger.isError())
				logger.error("PublishThread] RemoteProxyClient call ERROR." + e.getMessage(), e);
		} finally {
			;
		}
		stopWatch.stop();
		if (logger.isInfo()) {
			logger.info("PublishThread] RemoteProxyClient result time(" + stopWatch.getTime()
					+ ")");
		}
	}

}
