package com.ext.eai.agent.submessage;

import java.util.Vector;

import com.eactive.eai.agent.command.Command;
import com.eactive.eai.agent.command.CommandException;
import com.eactive.eai.common.submessage.SubMessageManager;
import com.eactive.eai.common.util.Logger;

public class ReloadSubMessageListCommand extends Command {
	private static final long serialVersionUID = 1L;

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

	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 {
			SubMessageManager manager = SubMessageManager.getInstance();

			Vector messageVt = (Vector) args;
			String key = "";
			for (int i = 0; i < messageVt.size(); i++) {
				key = (String) messageVt.get(i);

				if (key != null) {
					manager.reload(key);
					if (logger.isWarn())
						logger.warn(this.name + "] " + key + " 에 대한 정보가 Reload 되었습니다.");
				}
			}
		} catch (Exception e) {
			String rspErrorCode = "RECEAIMCM002";
			String msg = makeException(rspErrorCode, e);
			if (logger.isError())
				logger.error(msg, e);
			throw new CommandException(msg);
		}
		return "success";
	}

//	   public static void main(String args[]) throws Exception {
//	   test();
//}

// private static void test() throws Exception {
//        Command command = new ReloadSubMessageListCommand();
//        command.setArgs("ALL");
//        AgentUtil.broadcast(command);
//        
//    }
}
