Class IdleStateHandlerNoUnvoid
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
org.infinispan.client.hotrod.impl.transport.netty.IdleStateHandlerNoUnvoid
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler,io.netty.channel.ChannelOutboundHandler
public class IdleStateHandlerNoUnvoid
extends io.netty.channel.ChannelDuplexHandler
Triggers an
IdleStateEvent when a Channel has not performed
read, write, or both operation for a while.
Supported idle states
| Property | Meaning |
|---|---|
readerIdleTime |
an IdleStateEvent whose state is IdleState.READER_IDLE
will be triggered when no read was performed for the specified period of
time. Specify 0 to disable. |
writerIdleTime |
an IdleStateEvent whose state is IdleState.WRITER_IDLE
will be triggered when no write was performed for the specified period of
time. Specify 0 to disable. |
allIdleTime |
an IdleStateEvent whose state is IdleState.ALL_IDLE
will be triggered when neither read nor write was performed for the
specified period of time. Specify 0 to disable. |
// An example that sends a ping message when there is no outbound traffic // for 30 seconds. The connection is closed when there is no inbound traffic // for 60 seconds. public class MyChannelInitializer extendsChannelInitializer<Channel> {@Overridepublic void initChannel(Channelchannel) { channel.pipeline().addLast("idleStateHandler", newIdleStateHandler(60, 30, 0)); channel.pipeline().addLast("myHandler", new MyHandler()); } } // Handler should handle theIdleStateEventtriggered byIdleStateHandler. public class MyHandler extendsChannelDuplexHandler{@Overridepublic void userEventTriggered(ChannelHandlerContextctx,Objectevt) throwsException{ if (evt instanceofIdleStateEvent) {IdleStateEvente = (IdleStateEvent) evt; if (e.state() ==IdleState.READER_IDLE) { ctx.close(); } else if (e.state() ==IdleState.WRITER_IDLE) { ctx.writeAndFlush(new PingMessage()); } } } }ServerBootstrapbootstrap = ...; ... bootstrap.childHandler(new MyChannelInitializer()); ...
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Constructor Summary
ConstructorsConstructorDescriptionIdleStateHandlerNoUnvoid(boolean observeOutput, long readerIdleTime, long writerIdleTime, long allIdleTime, TimeUnit unit) Creates a new instance firingIdleStateEvents.IdleStateHandlerNoUnvoid(int readerIdleTimeSeconds, int writerIdleTimeSeconds, int allIdleTimeSeconds) Creates a new instance firingIdleStateEvents.IdleStateHandlerNoUnvoid(long readerIdleTime, long writerIdleTime, long allIdleTime, TimeUnit unit) -
Method Summary
Modifier and TypeMethodDescriptionvoidchannelActive(io.netty.channel.ChannelHandlerContext ctx) protected voidchannelIdle(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.timeout.IdleStateEvent evt) Is called when anIdleStateEventshould be fired.voidchannelInactive(io.netty.channel.ChannelHandlerContext ctx) voidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) voidchannelReadComplete(io.netty.channel.ChannelHandlerContext ctx) voidchannelRegistered(io.netty.channel.ChannelHandlerContext ctx) longReturn the allIdleTime that was given when instance this class in milliseconds.longReturn the readerIdleTime that was given when instance this class in milliseconds.longReturn the writerIdleTime that was given when instance this class in milliseconds.voidhandlerAdded(io.netty.channel.ChannelHandlerContext ctx) voidhandlerRemoved(io.netty.channel.ChannelHandlerContext ctx) protected io.netty.handler.timeout.IdleStateEventnewIdleStateEvent(io.netty.handler.timeout.IdleState state, boolean first) Returns aIdleStateEvent.voidReset the read timeout.voidReset the write timeout.voidwrite(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, readMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
Constructor Details
-
IdleStateHandlerNoUnvoid
public IdleStateHandlerNoUnvoid(int readerIdleTimeSeconds, int writerIdleTimeSeconds, int allIdleTimeSeconds) Creates a new instance firingIdleStateEvents.- Parameters:
readerIdleTimeSeconds- anIdleStateEventwhose state isIdleState.READER_IDLEwill be triggered when no read was performed for the specified period of time. Specify0to disable.writerIdleTimeSeconds- anIdleStateEventwhose state isIdleState.WRITER_IDLEwill be triggered when no write was performed for the specified period of time. Specify0to disable.allIdleTimeSeconds- anIdleStateEventwhose state isIdleState.ALL_IDLEwill be triggered when neither read nor write was performed for the specified period of time. Specify0to disable.
-
IdleStateHandlerNoUnvoid
public IdleStateHandlerNoUnvoid(long readerIdleTime, long writerIdleTime, long allIdleTime, TimeUnit unit) - See Also:
-
IdleStateHandlerNoUnvoid
public IdleStateHandlerNoUnvoid(boolean observeOutput, long readerIdleTime, long writerIdleTime, long allIdleTime, TimeUnit unit) Creates a new instance firingIdleStateEvents.- Parameters:
observeOutput- whether or not the consumption ofbytesshould be taken into consideration when assessing write idleness. The default isfalse.readerIdleTime- anIdleStateEventwhose state isIdleState.READER_IDLEwill be triggered when no read was performed for the specified period of time. Specify0to disable.writerIdleTime- anIdleStateEventwhose state isIdleState.WRITER_IDLEwill be triggered when no write was performed for the specified period of time. Specify0to disable.allIdleTime- anIdleStateEventwhose state isIdleState.ALL_IDLEwill be triggered when neither read nor write was performed for the specified period of time. Specify0to disable.unit- theTimeUnitofreaderIdleTime,writeIdleTime, andallIdleTime
-
-
Method Details
-
getReaderIdleTimeInMillis
public long getReaderIdleTimeInMillis()Return the readerIdleTime that was given when instance this class in milliseconds. -
getWriterIdleTimeInMillis
public long getWriterIdleTimeInMillis()Return the writerIdleTime that was given when instance this class in milliseconds. -
getAllIdleTimeInMillis
public long getAllIdleTimeInMillis()Return the allIdleTime that was given when instance this class in milliseconds. -
handlerAdded
- Specified by:
handlerAddedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerAddedin classio.netty.channel.ChannelHandlerAdapter- Throws:
Exception
-
handlerRemoved
- Specified by:
handlerRemovedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerRemovedin classio.netty.channel.ChannelHandlerAdapter- Throws:
Exception
-
channelRegistered
- Specified by:
channelRegisteredin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelRegisteredin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelActive
- Specified by:
channelActivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelActivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelInactive
- Specified by:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelRead
- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelReadComplete
- Specified by:
channelReadCompletein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadCompletein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception - Specified by:
writein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
writein classio.netty.channel.ChannelDuplexHandler- Throws:
Exception
-
resetReadTimeout
public void resetReadTimeout()Reset the read timeout. As this handler is not thread-safe, this method must be called on the event loop. -
resetWriteTimeout
public void resetWriteTimeout()Reset the write timeout. As this handler is not thread-safe, this method must be called on the event loop. -
channelIdle
protected void channelIdle(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.timeout.IdleStateEvent evt) throws Exception Is called when anIdleStateEventshould be fired. This implementation callsChannelHandlerContext.fireUserEventTriggered(Object).- Throws:
Exception
-
newIdleStateEvent
protected io.netty.handler.timeout.IdleStateEvent newIdleStateEvent(io.netty.handler.timeout.IdleState state, boolean first) Returns aIdleStateEvent.
-