Class NettyConnection
- All Implemented Interfaces:
Connection
,AutoCloseable
-
Constructor Summary
ConstructorsConstructorDescriptionNettyConnection
(SocketAddress serverAddress) NettyConnection
(SocketAddress serverAddress, ConnectionConfig config) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a connection event listener to receive notifications about connection events.void
Cancels any pending reconnection attempts.void
close()
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.static NettyConnection
Creates a connection for the standard session bus path.static NettyConnection
Creates a connection for the standard session bus path with custom configuration.static NettyConnection
Creates a connection for the standard system bus path.static NettyConnection
Creates a connection for the standard system bus path with custom configuration.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.
-
Constructor Details
-
NettyConnection
-
NettyConnection
-
-
Method Details
-
newSystemBusConnection
Creates a connection for the standard system bus path. (Typically /var/run/dbus/system_bus_socket)- Returns:
- A new instance.
- Throws:
UnsupportedOperationException
- if native transport for UDS is not available.
-
newSystemBusConnection
Creates a connection for the standard system bus path with custom configuration. (Typically /var/run/dbus/system_bus_socket)- Parameters:
config
- The connection configuration to use- Returns:
- A new instance.
- Throws:
UnsupportedOperationException
- if native transport for UDS is not available.
-
newSessionBusConnection
Creates a connection for the standard session bus path. (Path is usually obtained from DBUS_SESSION_BUS_ADDRESS env var)- Returns:
- A new instance.
- Throws:
UnsupportedOperationException
- if native transport for UDS is not available or address not found.
-
newSessionBusConnection
Creates a connection for the standard session bus path with custom configuration. (Path is usually obtained from DBUS_SESSION_BUS_ADDRESS env var)- Parameters:
config
- The connection configuration to use- Returns:
- A new instance.
- Throws:
UnsupportedOperationException
- if native transport for UDS is not available or address not found.
-
connect
Description copied from interface:Connection
Initiates a connection to a D-Bus instance.- Specified by:
connect
in interfaceConnection
- Returns:
- a
CompletionStage
that completes when the connection is established, or exceptionally if the attempt fails.
-
isConnected
public boolean isConnected()Description copied from interface:Connection
Indicates whether the connection has been successfully established and is active.- Specified by:
isConnected
in interfaceConnection
- Returns:
true
if the connection is active,false
otherwise.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
getNextSerial
Description copied from interface:Connection
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.
- Specified by:
getNextSerial
in interfaceConnection
- Returns:
- a unique
DBusUInt32
serial number for anOutboundMessage
.
-
getPipeline
Description copied from interface:Connection
Retrieves the associatedPipeline
for this connection.- Specified by:
getPipeline
in interfaceConnection
- Returns:
- the
Pipeline
instance used by this connection.
-
sendRequest
Description copied from interface:Connection
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.
- Specified by:
sendRequest
in interfaceConnection
- Parameters:
msg
- the outbound message to send.- Returns:
- a
CompletionStage
that completes with the corresponding inbound response message, or fails exceptionally on error.
-
sendAndRouteResponse
Description copied from interface:Connection
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.
- Specified by:
sendAndRouteResponse
in interfaceConnection
- Parameters:
msg
- the outbound message to send.future
- theCompletionStage
to complete once the message is written or if an error occurs.
-
getConfig
Description copied from interface:Connection
Retrieves the configuration for this connection.- Specified by:
getConfig
in interfaceConnection
- Returns:
- the
ConnectionConfig
instance used by this connection.
-
getState
Description copied from interface:Connection
Gets the current connection state.- Specified by:
getState
in interfaceConnection
- Returns:
- the current
ConnectionState
-
addConnectionEventListener
Description copied from interface:Connection
Adds a connection event listener to receive notifications about connection events.- Specified by:
addConnectionEventListener
in interfaceConnection
- Parameters:
listener
- the listener to add
-
removeConnectionEventListener
Description copied from interface:Connection
Removes a connection event listener.- Specified by:
removeConnectionEventListener
in interfaceConnection
- Parameters:
listener
- the listener to remove
-
triggerHealthCheck
Description copied from interface:Connection
Manually triggers a health check if health monitoring is enabled.- Specified by:
triggerHealthCheck
in interfaceConnection
- Returns:
- a
CompletionStage
that completes when the health check is triggered
-
getReconnectAttemptCount
public int getReconnectAttemptCount()Description copied from interface:Connection
Gets the current number of reconnection attempts.- Specified by:
getReconnectAttemptCount
in interfaceConnection
- Returns:
- the current reconnection attempt count
-
cancelReconnection
public void cancelReconnection()Description copied from interface:Connection
Cancels any pending reconnection attempts.- Specified by:
cancelReconnection
in interfaceConnection
-
resetReconnectionState
public void resetReconnectionState()Description copied from interface:Connection
Resets the reconnection state, clearing attempt count and timers.- Specified by:
resetReconnectionState
in interfaceConnection
-