Class CompatibleObjectEncoder
- java.lang.Object
-
- org.jboss.netty.handler.codec.oneone.OneToOneEncoder
-
- org.jboss.netty.handler.codec.serialization.CompatibleObjectEncoder
-
- All Implemented Interfaces:
ChannelDownstreamHandler
,ChannelHandler
public class CompatibleObjectEncoder extends OneToOneEncoder
An encoder which serializes a Java object into aChannelBuffer
(interoperability version).This encoder is interoperable with the standard Java object streams such as
ObjectInputStream
andObjectOutputStream
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicReference<ChannelBuffer>
buffer
private java.io.ObjectOutputStream
oout
private int
resetInterval
private int
writtenObjects
-
Constructor Summary
Constructors Constructor Description CompatibleObjectEncoder()
Creates a new instance with the reset interval of16
.CompatibleObjectEncoder(int resetInterval)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private ChannelBuffer
buffer(ChannelHandlerContext ctx)
protected java.lang.Object
encode(ChannelHandlerContext context, Channel channel, java.lang.Object msg)
Transforms the specified message into another message and return the transformed message.protected java.io.ObjectOutputStream
newObjectOutputStream(java.io.OutputStream out)
Creates a newObjectOutputStream
which wraps the specifiedOutputStream
.-
Methods inherited from class org.jboss.netty.handler.codec.oneone.OneToOneEncoder
doEncode, handleDownstream
-
-
-
-
Field Detail
-
buffer
private final java.util.concurrent.atomic.AtomicReference<ChannelBuffer> buffer
-
resetInterval
private final int resetInterval
-
oout
private volatile java.io.ObjectOutputStream oout
-
writtenObjects
private int writtenObjects
-
-
Constructor Detail
-
CompatibleObjectEncoder
public CompatibleObjectEncoder()
Creates a new instance with the reset interval of16
.
-
CompatibleObjectEncoder
public CompatibleObjectEncoder(int resetInterval)
Creates a new instance.- Parameters:
resetInterval
- the number of objects betweenObjectOutputStream.reset()
.0
will disable resetting the stream, but the remote peer will be at the risk of gettingOutOfMemoryError
in the long term.
-
-
Method Detail
-
newObjectOutputStream
protected java.io.ObjectOutputStream newObjectOutputStream(java.io.OutputStream out) throws java.lang.Exception
Creates a newObjectOutputStream
which wraps the specifiedOutputStream
. Override this method to use a subclass of theObjectOutputStream
.- Throws:
java.lang.Exception
-
encode
protected java.lang.Object encode(ChannelHandlerContext context, Channel channel, java.lang.Object msg) throws java.lang.Exception
Description copied from class:OneToOneEncoder
Transforms the specified message into another message and return the transformed message. Note that you can not returnnull
, unlike you can inOneToOneDecoder.decode(ChannelHandlerContext, Channel, Object)
; you must return something, at leastChannelBuffers.EMPTY_BUFFER
.- Specified by:
encode
in classOneToOneEncoder
- Throws:
java.lang.Exception
-
buffer
private ChannelBuffer buffer(ChannelHandlerContext ctx) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-