package com.eactive.eai.agent.b2bservice;

import java.util.Vector;

import com.eactive.eai.agent.command.Command;
import com.eactive.eai.agent.command.CommandException;
import com.eactive.eai.common.b2bservice.B2BServiceManager;
import com.eactive.eai.common.util.Logger;

public class ReloadB2BServiceListCommand extends Command {

	private static final long serialVersionUID = 1L;

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

	@Override
	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);
		}

		B2BServiceManager manager = B2BServiceManager.getInstance();
		try {
			Vector keyNameVt = (Vector) args;
			String keyName = "";
			for (int i = 0; i < keyNameVt.size(); i++) {
				keyName = (String) keyNameVt.get(i);
				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";
	}
}
