Class RealityCheckpoint
- All Implemented Interfaces:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelInboundHandler
,io.netty.channel.ChannelOutboundHandler
This handler serves as the reality checkpoint where messages transition between the low-level transport layer (Netty) and the high-level application layer (public API). It manages request-response correlation, timeouts, and ensures proper thread isolation by routing messages to the appropriate execution contexts. All inbound messages and connection events are switched from the Netty EventLoop to the ApplicationTaskExecutor here, enabling safe blocking operations in user handlers.
Named after the brilliant drum & bass track "Reality Checkpoint" by Logistics, because like that track, this class represents a moment of transition and clarity in the complex flow of D-Bus message processing.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable
-
Constructor Summary
ConstructorsConstructorDescriptionRealityCheckpoint
(ExecutorService applicationTaskExecutor, Connection connection) Creates a new instance.RealityCheckpoint
(ExecutorService applicationTaskExecutor, Connection connection, long methodCallTimeoutMs) Creates a new instance with custom timeout. -
Method Summary
Modifier and TypeMethodDescriptionvoid
channelInactive
(io.netty.channel.ChannelHandlerContext ctx) void
channelRead
(io.netty.channel.ChannelHandlerContext ctx, Object msg) void
exceptionCaught
(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) void
handlerAdded
(io.netty.channel.ChannelHandlerContext ctx) void
userEventTriggered
(io.netty.channel.ChannelHandlerContext ctx, Object evt) io.netty.util.concurrent.Future<Void>
Sends the givenOutboundMessage
without returning a future for the reply.io.netty.util.concurrent.Future<io.netty.util.concurrent.Future<InboundMessage>>
Sends the givenOutboundMessage
and returns a nestedFuture
that tracks both the write completion and the eventual reply.Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, read, write
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerRemoved, isSharable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.netty.channel.ChannelHandler
handlerRemoved
-
Constructor Details
-
RealityCheckpoint
Creates a new instance.- Parameters:
applicationTaskExecutor
- The executor service to run application-level callbacks (like signal handlers) on, to avoid blocking the Netty EventLoop. If null, a default will be attempted or tasks run on EventLoop (not recommended for blocking user code).connection
- An active D-Bus connection.
-
RealityCheckpoint
public RealityCheckpoint(ExecutorService applicationTaskExecutor, Connection connection, long methodCallTimeoutMs) Creates a new instance with custom timeout.- Parameters:
applicationTaskExecutor
- The executor service to run application-level callbacks (like signal handlers) on, to avoid blocking the Netty EventLoop. If null, a default will be attempted or tasks run on EventLoop (not recommended for blocking user code).connection
- An active D-Bus connection.methodCallTimeoutMs
- Timeout in milliseconds for method calls before they are considered stale and removed from pending calls map.
-
-
Method Details
-
handlerAdded
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) - Specified by:
handlerAdded
in interfaceio.netty.channel.ChannelHandler
- Overrides:
handlerAdded
in classio.netty.channel.ChannelHandlerAdapter
-
userEventTriggered
- Specified by:
userEventTriggered
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
userEventTriggered
in classio.netty.channel.ChannelInboundHandlerAdapter
-
writeMessage
public io.netty.util.concurrent.Future<io.netty.util.concurrent.Future<InboundMessage>> writeMessage(OutboundMessage msg) Sends the givenOutboundMessage
and returns a nestedFuture
that tracks both the write completion and the eventual reply.This method is intended for use by higher-level components within the library or application. It assumes that the
OutboundMessage
already has a valid and unique serial number assigned.The returned
Future
structure works as follows:- The outer
Future
completes when the outbound message has been successfully written to the transport. - The inner
Future
, provided as the outer result, will be completed when the correspondingInboundMessage
reply is received.
- Parameters:
msg
- the outbound message to send (must have a preassigned unique serial number).- Returns:
- a
Future
that completes with anotherFuture<InboundMessage>
: the outer future completes when the message is written; the inner future completes when the reply arrives.
- The outer
-
writeAndRouteResponse
Sends the givenOutboundMessage
without returning a future for the reply.Unlike
writeMessage
, this method does not provide aFuture
for the expectedInboundMessage
response. Instead, the reply will be delivered asynchronously through the connection’sPipeline
and must be handled by registeredInboundHandler
s.This method is suitable when the application relies on the pipeline for inbound message processing rather than awaiting a reply programmatically.
- Parameters:
msg
- the outbound message to send.- Returns:
- a
Future
that completes when the message has been successfully written, or exceptionally if an error occurs during transmission.
-
channelRead
- Specified by:
channelRead
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelRead
in classio.netty.channel.ChannelInboundHandlerAdapter
-
exceptionCaught
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelHandler
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
exceptionCaught
in classio.netty.channel.ChannelInboundHandlerAdapter
-
channelInactive
- Specified by:
channelInactive
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelInactive
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
Exception
-