package com.eactive.eai.rms.onl.server.repository;

import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.stereotype.Repository;

import com.eactive.eai.rms.onl.vo.AdapterStatusVO;

/**
 * The Class Repository.
 * <ul>
 * <li>1. Function : EAI Framework 으로 부터 수신된 모든 객체는 이 클래스에 저장 됩니다.</li>
 * <li>2. Summary : 저장된 객체는 timeToLive 설정에 의해 Expire 됩니다.</li>
 * <li>3. Notification :</li>
 * </ul>
 * 
 * @author : $Author: 윤창용 $
 * @version : $Revision: 1.8.14.4 $
 */
@Repository("adaptersStatusRepository")
public class AdaptersStatusRepository {

	private ConcurrentHashMap<String, Object> repository = new ConcurrentHashMap<String, Object>();;

	private ConcurrentHashMap<String, Object> sendRepository = new ConcurrentHashMap<String, Object>();;

	public void addAdapterStatus(String adapterGroupName, AdapterStatusVO o) {
		repository.put(adapterGroupName, o);
	}

	public Object getAdapterStatus(String adapterGroupName) {
		return repository.get(adapterGroupName);
	}

	public Object removeAdapterStatus(String adapterGroupName) {
		return repository.remove(adapterGroupName);
	}
	
	public void addSendAdapterStatus(String adapterGroupName, AdapterStatusVO o) {
		sendRepository.put(adapterGroupName, o);
	}

	public Object getSendAdapterStatus(String adapterGroupName) {
		return sendRepository.get(adapterGroupName);
	}

	public Object removeSendAdapterStatus(String adapterGroupName) {
		return sendRepository.remove(adapterGroupName);
	}
	public ArrayList<String> getAdapterStatusNames(){
		ArrayList<String> list = new ArrayList<String>();
		for (Object obj : repository.keySet()){
			list.add((String)obj);
		}
		return list;
	}
	public ArrayList<String> getSendAdapterStatusNames(){
		ArrayList<String> list = new ArrayList<String>();
		for (Object obj : sendRepository.keySet()){
			list.add((String)obj);
		}
		return list;
	}
	
	public void cleanupAll() {
		repository.clear();
		repository = new ConcurrentHashMap<String, Object>();
		sendRepository.clear();
		sendRepository = new ConcurrentHashMap<String, Object>();
	}
	public void cleanupRepository(){
		repository.clear();
		repository = new ConcurrentHashMap<String, Object>();
	}
	public void cleanupSendRepository(){
		sendRepository.clear();
		sendRepository = new ConcurrentHashMap<String, Object>();
	}

}
