IdleStateHandler

cc.otavia.handler.timeout.IdleStateHandler
See theIdleStateHandler companion object
class IdleStateHandler(readerIdleTime: Long, writerIdleTime: Long, allIdleTime: Long, unit: TimeUnit) extends ChannelHandler

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. 
// 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.
class MyChannelInitializer extends ChannelInitializer[Channel] {
      override protected def initChannel(ch: Channel): Unit = {
          ch.pipeline.addLast("idleStateHandler", new IdleStateHandler(60, 30, 0))
          ch.pipeline.addLast("myHandler", new MyHandler())
      }
}

class MyHandler extends ChannelHandler {
    override def channelInboundEvent(ctx: ChannelHandlerContext, evt: AnyRef): Unit = {
        evt match
            case event: IdleStateEvent =>
                if (event.state == IdleState.READER_IDLE)
                    ctx.close()
                else if (event.state == IdleState.WRITER_IDLE)
                    ctx.writeAndFlush(new PingMessage())
            case _ =>
   }
}

Value parameters

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.

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.

unit

the TimeUnit of readerIdleTime, writeIdleTime, and allIdleTime

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.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def channelActive(ctx: ChannelHandlerContext): Unit

The Channel of the ChannelHandlerContext is now active

The Channel of the ChannelHandlerContext is now active

Attributes

Definition Classes
override def channelInactive(ctx: ChannelHandlerContext): Unit

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.

Attributes

Definition Classes
override def channelRead(ctx: ChannelHandlerContext, msg: AnyRef): Unit

Invoked when the current Channel has read a message from the peer.

Invoked when the current Channel has read a message from the peer.

Attributes

Definition Classes
override def channelReadComplete(ctx: ChannelHandlerContext): Unit

Invoked when the last message read by the current read operation has been consumed by channelRead. If ChannelOption.AUTO_READ is off, no further attempt to read an inbound data from the current Channel will be made until ChannelOutboundInvoker.read(ReadBufferAllocator) is called.

Invoked when the last message read by the current read operation has been consumed by channelRead. If ChannelOption.AUTO_READ is off, no further attempt to read an inbound data from the current Channel will be made until ChannelOutboundInvoker.read(ReadBufferAllocator) is called.

Attributes

Definition Classes
override def channelRegistered(ctx: ChannelHandlerContext): Unit

The Channel of the ChannelHandlerContext was registered with its cc.otavia.core.actor.ChannelsActor

The Channel of the ChannelHandlerContext was registered with its cc.otavia.core.actor.ChannelsActor

Attributes

Definition Classes
override def channelTimeoutEvent(ctx: ChannelHandlerContext, id: Long): Unit

Gets called if a channel timeout event happened.

Gets called if a channel timeout event happened.

Value parameters

ctx

ChannelHandlerContext of this handler.

id

registered cc.otavia.core.timer.TimeoutTrigger id of this timeout event.

Attributes

Definition Classes
override def handlerAdded(ctx: ChannelHandlerContext): Unit

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.

Attributes

Definition Classes
override def handlerRemoved(ctx: ChannelHandlerContext): Unit

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

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

Attributes

Definition Classes
def ticksInNanos(): Long
override def write(ctx: ChannelHandlerContext, msg: AnyRef): Unit

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.

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.

Value parameters

ctx

the ChannelHandlerContext for which the bind operation is made

msg

the message to write

Attributes

Definition Classes

Inherited methods

def bind(ctx: ChannelHandlerContext, local: SocketAddress, future: ChannelFuture): ChannelFuture

Called once a bind operation is made.

Called once a bind operation is made.

Value parameters

ctx

the ChannelHandlerContext for which the bind operation is made

local

the SocketAddress to which it should bound

Attributes

Inherited from:
ChannelHandler
def channelExceptionCaught(ctx: ChannelHandlerContext, cause: Throwable, id: Long): Unit

Gets called if a Throwable was thrown when handling inbound events.

Gets called if a Throwable was thrown when handling inbound events.

Attributes

Inherited from:
ChannelHandler
def channelExceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit

Gets called if a Throwable was thrown when handling inbound events.

Gets called if a Throwable was thrown when handling inbound events.

Attributes

Inherited from:
ChannelHandler
def channelInboundEvent(ctx: ChannelHandlerContext, evt: AnyRef): Unit

Gets called if a custom inbound event happened.

Gets called if a custom inbound event happened.

Attributes

Inherited from:
ChannelHandler
def channelRead(ctx: ChannelHandlerContext, msg: AnyRef, msgId: Long): Unit

Invoked when the current Channel has read a message from the peer.

Invoked when the current Channel has read a message from the peer.

Attributes

Inherited from:
ChannelHandler

The Channel of the ChannelHandlerContext was shutdown in one direction. This might either be because the remote peer did cause a shutdown of one direction or the shutdown was requested explicit by us and was executed.

The Channel of the ChannelHandlerContext was shutdown in one direction. This might either be because the remote peer did cause a shutdown of one direction or the shutdown was requested explicit by us and was executed.

Value parameters

ctx

the ChannelHandlerContext for which we notify about the completed shutdown.

direction

the ChannelShutdownDirection of the completed shutdown.

Attributes

Inherited from:
ChannelHandler

Attributes

Inherited from:
ChannelHandler

