public class ProtocolCodecFilter extends IoFilterAdapter
IoFilter which translates binary or protocol specific data into
message objects and vice versa using ProtocolCodecFactory,
ProtocolEncoder, or ProtocolDecoder.| Modifier and Type | Class and Description |
|---|---|
private static class |
ProtocolCodecFilter.EncodedWriteRequest |
private static class |
ProtocolCodecFilter.MessageWriteRequest |
private static class |
ProtocolCodecFilter.ProtocolDecoderOutputImpl |
private static class |
ProtocolCodecFilter.ProtocolEncoderOutputImpl |
IoFilter.NextFilter| Modifier and Type | Field and Description |
|---|---|
private static AttributeKey |
DECODER |
private static AttributeKey |
DECODER_OUT |
private static IoBuffer |
EMPTY_BUFFER |
private static java.lang.Class<?>[] |
EMPTY_PARAMS |
private static AttributeKey |
ENCODER |
private static AttributeKey |
ENCODER_OUT |
private ProtocolCodecFactory |
factory
The factory responsible for creating the encoder and decoder
|
private java.util.concurrent.Semaphore |
lock |
private static org.slf4j.Logger |
LOGGER
A logger for this class
|
| Constructor and Description |
|---|
ProtocolCodecFilter(java.lang.Class<? extends ProtocolEncoder> encoderClass,
java.lang.Class<? extends ProtocolDecoder> decoderClass)
Creates a new instance of ProtocolCodecFilter, without any factory.
|
ProtocolCodecFilter(ProtocolCodecFactory factory)
Creates a new instance of ProtocolCodecFilter, associating a factory
for the creation of the encoder and decoder.
|
ProtocolCodecFilter(ProtocolEncoder encoder,
ProtocolDecoder decoder)
Creates a new instance of ProtocolCodecFilter, without any factory.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
disposeCodec(IoSession session)
Dispose the encoder, decoder, and the callback for the decoded
messages.
|
private void |
disposeDecoder(IoSession session)
Dispose the decoder, removing its instance from the
session's attributes, and calling the associated
dispose method.
|
private void |
disposeDecoderOut(IoSession session)
Remove the decoder callback from the session's attributes.
|
private void |
disposeEncoder(IoSession session)
Dispose the encoder, removing its instance from the
session's attributes, and calling the associated
dispose method.
|
void |
filterWrite(IoFilter.NextFilter nextFilter,
IoSession session,
WriteRequest writeRequest)
Filters
IoSession.write(Object) method invocation. |
private ProtocolDecoderOutput |
getDecoderOut(IoSession session,
IoFilter.NextFilter nextFilter)
Return a reference to the decoder callback.
|
ProtocolEncoder |
getEncoder(IoSession session)
Get the encoder instance from a given session.
|
private ProtocolEncoderOutput |
getEncoderOut(IoSession session,
IoFilter.NextFilter nextFilter,
WriteRequest writeRequest) |
void |
messageReceived(IoFilter.NextFilter nextFilter,
IoSession session,
java.lang.Object message)
Process the incoming message, calling the session decoder.
|
void |
messageSent(IoFilter.NextFilter nextFilter,
IoSession session,
WriteRequest writeRequest)
Filters
IoHandler.messageSent(IoSession,Object) event. |
void |
onPostRemove(IoFilterChain parent,
java.lang.String name,
IoFilter.NextFilter nextFilter)
Invoked after this filter is removed from the specified parent.
|
void |
onPreAdd(IoFilterChain parent,
java.lang.String name,
IoFilter.NextFilter nextFilter)
Invoked before this filter is added to the specified parent.
|
void |
sessionClosed(IoFilter.NextFilter nextFilter,
IoSession session)
Filters
IoHandler.sessionClosed(IoSession) event. |
destroy, exceptionCaught, filterClose, init, inputClosed, onPostAdd, onPreRemove, sessionCreated, sessionIdle, sessionOpened, toStringprivate static final org.slf4j.Logger LOGGER
private static final java.lang.Class<?>[] EMPTY_PARAMS
private static final IoBuffer EMPTY_BUFFER
private static final AttributeKey ENCODER
private static final AttributeKey DECODER
private static final AttributeKey DECODER_OUT
private static final AttributeKey ENCODER_OUT
private final ProtocolCodecFactory factory
private final java.util.concurrent.Semaphore lock
public ProtocolCodecFilter(ProtocolCodecFactory factory)
factory - The associated factorypublic ProtocolCodecFilter(ProtocolEncoder encoder, ProtocolDecoder decoder)
encoder - The class responsible for encoding the messagedecoder - The class responsible for decoding the messagepublic ProtocolCodecFilter(java.lang.Class<? extends ProtocolEncoder> encoderClass, java.lang.Class<? extends ProtocolDecoder> decoderClass)
encoderClass - The class responsible for encoding the messagedecoderClass - The class responsible for decoding the messagepublic ProtocolEncoder getEncoder(IoSession session)
session - The associated session we will get the encoder frompublic void onPreAdd(IoFilterChain parent, java.lang.String name, IoFilter.NextFilter nextFilter) throws java.lang.Exception
IoFilterAdapterIoFilter.init() is invoked.onPreAdd in interface IoFilteronPreAdd in class IoFilterAdapterparent - the parent who called this methodname - the name assigned to this filternextFilter - the IoFilter.NextFilter for this filter. You can reuse
this object until this filter is removed from the chain.java.lang.Exceptionpublic void onPostRemove(IoFilterChain parent, java.lang.String name, IoFilter.NextFilter nextFilter) throws java.lang.Exception
IoFilterAdapterIoFilter.destroy() is invoked.onPostRemove in interface IoFilteronPostRemove in class IoFilterAdapterparent - the parent who called this methodname - the name assigned to this filternextFilter - the IoFilter.NextFilter for this filter. You can reuse
this object until this filter is removed from the chain.java.lang.Exceptionpublic void messageReceived(IoFilter.NextFilter nextFilter, IoSession session, java.lang.Object message) throws java.lang.Exception
messageReceived in interface IoFiltermessageReceived in class IoFilterAdapternextFilter - the IoFilter.NextFilter for this filter. You can reuse this
object until this filter is removed from the chain.session - The IoSession which has received this eventmessage - The received messagejava.lang.Exceptionpublic void messageSent(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws java.lang.Exception
IoFilterAdapterIoHandler.messageSent(IoSession,Object) event.messageSent in interface IoFiltermessageSent in class IoFilterAdapternextFilter - the IoFilter.NextFilter for this filter. You can reuse this
object until this filter is removed from the chain.session - The IoSession which has received this eventwriteRequest - The WriteRequest that contains the sent messagejava.lang.Exceptionpublic void filterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws java.lang.Exception
IoFilterAdapterIoSession.write(Object) method invocation.filterWrite in interface IoFilterfilterWrite in class IoFilterAdapternextFilter - the IoFilter.NextFilter for this filter. You can reuse this
object until this filter is removed from the chain.session - The IoSession which has to process this invocationwriteRequest - The WriteRequest to processjava.lang.Exceptionpublic void sessionClosed(IoFilter.NextFilter nextFilter, IoSession session) throws java.lang.Exception
IoFilterAdapterIoHandler.sessionClosed(IoSession) event.sessionClosed in interface IoFiltersessionClosed in class IoFilterAdapternextFilter - the IoFilter.NextFilter for this filter. You can reuse this
object until this filter is removed from the chain.session - The IoSession which has received this eventjava.lang.Exceptionprivate void disposeCodec(IoSession session)
private void disposeEncoder(IoSession session)
private void disposeDecoder(IoSession session)
private ProtocolDecoderOutput getDecoderOut(IoSession session, IoFilter.NextFilter nextFilter)
private ProtocolEncoderOutput getEncoderOut(IoSession session, IoFilter.NextFilter nextFilter, WriteRequest writeRequest)
private void disposeDecoderOut(IoSession session)