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

import com.eactive.eai.adapter.socket2.protocol.snmp.codec.SnmpCodecFactory;
import edu.emory.mathcs.backport.java.util.concurrent.Executors;
import org.apache.mina.common.DefaultIoFilterChainBuilder;
import org.apache.mina.filter.LoggingFilter;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.executor.ExecutorFilter;
import org.apache.mina.transport.socket.nio.DatagramAcceptor;

import java.net.InetSocketAddress;


public class SnmpAdapter {
	public SnmpAdapter() throws Exception {
		DatagramAcceptor acceptor = new DatagramAcceptor(Executors.newCachedThreadPool());
		
		DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
		chain.addLast("logger", new LoggingFilter());
		chain.addLast("executor", new ExecutorFilter(Executors.newCachedThreadPool()));
		chain.addLast("codec", new ProtocolCodecFilter(new SnmpCodecFactory()));
		
//		DatagramAcceptorConfig config = (DatagramAcceptorConfig) acceptor.getDefaultConfig();
		//config.setReuseAddress(true);	
		
		acceptor.bind(new InetSocketAddress(161), new SnmpHandler());
		acceptor.bind(new InetSocketAddress(162), new SnmpHandler());
	}
	
	public static void main(String[] args) throws Exception {
		new SnmpAdapter();
	}
}
