package com.eactive.eai.agent.fcqueuereceiver;

import com.eactive.eai.agent.command.Command;
import com.eactive.eai.agent.command.CommandException;
import com.eactive.eai.common.util.Logger;
import com.eactive.eai.flowcontrol.jms.FCQueueReceiverManager;

public class ReloadFCReceiverCommand extends Command {

	private static final long serialVersionUID = 1L;

	public ReloadFCReceiverCommand() {
		super("ReloadFCReceiverCommand");
	}

	public Object execute() throws CommandException {
		Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
		if (logger.isInfo())
			logger.info(this.name + " is executed");

		if (!(args instanceof String)) {
			String rspErrorCode = "RECEAIMCM001";
			String msg = makeException(rspErrorCode, null);
			if (logger.isError())
				logger.error(msg);
			throw new CommandException(msg);
		}

		try {
			FCQueueReceiverManager manager = FCQueueReceiverManager.getInstance();

			String queRcverName = (String) args;
			if (logger.isInfo()) {
				logger.info(this.name + " Reload[" + queRcverName + "]");
			}

			if (queRcverName != null) {
				manager.loadFCQueueReceiver(queRcverName);
			}

		} catch (Exception e) {
			if (logger.isError())
				logger.error(e.getMessage(), e);
			throw new CommandException(e.getMessage());
		}
		return "success";

	}

}
