org.apache.mina.filter.codec

Class SynchronizedProtocolEncoder

Implemented Interfaces:
ProtocolEncoder

public class SynchronizedProtocolEncoder
extends java.lang.Object
implements ProtocolEncoder

A ProtocolEncoder implementation which decorates an existing encoder to be thread-safe. Please be careful if you're going to use this decorator because it can be a root of performance degradation in a multi-thread environment. Please use this decorator only when you need to synchronize on a per-encoder basis instead of on a per-session basis, which is not common.

Constructor Summary

SynchronizedProtocolEncoder(ProtocolEncoder encoder)
Creates a new instance which decorates the specified encoder.

Method Summary

void
dispose(IoSession session)
Releases all resources related with this encoder.
void
encode(IoSession session, Object message, ProtocolEncoderOutput out)
Encodes higher-level message objects into binary or protocol-specific data.
ProtocolEncoder
getEncoder()
Returns the encoder this encoder is decorating.

Constructor Details

SynchronizedProtocolEncoder

public SynchronizedProtocolEncoder(ProtocolEncoder encoder)
Creates a new instance which decorates the specified encoder.

Method Details

dispose

public void dispose(IoSession session)
            throws Exception
Releases all resources related with this encoder.
Specified by:
dispose in interface ProtocolEncoder

encode

public void encode(IoSession session,
                   Object message,
                   ProtocolEncoderOutput out)
            throws Exception
Encodes higher-level message objects into binary or protocol-specific data. MINA invokes ProtocolEncoder.encode(IoSession,Object,ProtocolEncoderOutput) method with message which is popped from the session write queue, and then the encoder implementation puts encoded ByteBuffers into ProtocolEncoderOutput.
Specified by:
encode in interface ProtocolEncoder

getEncoder

public ProtocolEncoder getEncoder()
Returns the encoder this encoder is decorating.