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.DatagramAcceptor;
import org.apache.mina.transport.socket.nio.DatagramAcceptorConfig;
import org.apache.mina.transport.socket.nio.support.DatagramAcceptorDelegate;


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

	protected BaseIoAcceptorConfig createAcceptorConfig() {
		DatagramAcceptorConfig config = new DatagramAcceptorConfig();
		config.setDisconnectOnUnbind(true);
		//config.setSessionRecycler(new ExpiringSessionRecycler(24 * 60 * 60 ));
		return config;
	}
	
	protected BaseIoAcceptor createAcceptor(int ioProcessorCount, Executor ioProcessExecutor) {
		DatagramAcceptor da = new DatagramAcceptor();
		DatagramAcceptorDelegate acceptor = new DatagramAcceptorDelegate(da, ioProcessExecutor, this);	
		return acceptor;
	}
}	
