package com.eactive.eai.agent.useDate;

import com.eactive.eai.agent.command.Command;
import com.eactive.eai.agent.command.CommandException;
import com.eactive.eai.common.usedate.UseDateControlManager;
import com.eactive.eai.common.util.Logger;

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

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

    /** 
    * 1. 기능 :  UseDateControlManager에 interface용 bucket을 리로드
    * 2. 처리 개요 : 
    * 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 String)) {
			String rspErrorCode = "RECEAIMCM001";
			String msg = makeException(rspErrorCode, null);
			if (logger.isError())
				logger.error(msg);
			throw new CommandException(msg);
		}

		String keyName = (String) args;
		try {
			UseDateControlManager manager = UseDateControlManager.getInstance();

			if (keyName != null) {
				if ("ALL".equals(keyName)) {
					manager.reload();
					if (logger.isWarn())
						logger.warn(this.name + "] all rule Reload.");
				} else {
					manager.reload(keyName);
					if (logger.isWarn())
						logger.warn(this.name + "] " + keyName + " 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";

	}

}
