package com.eactive.eai.adapter.amq;

import com.eactive.eai.adapter.listener.AdapterException;
import com.eactive.eai.adapter.listener.AdapterListenerSupport;
import com.eactive.eai.common.util.Logger;

/**
 * @formatter:off
 * ActiveMQ 어댑터 LISTENER 클래스
 * ActiveMQ 어댑터를 기동/중지한다
 * @formatter:on
 */
public class AMQAdapterListener extends AdapterListenerSupport {
	public static Logger logger = Logger.getLogger(Logger.LOGGER_ADAPTER);

	@Override
	public void start() throws AdapterException {
		if (logger.isInfo()) {
			logger.info("= AMQAdapterListener start.........");
		}

		try {
			if (info == null) {
				throw new Exception("AMQAdapterListener | AdapterVO가 NULL입니다.");
			}

			AMQAdapterManager manager = AMQAdapterManager.getInstance();
			info.setStatus(true);
			manager.start(info);
		} catch (Throwable e) {
			logger.error("[" + info.getName() + "] 구동 실패", e);
		}
	}

	@Override
	public void stop() throws AdapterException {
		if (logger.isInfo()) {
			logger.info("= AMQAdapterListener stop.........");
		}
		
		try {
			if (info == null) {
				throw new Exception("AMQAdapterListener | AdapterVO가 NULL입니다.");
			}

			AMQAdapterManager manager = AMQAdapterManager.getInstance();
			manager.stop(info);
			info.setStatus(false);
		} catch (Throwable e) {
			logger.error("[" + info.getName() + "] 중지 실패", e);
		}
	}
}
