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

import com.eactive.eai.adapter.socket2.config.SocketAdapterContext;
import com.eactive.eai.adapter.socket2.protocol.TcpAdapterClient;
import com.eactive.eai.adapter.socket2.protocol.cisco.codec.CiscoCodecFactory;
import com.eactive.eai.adapter.socket2.protocol.fixedheader.codec.FixedHeaderCodecFactory;
import com.eactive.eai.adapter.socket2.protocol.xecure2.handshake.Xecure2ClientFilter;
import org.apache.mina.filter.codec.ProtocolCodecFilter;

public class Xecure2Client extends TcpAdapterClient {

	public Xecure2Client(SocketAdapterContext context) throws Exception {
		super(context);
		this.handler = new Xecure2Handler(this);
		
		if ("CISCO".equals(context.getXecureType()))
			config.getFilterChain().addFirst("codec", new ProtocolCodecFilter(new CiscoCodecFactory(this)));
		else
			config.getFilterChain().addFirst("codec", new ProtocolCodecFilter(new FixedHeaderCodecFactory(this)));

		//avoid Polling Filter
//		config.getFilterChain().addAfter("codec", "xecure2.fixed", new Xecure2ClientFilter(this));
		config.getFilterChain().addLast("xecure2.fixed", new Xecure2ClientFilter(this));
	}
}
