Interface Connection
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DummyConnection
,NettyConnection
A D-Bus connection enables inter-process communication by allowing messages to be sent and received. There are two primary types of buses in D-Bus:
- System Bus: A bus shared between system and user processes.
- Session Bus: A user-specific bus available within a single login session.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a connection event listener to receive notifications about connection events.void
Cancels any pending reconnection attempts.connect()
Initiates a connection to a D-Bus instance.Retrieves the configuration for this connection.Generates and returns the next unique serial number for outbound messages.Retrieves the associatedPipeline
for this connection.int
Gets the current number of reconnection attempts.getState()
Gets the current connection state.boolean
Indicates whether the connection has been successfully established and is active.void
Removes a connection event listener.void
Resets the reconnection state, clearing attempt count and timers.void
sendAndRouteResponse
(OutboundMessage msg, CompletionStage<Void> future) Sends the givenOutboundMessage
over the connection and completes the provided future when the message has been written to the D-Bus transport.Sends the givenOutboundMessage
over this connection, bypassing the pipeline.Manually triggers a health check if health monitoring is enabled.Methods inherited from interface java.lang.AutoCloseable
close
-
Method Details
-
connect
CompletionStage<Void> connect()Initiates a connection to a D-Bus instance.- Returns:
- a
CompletionStage
that completes when the connection is established, or exceptionally if the attempt fails.
-
isConnected
boolean isConnected()Indicates whether the connection has been successfully established and is active.- Returns:
true
if the connection is active,false
otherwise.
-
getPipeline
Pipeline getPipeline()Retrieves the associatedPipeline
for this connection.- Returns:
- the
Pipeline
instance used by this connection.
-
getNextSerial
DBusUInt32 getNextSerial()Generates and returns the next unique serial number for outbound messages.Serial numbers are used to correlate requests and replies and are unique per connection.
- Returns:
- a unique
DBusUInt32
serial number for anOutboundMessage
.
-
sendRequest
Sends the givenOutboundMessage
over this connection, bypassing the pipeline.This method is intended for simple request-response interactions where no additional pipeline-based processing is needed. The returned
CompletionStage
is completed directly with the correspondingInboundMessage
response or exceptionally if an error occurs.Note: Use this method only for straightforward communication scenarios that do not require handler involvement or advanced message routing.
- Parameters:
msg
- the outbound message to send.- Returns:
- a
CompletionStage
that completes with the corresponding inbound response message, or fails exceptionally on error.
-
sendAndRouteResponse
Sends the givenOutboundMessage
over the connection and completes the provided future when the message has been written to the D-Bus transport.The outbound message is transmitted directly over the connection and does not pass through the outbound pipeline. However, the corresponding
InboundMessage
response will be delivered through the pipeline, allowing it to be processed by registeredInboundHandler
s.This method is intended for scenarios where custom or advanced processing of responses is needed, while keeping message transmission efficient.
- Parameters:
msg
- the outbound message to send.future
- theCompletionStage
to complete once the message is written or if an error occurs.
-
getConfig
ConnectionConfig getConfig()Retrieves the configuration for this connection.- Returns:
- the
ConnectionConfig
instance used by this connection.
-
getState
ConnectionState getState()Gets the current connection state.- Returns:
- the current
ConnectionState
-
addConnectionEventListener
Adds a connection event listener to receive notifications about connection events.- Parameters:
listener
- the listener to add
-
removeConnectionEventListener
Removes a connection event listener.- Parameters:
listener
- the listener to remove
-
triggerHealthCheck
CompletionStage<Void> triggerHealthCheck()Manually triggers a health check if health monitoring is enabled.- Returns:
- a
CompletionStage
that completes when the health check is triggered
-
getReconnectAttemptCount
int getReconnectAttemptCount()Gets the current number of reconnection attempts.- Returns:
- the current reconnection attempt count
-
cancelReconnection
void cancelReconnection()Cancels any pending reconnection attempts. -
resetReconnectionState
void resetReconnectionState()Resets the reconnection state, clearing attempt count and timers.
-