package com.eactive.eai.adapter.socket2.protocol.login;

import com.eactive.eai.adapter.socket2.config.SocketAdapterManager;
import com.eactive.eai.adapter.socket2.protocol.ISocketAdapter;
import com.eactive.eai.adapter.socket2.protocol.ProtocolHandler;
import org.apache.mina.common.IoSession;


public class LazyHandler extends ProtocolHandler {
	public LazyHandler(ISocketAdapter adapter) {
		super(adapter);
	}
	@Override
	public void sessionClosed(IoSession session) throws Exception {
		super.sessionClosed(session);
	}
	
	@Override
	public void sessionOpened(IoSession session) throws Exception {
	
		super.sessionOpened(session);
		ISocketAdapter[] adapters = SocketAdapterManager.getInstance().getSocketAdapters(adapter.getContext().getAdapterGroupName());
		if(adapters == null) return;
		for (int i=0; i<adapters.length; i++) {
			if ("BIND".equals(adapters[i].getContext().getProtocol())) {
				adapters[i].getSessionPool().shutdown();
				adapters[i].stopForcely();
			}
		}				
	}	

}
