cc.otavia.handler.timeout
Members list
Type members
Classlikes
A enum that represents the idle state of a cc.otavia.core.channel.Channel
A enum that represents the idle state of a cc.otavia.core.channel.Channel
Attributes
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
A user event triggered by IdleStateHandler when a Channel is idle.
A user event triggered by IdleStateHandler when a Channel is idle.
Value parameters
- first
-
true
if its the first idle event for the IdleStateEvent. - state
-
the IdleStateEvent which triggered the event.
Attributes
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Triggers an IdleStateEvent when a Channel has not performed read, write, or both operation for a while.
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
- Supertypes
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
IdleStateHandler.type