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

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


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

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