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 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()); ...
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 int | |
| private long | |
| private long | |
| private long | |
| private static final long | |
| private final boolean | |
| private final long | |
| private Future | |
| private boolean | |
| private static final byte | |
| private static final byte | |
| private byte | |
| private final ChannelFutureListener | |
| 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 | |
| public | IdleStateHandler(boolean
whether or not the consumption of observeOutput, long bytes should be taken into
consideration when assessing write idleness. The default is false.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 |
| 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 | |
| lastChangeCheckTimeStamp | back to summary |
|---|---|
| private long lastChangeCheckTimeStamp | |
| lastFlushProgress | back to summary |
|---|---|
| private long lastFlushProgress | |
| lastMessageHashCode | back to summary |
|---|---|
| private int lastMessageHashCode | |
| lastPendingWriteBytes | back to summary |
|---|---|
| private long lastPendingWriteBytes | |
| 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 | |
| observeOutput | back to summary |
|---|---|
| private final boolean observeOutput | |
| readerIdleTimeNanos | back to summary |
|---|---|
| private final long readerIdleTimeNanos | |
| readerIdleTimeout | back to summary |
|---|---|
| private Future<?> readerIdleTimeout | |
| reading | back to summary |
|---|---|
| private boolean reading | |
| ST_DESTROYED | back to summary |
|---|---|
| private static final byte ST_DESTROYED | |
| ST_INITIALIZED | back to summary |
|---|---|
| private static final byte ST_INITIALIZED | |
| state | back to summary |
|---|---|
| private byte state | |
| writeListener | back to summary |
|---|---|
| private final ChannelFutureListener 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) | |
| IdleStateHandler | back to summary |
|---|---|
| public IdleStateHandler(boolean observeOutput, 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 io. Implements io. Doc from io. Calls
| |
| 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 io. Implements io. Doc from io. Calls
| |
| channelRead | back to summary |
|---|---|
| public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| channelReadComplete | back to summary |
|---|---|
| public void channelReadComplete(ChannelHandlerContext ctx) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| channelRegistered | back to summary |
|---|---|
| public void channelRegistered(ChannelHandlerContext ctx) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| 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 io. Implements io. Doc from io. Gets called after the
| |
| handlerRemoved | back to summary |
|---|---|
| public void handlerRemoved(ChannelHandlerContext ctx) throws Exception Overrides io. Implements io. Doc from io. Gets called after the
| |
| hasOutputChanged | back to summary |
|---|---|
| private boolean hasOutputChanged(ChannelHandlerContext ctx, boolean first) Returns | |
| initialize | back to summary |
|---|---|
| private void initialize(ChannelHandlerContext ctx) | |
| initOutputChanged | back to summary |
|---|---|
| private void initOutputChanged(ChannelHandlerContext ctx) | |
| newIdleStateEvent | back to summary |
|---|---|
| protected IdleStateEvent newIdleStateEvent(IdleState state, boolean first) Returns a | |
| resetReadTimeout | back to summary |
|---|---|
| public void resetReadTimeout() Reset the read timeout. As this handler is not thread-safe, this method must be called on the event loop. | |
| resetWriteTimeout | back to summary |
|---|---|
| public void resetWriteTimeout() Reset the write timeout. As this handler is not thread-safe, this method must be called on the event loop. | |
| 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 void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| 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.
| |