Gets called once the writable state of a Channel changed. You can check the state with Channel.writableBytes or Channel.isWritable .

Gets called once the writable state of a Channel changed. You can check the state with Channel.writableBytes or Channel.isWritable .

Attributes

Inherited from:
ChannelHandler

Called once a close operation is made.

Called once a close operation is made.

Value parameters

ctx

the ChannelHandlerContext for which the bind operation is made

Attributes

Inherited from:
ChannelHandler
def connect(ctx: ChannelHandlerContext, remote: SocketAddress, local: Option[SocketAddress], future: ChannelFuture): ChannelFuture

Called once a connect operation is made.

Called once a connect operation is made.

Value parameters

ctx

the ChannelHandlerContext for which the bind operation is made

local

the option SocketAddress which is used as source on connect

remote

the SocketAddress to which it should connect

Attributes

Inherited from:
ChannelHandler

Called once a deregister operation is made from the current registered cc.otavia.core.actor.ChannelsActor

Called once a deregister operation is made from the current registered cc.otavia.core.actor.ChannelsActor

Attributes

Inherited from:
ChannelHandler

Called once a disconnect operation is made.

Called once a disconnect operation is made.

Value parameters

ctx

the ChannelHandlerContext for which the bind operation is made

Attributes

Inherited from:
ChannelHandler
def flush(ctx: ChannelHandlerContext): Unit

Called once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.

Called once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.

Attributes

Inherited from:
ChannelHandler
def hasInboundAdaptive: Boolean

If the handler has inbound AdaptiveBuffer

If the handler has inbound AdaptiveBuffer

Attributes

Inherited from:
ChannelHandler
def hasOutboundAdaptive: Boolean

If the handler has outbound AdaptiveBuffer

If the handler has outbound AdaptiveBuffer

Attributes

Inherited from:
ChannelHandler
def isBufferHandler: Boolean

Attributes

Inherited from:
ChannelHandler
def isSharable: Boolean

Attributes

Returns

true if this handler is sharable and thus can be added to more than one ChannelPipeline. By default, this method returns false. If this method returns false, you have to create a new handler instance every time you add it to a pipeline because it has unshared state such as member variables.

Inherited from:
ChannelHandler
def open(ctx: ChannelHandlerContext, path: Path, options: Seq[OpenOption], attrs: Seq[FileAttribute[_]], future: ChannelFuture): ChannelFuture

Called once a open operation is made.

Called once a open operation is made.

Value parameters

attrs

An optional list of file attributes to set atomically when creating the file

ctx

the ChannelHandlerContext for which the bind operation is made

options

Options specifying how the file is opened

path

The path of the file to open or create

Attributes

Inherited from:
ChannelHandler

The number of the outbound bytes that are buffered / queued in this ChannelHandler. This number will affect the writability of the Channel together the buffered / queued bytes in the Channel itself. By default this methods returns 0. If the ChannelHandler implementation buffers / queues outbound data this methods should be implemented to return the correct value.

The number of the outbound bytes that are buffered / queued in this ChannelHandler. This number will affect the writability of the Channel together the buffered / queued bytes in the Channel itself. By default this methods returns 0. If the ChannelHandler implementation buffers / queues outbound data this methods should be implemented to return the correct value.

Value parameters

ctx

the ChannelHandlerContext for which the bind operation is made

Attributes

Returns

the number of buffered / queued bytes.

Inherited from:
ChannelHandler
def read(ctx: ChannelHandlerContext, readPlan: ReadPlan): Unit

Called once a read operation is made from the current registered cc.otavia.core.actor.ChannelsActor. If the ChannelHandler implementation queues the read and another read happens it is free to drop the first ReadPlan and just use the last one.

Called once a read operation is made from the current registered cc.otavia.core.actor.ChannelsActor. If the ChannelHandler implementation queues the read and another read happens it is free to drop the first ReadPlan and just use the last one.

Value parameters

ctx

the ChannelHandlerContext for which the bind operation is made

readPlan

The ReadPlan that should be used to allocate a Buffer if needed (for reading the data).

Attributes

Inherited from:
ChannelHandler

Called once a register operation is made to register for IO on the cc.otavia.core.actor.ChannelsActor.

Called once a register operation is made to register for IO on the cc.otavia.core.actor.ChannelsActor.

Attributes

Inherited from:
ChannelHandler
def sendOutboundEvent(ctx: ChannelHandlerContext, event: AnyRef): Unit

Called once a custom defined outbound event was sent. This operation will pass the event through the ChannelPipeline in the outbound direction.

Called once a custom defined outbound event was sent. This operation will pass the event through the ChannelPipeline in the outbound direction.

Value parameters

ctx

the ChannelHandlerContext for which the bind operation is made

event

the event.

Attributes

Inherited from:
ChannelHandler

Called once a shutdown operation was requested and should be executed.

Called once a shutdown operation was requested and should be executed.

Value parameters

ctx

the ChannelHandlerContext for which the bind operation is made

direction

the ChannelShutdownDirection that is used.

Attributes

Inherited from:
ChannelHandler
def write(ctx: ChannelHandlerContext, msg: AnyRef, msgId: Long): Unit

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.

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.

Value parameters

ctx

the ChannelHandlerContext for which the bind operation is made

msg

the message to write

msgId

the id of the message

Attributes

Inherited from:
ChannelHandler