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

import com.eactive.eai.adapter.socket2.config.SocketAdapterContext;
import edu.emory.mathcs.backport.java.util.concurrent.Executor;
import org.apache.mina.common.support.BaseIoAcceptor;
import org.apache.mina.common.support.BaseIoAcceptorConfig;
import org.apache.mina.transport.socket.nio.SocketAcceptor;
import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;


abstract public class TcpAdapterServer extends SocketAdapterServer {
	public TcpAdapterServer(SocketAdapterContext context) throws Exception {
		super(context);
	}

	protected BaseIoAcceptorConfig createAcceptorConfig() {
		SocketAcceptorConfig config = new SocketAcceptorConfig();

		//config.getSessionConfig().setSoLinger(0);
		
		// to reuse TIME_WAIT state port
		config.setReuseAddress("Y".equals(context.getSocketReuse()) ? true : false);
		
		return config;
	}
	
	protected BaseIoAcceptor createAcceptor(int ioProcessorCount, Executor ioProcessExecutor) {
		return new SocketAcceptor(ioProcessorCount, ioProcessExecutor, this);
	}
}	
