package com.eactive.eai.agent.b2bextractor;

import java.util.Vector;

import com.eactive.eai.agent.command.Command;
import com.eactive.eai.agent.command.CommandException;
import com.eactive.eai.common.b2bextractor.B2BExtractManager;
import com.eactive.eai.common.util.Logger;

/**
 * 라우팅필드 추출 서비스리스트 메모리 동기화 Command - 오픈뱅킹 EAIServiceLoader_312에서 사용
 * 
 * @author openbanking
 * @since 2019.08
 */
public class ReloadB2BExtractListCommand extends Command {

	private static final long serialVersionUID = 1L;
	private static final Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);

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

	@Override
	public Object execute() throws CommandException {
		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);
		}

		B2BExtractManager manager = B2BExtractManager.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";
	}
}
