package com.eactive.eai.agent.eaimessage;

import java.util.Vector;

import com.eactive.eai.agent.command.Command;
import com.eactive.eai.agent.command.CommandException;
import com.eactive.eai.common.message.EAIMessageManager;
import com.eactive.eai.common.util.Logger;

public class RemoveEAIMessageListCommand extends Command {

	private static final long serialVersionUID = 1L;

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

    /** 
    * 1. 기능 :  EAIMessageManager의  EAIMessage 제거
    * 2. 처리 개요 : EAIMessage EAISvrInstNm이 DEFAULT_SERVER(ALL) 이거나  LocalServer인 경우
    *               EAIMessageManager의  EAIMessage 제거
    * 3. 주의사항 
    *
    * @exception    CommandException	Argument Type이 다르거나 Command 수행중 Excpetion이 발생할 경우
    **/
	public Object execute() throws CommandException {
		Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
		if (logger.isInfo())
			logger.info(this.name + " is executed");

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

		try {
			EAIMessageManager manager = EAIMessageManager.getInstance();

			Vector keyNameVt = (Vector) args;
			String keyName = "";
			for (int i = 0; i < keyNameVt.size(); i++) {
				keyName = (String) keyNameVt.get(i);
				if (keyName != null) {
					manager.removeEAIMessage(keyName);
					if (logger.isWarn())
						logger.warn(this.name + "] " + keyName + " Remove.");
				}
			}

		} catch (Exception e) {
			String rspErrorCode = "RECEAIMCM002";
			String msg = makeException(rspErrorCode, e);
			if (logger.isError())
				logger.error(msg, e);
			throw new CommandException(msg);
		}
		return "success";

	}

}
