Class NettyConnection
- All Implemented Interfaces:
Connection,AutoCloseable
-
Constructor Summary
ConstructorsConstructorDescriptionNettyConnection(SocketAddress serverAddress) NettyConnection(SocketAddress serverAddress, ConnectionConfig config) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a connection event listener to receive notifications about connection events.voidCancels any pending reconnection attempts.voidclose()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 associatedPipelinefor this connection.intGets the current number of reconnection attempts.getState()Gets the current connection state.booleanIndicates whether the connection has been successfully established and is active.static NettyConnectionCreates a connection for the standard session bus path.static NettyConnectionCreates a connection for the standard session bus path with custom configuration.static NettyConnectionCreates a connection for the standard system bus path.static NettyConnectionCreates a connection for the standard system bus path with custom configuration.voidRemoves a connection event listener.voidResets the reconnection state, clearing attempt count and timers.voidsendAndRouteResponse(OutboundMessage msg, CompletionStage<Void> future) Sends the givenOutboundMessageover the connection and completes the provided future when the message has been written to the D-Bus transport.Sends the givenOutboundMessageover 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:ConnectionInitiates a connection to a D-Bus instance.- Specified by:
connectin interfaceConnection- Returns:
- a
CompletionStagethat completes when the connection is established, or exceptionally if the attempt fails.
-
isConnected
public boolean isConnected()Description copied from interface:ConnectionIndicates whether the connection has been successfully established and is active.- Specified by:
isConnectedin interfaceConnection- Returns:
trueif the connection is active,falseotherwise.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
getNextSerial
Description copied from interface:ConnectionGenerates 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:
getNextSerialin interfaceConnection- Returns:
- a unique
DBusUInt32serial number for anOutboundMessage.
-
getPipeline
Description copied from interface:ConnectionRetrieves the associatedPipelinefor this connection.- Specified by:
getPipelinein interfaceConnection- Returns:
- the
Pipelineinstance used by this connection.
-
sendRequest
Description copied from interface:ConnectionSends the givenOutboundMessageover this connection, bypassing the pipeline.This method is intended for simple request-response interactions where no additional pipeline-based processing is needed. The returned
CompletionStageis completed directly with the correspondingInboundMessageresponse 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:
sendRequestin interfaceConnection- Parameters:
msg- the outbound message to send.- Returns:
- a
CompletionStagethat completes with the corresponding inbound response message, or fails exceptionally on error.
-
sendAndRouteResponse
Description copied from interface:ConnectionSends the givenOutboundMessageover 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
InboundMessageresponse will be delivered through the pipeline, allowing it to be processed by registeredInboundHandlers.This method is intended for scenarios where custom or advanced processing of responses is needed, while keeping message transmission efficient.
- Specified by:
sendAndRouteResponsein interfaceConnection- Parameters:
msg- the outbound message to send.future- theCompletionStageto complete once the message is written or if an error occurs.
-
getConfig
Description copied from interface:ConnectionRetrieves the configuration for this connection.- Specified by:
getConfigin interfaceConnection- Returns:
- the
ConnectionConfiginstance used by this connection.
-
getState
Description copied from interface:ConnectionGets the current connection state.- Specified by:
getStatein interfaceConnection- Returns:
- the current
ConnectionState
-
addConnectionEventListener
Description copied from interface:ConnectionAdds a connection event listener to receive notifications about connection events.- Specified by:
addConnectionEventListenerin interfaceConnection- Parameters:
listener- the listener to add
-
removeConnectionEventListener
Description copied from interface:ConnectionRemoves a connection event listener.- Specified by:
removeConnectionEventListenerin interfaceConnection- Parameters:
listener- the listener to remove
-
triggerHealthCheck
Description copied from interface:ConnectionManually triggers a health check if health monitoring is enabled.- Specified by:
triggerHealthCheckin interfaceConnection- Returns:
- a
CompletionStagethat completes when the health check is triggered
-
getReconnectAttemptCount
public int getReconnectAttemptCount()Description copied from interface:ConnectionGets the current number of reconnection attempts.- Specified by:
getReconnectAttemptCountin interfaceConnection- Returns:
- the current reconnection attempt count
-
cancelReconnection
public void cancelReconnection()Description copied from interface:ConnectionCancels any pending reconnection attempts.- Specified by:
cancelReconnectionin interfaceConnection
-
resetReconnectionState
public void resetReconnectionState()Description copied from interface:ConnectionResets the reconnection state, clearing attempt count and timers.- Specified by:
resetReconnectionStatein interfaceConnection
-