package com.eactive.eai.agent.circuitBreaker.type;

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.common.circuitBreaker.type.TypedCircuitBreakerManager;

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

	public ReloadTypedCircuitBreakerCommand() {
		super("ReloadInflowInterfaceControlCommand");
	}

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

		String keyName;
		if (!(this.args instanceof String)) {
			keyName = "RECEAIMCM001";
			String msg = this.makeException(keyName, (Throwable) null);
			if (logger.isError()) {
				logger.error(msg);
			}

			throw new CommandException(msg);
		} else {
			keyName = (String) this.args;

			try {
				TypedCircuitBreakerManager manager = TypedCircuitBreakerManager.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.");
						}
					}
				}

				return "success";
			} catch (Exception var6) {
				String rspErrorCode = "RECEAIMCM002";
				String msg = this.makeException(rspErrorCode, var6);
				if (logger.isError()) {
					logger.error(msg, var6);
				}

				throw new CommandException(msg);
			}
		}
	}
}