Top Description Inners Fields Constructors Methods
io.netty5.handler.timeout

public Class WriteTimeoutHandler

extends Object
implements ChannelHandler
Class Inheritance
All Implemented Interfaces
io.netty5.channel.ChannelHandler
Imports
io.netty5.bootstrap.ServerBootstrap, io.netty5.channel.Channel, .ChannelHandler, .ChannelHandlerContext, .ChannelInitializer, io.netty5.util.concurrent.Future, .FutureListener, java.util.concurrent.TimeUnit

Raises a WriteTimeoutException when a write operation cannot finish in a certain period of time.
// The connection is closed when a write operation cannot finish in 30 seconds.

public class MyChannelInitializer extends ChannelInitializer<Channel> {
    public void initChannel(Channel channel) {
        channel.pipeline().addLast("writeTimeoutHandler", new WriteTimeoutHandler(30);
        channel.pipeline().addLast("myHandler", new MyHandler());
    }
}

// Handler should handle the WriteTimeoutException.
public class MyHandler implements ChannelHandler {
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
            throws Exception {
        if (cause instanceof WriteTimeoutException) {
            // do something
        } else {
            super.exceptionCaught(ctx, cause);
        }
    }
}

ServerBootstrap bootstrap = ...;
...
bootstrap.childHandler(new MyChannelInitializer());
...
See Also
ReadTimeoutHandler, IdleStateHandler

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private boolean
private WriteTimeoutHandler.WriteTimeoutTask
lastTask

A doubly-linked list to track all WriteTimeoutTasks

private static final long
private final long

Constructor Summary

AccessConstructor and Description
public
WriteTimeoutHandler(int
write timeout in seconds
timeoutSeconds
)

Creates a new instance.

public
WriteTimeoutHandler(long
write timeout
timeout
,
TimeUnit
the TimeUnit of timeout
unit
)

Creates a new instance.

Method Summary

Modifier and TypeMethod and Description
private void
public void
handlerRemoved(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.
private void
private void
public Future<Void>
write(ChannelHandlerContext
the ChannelHandlerContext for which the write operation is made
ctx
,
Object
the message to write
msg
)

Overrides default io.netty5.channel.ChannelHandler.write.

Called once a write operation is made.
protected void
writeTimedOut(ChannelHandlerContext ctx)

Is called when a write timeout was detected

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closedback to summary
private boolean closed
lastTaskback to summary
private WriteTimeoutHandler.WriteTimeoutTask lastTask

A doubly-linked list to track all WriteTimeoutTasks

MIN_TIMEOUT_NANOSback to summary
private static final long MIN_TIMEOUT_NANOS
timeoutNanosback to summary
private final long timeoutNanos

Constructor Detail

WriteTimeoutHandlerback to summary
public WriteTimeoutHandler(int timeoutSeconds)

Creates a new instance.

Parameters
timeoutSeconds:int

write timeout in seconds

WriteTimeoutHandlerback to summary
public WriteTimeoutHandler(long timeout, TimeUnit unit)

Creates a new instance.

Parameters
timeout:long

write timeout

unit:TimeUnit

the TimeUnit of timeout

Method Detail

addWriteTimeoutTaskback to summary
private void addWriteTimeoutTask(WriteTimeoutHandler.WriteTimeoutTask task)
handlerRemovedback to summary
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.handlerRemoved.

Doc from io.netty5.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.

Annotations
@Override
removeWriteTimeoutTaskback to summary
private void removeWriteTimeoutTask(WriteTimeoutHandler.WriteTimeoutTask task)
scheduleTimeoutback to summary
private void scheduleTimeout(final ChannelHandlerContext ctx, final Future<Void> future)
writeback to summary
public Future<Void> write(ChannelHandlerContext ctx, Object msg)

Overrides default io.netty5.channel.ChannelHandler.write.

Doc from io.netty5.channel.ChannelHandler.write.

Called once a write operation is made. The write operation will write the messages through the ChannelPipeline. Those are then ready to be flushed to the actual Channel once Channel#flush() is called.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the write operation is made

msg:Object

the message to write

Returns:Future<Void>

the Future which will be notified once the operation completes.

Annotations
@Override
writeTimedOutback to summary
protected void writeTimedOut(ChannelHandlerContext ctx) throws Exception

Is called when a write timeout was detected

io.netty5.handler.timeout back to summary

private final Class WriteTimeoutHandler.WriteTimeoutTask

extends Object
implements Runnable, FutureListener<Void>
Class Inheritance
  • java.lang.Object
  • io.netty5.handler.timeout.WriteTimeoutHandler.WriteTimeoutTask
All Implemented Interfaces
io.netty5.util.concurrent.FutureListener, java.lang.Runnable

Field Summary

Modifier and TypeField and Description
private final ChannelHandlerContext
private final Future<Void>
pack-priv WriteTimeoutHandler.WriteTimeoutTask
pack-priv WriteTimeoutHandler.WriteTimeoutTask
pack-priv Future<?>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
operationComplete(Future<? extends Void>
the source Future which called this callback
future
)

Implements io.netty5.util.concurrent.FutureListener.operationComplete.

Invoked when the operation associated with the Future has been completed.
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ctxback to summary
private final ChannelHandlerContext ctx
futureback to summary
private final Future<Void> future
nextback to summary
pack-priv WriteTimeoutHandler.WriteTimeoutTask next
prevback to summary
pack-priv WriteTimeoutHandler.WriteTimeoutTask prev
scheduledFutureback to summary
pack-priv Future<?> scheduledFuture

Constructor Detail

WriteTimeoutTaskback to summary
pack-priv WriteTimeoutTask(ChannelHandlerContext ctx, Future<Void> future)

Method Detail

operationCompleteback to summary
public void operationComplete(Future<? extends Void> future) throws Exception

Implements io.netty5.util.concurrent.FutureListener.operationComplete.

Doc from io.netty5.util.concurrent.FutureListener.operationComplete.

Invoked when the operation associated with the Future has been completed.

Parameters
future:Future<? extends Void>

the source Future which called this callback

Annotations
@Override
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override