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 RemoveFCReceiverCommand extends Command {
	private static final long serialVersionUID = 1L;

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

	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 {

			String queRcverName = (String) args;
			FCQueueReceiverManager manager = FCQueueReceiverManager.getInstance();

			if (logger.isInfo()) {
				logger.info(this.name + " Remove[" + queRcverName + "]");
			}
			if (queRcverName != null) {
				manager.removeFCQueueReceiver(queRcverName);
			} else {
				throw new CommandException("ReceiverName Error - " + queRcverName);
			}

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

	}
}
