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

import com.eactive.eai.adapter.socket2.config.SocketAdapterContext;
import com.eactive.eai.adapter.socket2.filter.polling.KFTCPollingFilter;
import com.eactive.eai.adapter.socket2.protocol.TcpAdapterServer;
import com.eactive.eai.adapter.socket2.protocol.dynamicoffset.codec.DynamicOffsetCodecFactory;
import com.eactive.eai.adapter.socket2.protocol.fixedheader.ack.AckServerFilter;
import com.eactive.eai.adapter.socket2.protocol.fixedheader.codec.ChunkCodecFactory;
import org.apache.mina.filter.codec.ProtocolCodecFilter;


public class DynamicOffsetServer extends TcpAdapterServer {
	public DynamicOffsetServer(SocketAdapterContext context) throws Exception {
		super(context);		
		this.handler = new DynamicOffsetHandler(this);
		
		if ("NONE".equals(context.getLlFieldType())) {
			config.getFilterChain().addFirst("codec", new ProtocolCodecFilter(new ChunkCodecFactory(this)));
		} else {
			config.getFilterChain().addFirst("codec", new ProtocolCodecFilter(new DynamicOffsetCodecFactory(this)));
		}

		if ("Y".equals(context.getAckSupport())) {
			config.getFilterChain().addAfter("codec", "ack", new AckServerFilter(this));
		}
		if (context.isPollingUse()) {
			config.getFilterChain().addAfter("polling", "kftcPolling", new KFTCPollingFilter(this));
			config.getFilterChain().remove("polling");
		}

	}
}
