IdleStateEvent when a Channel has not performed
read, write, or both operation for a while.
| 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 implementsChannelHandler{@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()); ...
ReadTimeoutHandler, WriteTimeoutHandler
| Modifier and Type | Class and Description |
|---|---|
| private abstract static class | |
| private class | |
| private class | |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private final long | |
| private Future | |
| private boolean | |
| private boolean | |
| private boolean | |
| private long | |
| private long | |
| private static final long | |
| private final long | |
| private Future | |
| private boolean | |
| private byte | |
| private final FutureListener | |
| private final long | |
| private Future |
| Access | Constructor and Description |
|---|---|
| public | IdleStateHandler(int
an readerIdleTimeSeconds, int 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.an writerIdleTimeSeconds, int 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.an allIdleTimeSeconds)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.Creates a new instance firing |
| public | IdleStateHandler(long
an readerIdleTime, long 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.an writerIdleTime, long 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.an allIdleTime, TimeUnit unit)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.Creates a new instance firing |
| Modifier and Type | Method and Description |
|---|---|
| public void | channelActive(ChannelHandlerContext ctx)
Overrides default io. Channel of the ChannelHandlerContext is now active
|
| protected void | channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt)
Is called when an |
| public void | channelInactive(ChannelHandlerContext ctx)
Overrides default io. Channel of the ChannelHandlerContext was registered is now inactive and reached its
end of lifetime.
|
| public void | channelRead(ChannelHandlerContext ctx, Object msg)
Overrides default io. Channel has read a message from the peer.
|
| public void | channelReadComplete(ChannelHandlerContext ctx)
Overrides default io. channelRead(ChannelHandlerContext, Object).
|
| public void | channelRegistered(ChannelHandlerContext ctx)
Overrides default io. Channel of the ChannelHandlerContext was registered with its EventLoop
|
| private void | |
| public long | getAllIdleTimeInMillis()
Return the allIdleTime that was given when instance this class in milliseconds. |
| public long | getReaderIdleTimeInMillis()
Return the readerIdleTime that was given when instance this class in milliseconds. |
| public long | getWriterIdleTimeInMillis()
Return the writerIdleTime that was given when instance this class in milliseconds. |
| public void | handlerAdded(ChannelHandlerContext ctx)
Overrides default io. ChannelHandler was added to the actual context and it's ready to handle events.
|
| public void | handlerRemoved(ChannelHandlerContext ctx)
Overrides default io. ChannelHandler was removed from the actual context and it doesn't handle events
anymore.
|
| private void | |
| protected IdleStateEvent | |
| pack-priv Future | schedule(ChannelHandlerContext ctx, Runnable task, long delay, TimeUnit unit)
This method is visible for testing! |
| pack-priv long | |
| public Future | write(ChannelHandlerContext
the ctx, Object ChannelHandlerContext for which the write operation is madethe message to write msg)Overrides default io. |
| allIdleTimeNanos | back to summary |
|---|---|
| private final long allIdleTimeNanos | |
| allIdleTimeout | back to summary |
|---|---|
| private Future<?> allIdleTimeout | |
| firstAllIdleEvent | back to summary |
|---|---|
| private boolean firstAllIdleEvent | |
| firstReaderIdleEvent | back to summary |
|---|---|
| private boolean firstReaderIdleEvent | |
| firstWriterIdleEvent | back to summary |
|---|---|
| private boolean firstWriterIdleEvent | |
| lastReadTime | back to summary |
|---|---|
| private long lastReadTime | |
| lastWriteTime | back to summary |
|---|---|
| private long lastWriteTime | |
| MIN_TIMEOUT_NANOS | back to summary |
|---|---|
| private static final long MIN_TIMEOUT_NANOS | |
| readerIdleTimeNanos | back to summary |
|---|---|
| private final long readerIdleTimeNanos | |
| readerIdleTimeout | back to summary |
|---|---|
| private Future<?> readerIdleTimeout | |
| reading | back to summary |
|---|---|
| private boolean reading | |
| state | back to summary |
|---|---|
| private byte state | |
| writeListener | back to summary |
|---|---|
| private final FutureListener<Void> writeListener | |
| writerIdleTimeNanos | back to summary |
|---|---|
| private final long writerIdleTimeNanos | |
| writerIdleTimeout | back to summary |
|---|---|
| private Future<?> writerIdleTimeout | |
| IdleStateHandler | back to summary |
|---|---|
| public IdleStateHandler(int readerIdleTimeSeconds, int writerIdleTimeSeconds, int allIdleTimeSeconds) Creates a new instance firing
| |
| IdleStateHandler | back to summary |
|---|---|
| public IdleStateHandler(long readerIdleTime, long writerIdleTime, long allIdleTime, TimeUnit unit) Creates a new instance firing
| |
| channelActive | back to summary |
|---|---|
| public void channelActive(ChannelHandlerContext ctx) throws Exception Overrides default io. Doc from io. The
| |
| channelIdle | back to summary |
|---|---|
| protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception Is called when an | |
| channelInactive | back to summary |
|---|---|
| public void channelInactive(ChannelHandlerContext ctx) throws Exception Overrides default io. Doc from io. The
| |
| channelRead | back to summary |
|---|---|
| public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception Overrides default io. Doc from io. Invoked when the current
| |
| channelReadComplete | back to summary |
|---|---|
| public void channelReadComplete(ChannelHandlerContext ctx) throws Exception Overrides default io. Doc from io. Invoked when the last message read by the current read operation has been consumed by
| |
| channelRegistered | back to summary |
|---|---|
| public void channelRegistered(ChannelHandlerContext ctx) throws Exception Overrides default io. Doc from io. The
| |
| destroy | back to summary |
|---|---|
| private void destroy() | |
| getAllIdleTimeInMillis | back to summary |
|---|---|
| public long getAllIdleTimeInMillis() Return the allIdleTime that was given when instance this class in milliseconds. | |
| getReaderIdleTimeInMillis | back to summary |
|---|---|
| public long getReaderIdleTimeInMillis() Return the readerIdleTime that was given when instance this class in milliseconds. | |
| getWriterIdleTimeInMillis | back to summary |
|---|---|
| public long getWriterIdleTimeInMillis() Return the writerIdleTime that was given when instance this class in milliseconds. | |
| handlerAdded | back to summary |
|---|---|
| public void handlerAdded(ChannelHandlerContext ctx) throws Exception Overrides default io. Doc from io. Gets called after the
| |
| handlerRemoved | back to summary |
|---|---|
| public void handlerRemoved(ChannelHandlerContext ctx) throws Exception Overrides default io. Doc from io. Gets called after the
| |
| initialize | back to summary |
|---|---|
| private void initialize(ChannelHandlerContext ctx) | |
| newIdleStateEvent | back to summary |
|---|---|
| protected IdleStateEvent newIdleStateEvent(IdleState state, boolean first) Returns a | |
| schedule | back to summary |
|---|---|
| pack-priv Future This method is visible for testing! | |
| ticksInNanos | back to summary |
|---|---|
| pack-priv long ticksInNanos() This method is visible for testing! | |
| write | back to summary |
|---|---|
| public Future Overrides default io. Doc from io. Called once a write operation is made. The write operation will write the messages through the
| |
| Modifier and Type | Field and Description |
|---|---|
| private final ChannelHandlerContext |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| protected abstract void |
| ctx | back to summary |
|---|---|
| private final ChannelHandlerContext ctx | |
| AbstractIdleTask | back to summary |
|---|---|
| pack-priv AbstractIdleTask(ChannelHandlerContext ctx) | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |
| run | back to summary |
|---|---|
| protected abstract void run(ChannelHandlerContext ctx) | |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected void | run(ChannelHandlerContext ctx)
Implements abstract io. |
| AllIdleTimeoutTask | back to summary |
|---|---|
| pack-priv AllIdleTimeoutTask(ChannelHandlerContext ctx) | |
| run | back to summary |
|---|---|
| protected void run(ChannelHandlerContext ctx) Implements abstract io.
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected void | run(ChannelHandlerContext ctx)
Implements abstract io. |
| ReaderIdleTimeoutTask | back to summary |
|---|---|
| pack-priv ReaderIdleTimeoutTask(ChannelHandlerContext ctx) | |
| run | back to summary |
|---|---|
| protected void run(ChannelHandlerContext ctx) Implements abstract io.
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected void | run(ChannelHandlerContext ctx)
Implements abstract io. |
| WriterIdleTimeoutTask | back to summary |
|---|---|
| pack-priv WriterIdleTimeoutTask(ChannelHandlerContext ctx) | |
| run | back to summary |
|---|---|
| protected void run(ChannelHandlerContext ctx) Implements abstract io.
| |