Top Description Fields Constructors Methods
org.freedesktop.dbus.connections.base

public abstract sealed Class AbstractConnectionBase

extends Object
implements Closeable
permits ConnectionMethodInvocation
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
org.freedesktop.dbus.connections.base.ConnectionMethodInvocation
Imports
org.freedesktop.dbus.DBusCallInfo, .DBusMatchRule, .RemoteObject, org.freedesktop.dbus.connections.BusAddress, .IDisconnectAction, .IDisconnectCallback, org.freedesktop.dbus.connections.config.ReceivingServiceConfig, .TransportConfig, org.freedesktop.dbus.connections.impl.ConnectionConfig, org.freedesktop.dbus.connections.transports.AbstractTransport, .TransportBuilder, org.freedesktop.dbus.errors.UnknownProperty, org.freedesktop.dbus.exceptions.DBusException, .DBusExecutionException, .FatalDBusException, .NotConnected, org.freedesktop.dbus.interfaces.DBusInterface, .DBusSigHandler, org.freedesktop.dbus.messages.*, .Error, org.freedesktop.dbus.messages.constants.Flags, org.freedesktop.dbus.utils.IThrowingConsumer, .IThrowingFunction, .NameableThreadFactory, org.slf4j.Logger, .LoggerFactory, java.io.Closeable, .EOFException, .IOException, java.nio.channels.ClosedByInterruptException, java.util.*, .Map.Entry, java.util.concurrent.*

Class containing most parts required for a arbitrary connection.
It is not intended to be used directly, therefore it is sealed.
Author
hypfvieh
Since
5.0.0 - 2023-10-23

Field Summary

Modifier and TypeField and Description
private final BusAddress
private final PendingCallbackManager
private final ConnectionConfig
private volatile boolean
private final Map<String, ExportedObject>
private final FallbackContainer
private final Map<DBusMatchRule, Queue<DBusSigHandler<DBusSignal>>>
private final Map<DBusMatchRule, Queue<DBusSigHandler<? extends DBusSignal>>>
private final Map<DBusInterface, RemoteObject>
private static final Map<Thread, DBusCallInfo>
private final Logger
private final MessageFactory
private final ObjectTree
private final Map<Long, MethodCall>
private final Queue<Error>
private final IncomingMessageThread
private final ReceivingService
private final ExecutorService
private AbstractTransport

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Disconnect this session (for use in try-with-resources).

public boolean

Returns:

true if connection established or already connected, false otherwise
connect
()

Connects the underlying transport if it is not already connected.

protected abstract IncomingMessageThread

Returns:

IncomingMessageThread, never null
createReaderThread
(BusAddress
current bus address
_busAddress
)

Create the read thread for reading incoming messages.

protected synchronized void
disconnect(IDisconnectAction
action execute before actual disconnect, null if not needed
_before
,
IDisconnectAction
action execute after disconnect, null if not needed
_after
)

Special disconnect method which may be used whenever some cleanup before or after disconnection to DBus is required.

public synchronized void
disconnect()

Disconnect from the Bus.

protected <
type of exception
X extends Throwable
>
void
doWithExportedObjects(Class<X>
exception type which may be thrown
_exClz
,
IThrowingConsumer<Map<String, ExportedObject>, X>
action to execute
_action
)

Do some action with the currently exported objects in a synchronized manor.

protected <T,
type of exception
X extends Throwable
>
T

Returns:

whatever the action returns
doWithExportedObjectsAndReturn
(Class<X>
exception type which may be thrown
_exClz
,
IThrowingFunction<Map<String, ExportedObject>, T, X>
action to execute
_action
)

Do some action with the currently exported objects in a synchronized manor.

public BusAddress

Returns:

new BusAddress object
getAddress
()

Returns the address this connection is connected to.

protected BusAddress
protected PendingCallbackManager
public static DBusCallInfo

Returns:

the DBusCallInfo for this method call, or null if we are not in a method call.
getCallInfo
()

Returns a structure with information on the current method call.

protected ConnectionConfig
public IDisconnectCallback

Returns:

callback or null if no callback registered
getDisconnectCallback
()

Returns the currently configured disconnect callback.

public DBusExecutionException

Returns:

A DBusExecutionException, or null if no error is pending.
getError
()

Return any DBus error which has been received.

public abstract DBusInterface

Returns:

DBusInterface compatible object
getExportedObject
(String
source
_source
,
String
path
_path
)

Retrieves an remote object using source and path.

public abstract <T extends DBusInterface> T

Returns:

DBusInterface compatible object
getExportedObject
(String
source
_source
,
String
path
_path
,
Class<T>
class of remote object
_type
)

Retrieves an remote object using source and path.

public String
protected FallbackContainer
protected Map<DBusMatchRule, Queue<DBusSigHandler<DBusSignal>>>
protected Map<DBusMatchRule, Queue<DBusSigHandler<? extends DBusSignal>>>
protected Map<DBusInterface, RemoteObject>
protected Map<Thread, DBusCallInfo>
protected Logger
public abstract String

Returns:

String
getMachineId
()

The generated UUID of this machine.

public MessageFactory
public ObjectTree
protected Map<Long, MethodCall>
protected Queue<Error>
protected ReceivingService
protected AbstractTransport

Returns:

AbstractTransport
getTransport
()

The currently configured transport.

public TransportConfig

Returns:

transport config
getTransportConfig
()

Returns the transport's configuration.

protected final synchronized void
internalDisconnect(IOException
exception caused the disconnection (null if intended disconnect)
_connectionError
)

Disconnects the DBus session.

public boolean

Returns:

true if connected
isConnected
()

Whether the transport is connected.

protected void
listen()

Start reading and messages.

pack-priv Message
protected void
rejectUnknownProperty(final MethodCall
method call
_methodCall
,
Object[]
params
_params
)

Sends a reply on the bus to signal a non-existing property was requested.

public void
sendMessage(Message
message to send
_message
)

Send a message or signal to the DBus daemon.

private void
sendMessageInternally(Message
message to send
_message
)

Send a message to DBus.

public void
setDisconnectCallback(IDisconnectCallback
callback to execute or null to remove
_disconnectCallback
)
Deprecated for removal since 5.1.0 - 2024-07-12. should be set on construction using the builder

Set the callback which will be notified when a disconnection happens.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
unExportObject(String
The objectpath to stop exporting.
_objectpath
)

Stop Exporting an object

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

busAddressback to summary
private final BusAddress busAddress
callbackManagerback to summary
private final PendingCallbackManager callbackManager
connectionConfigback to summary
private final ConnectionConfig connectionConfig
disconnectingback to summary
private volatile boolean disconnecting
exportedObjectsback to summary
private final Map<String, ExportedObject> exportedObjects
fallbackContainerback to summary
private final FallbackContainer fallbackContainer
genericHandledSignalsback to summary
private final Map<DBusMatchRule, Queue<DBusSigHandler<DBusSignal>>> genericHandledSignals
handledSignalsback to summary
private final Map<DBusMatchRule, Queue<DBusSigHandler<? extends DBusSignal>>> handledSignals
importedObjectsback to summary
private final Map<DBusInterface, RemoteObject> importedObjects
INFOMAPback to summary
private static final Map<Thread, DBusCallInfo> INFOMAP
loggerback to summary
private final Logger logger
messageFactoryback to summary
private final MessageFactory messageFactory
objectTreeback to summary
private final ObjectTree objectTree
pendingCallsback to summary
private final Map<Long, MethodCall> pendingCalls
pendingErrorQueueback to summary
private final Queue<Error> pendingErrorQueue
readerThreadback to summary
private final IncomingMessageThread readerThread
receivingServiceback to summary
private final ReceivingService receivingService
senderServiceback to summary
private final ExecutorService senderService
transportback to summary
private AbstractTransport transport

Constructor Detail

AbstractConnectionBaseback to summary
protected AbstractConnectionBase(ConnectionConfig _conCfg, TransportConfig _transportConfig, ReceivingServiceConfig _rsCfg) throws DBusException

Method Detail

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Disconnect this session (for use in try-with-resources).

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Closeable.close.

if an I/O error occurs

connectback to summary
public boolean connect() throws IOException

Connects the underlying transport if it is not already connected.

Will work for both, client and server (listening) connections.

Returns:boolean

true if connection established or already connected, false otherwise

Exceptions
IOException:
when connection was not already established and creating the connnection failed
createReaderThreadback to summary
protected abstract IncomingMessageThread createReaderThread(BusAddress _busAddress)

Create the read thread for reading incoming messages.

Parameters
_busAddress:BusAddress

current bus address

Returns:IncomingMessageThread

IncomingMessageThread, never null

disconnectback to summary
protected synchronized void disconnect(IDisconnectAction _before, IDisconnectAction _after)

Special disconnect method which may be used whenever some cleanup before or after disconnection to DBus is required.

Parameters
_before:IDisconnectAction

action execute before actual disconnect, null if not needed

_after:IDisconnectAction

action execute after disconnect, null if not needed

disconnectback to summary
public synchronized void disconnect()

Disconnect from the Bus.

doWithExportedObjectsback to summary
protected <X extends Throwable> void doWithExportedObjects(Class<X> _exClz, IThrowingConsumer<Map<String, ExportedObject>, X> _action) throws IThrowingConsumer-:X

Do some action with the currently exported objects in a synchronized manor.

Parameters
<X>
type of exception
_exClz:Class<X>

exception type which may be thrown

_action:IThrowingConsumer<Map<String, ExportedObject>, X>

action to execute

Exceptions
IThrowingConsumer-:X:
thrown when action throws
doWithExportedObjectsAndReturnback to summary
protected <T, X extends Throwable> T doWithExportedObjectsAndReturn(Class<X> _exClz, IThrowingFunction<Map<String, ExportedObject>, T, X> _action) throws IThrowingFunction-:X

Do some action with the currently exported objects in a synchronized manor.

Parameters
<X>
type of exception
_exClz:Class<X>

exception type which may be thrown

_action:IThrowingFunction<Map<String, ExportedObject>, T, X>

action to execute

Returns:T

whatever the action returns

Exceptions
IThrowingFunction-:X:
thrown when action throws
getAddressback to summary
public BusAddress getAddress()

Returns the address this connection is connected to.

Returns:BusAddress

new BusAddress object

getBusAddressback to summary
protected BusAddress getBusAddress()
getCallbackManagerback to summary
protected PendingCallbackManager getCallbackManager()
getCallInfoback to summary
public static DBusCallInfo getCallInfo()

Returns a structure with information on the current method call.

Returns:DBusCallInfo

the DBusCallInfo for this method call, or null if we are not in a method call.

getConnectionConfigback to summary
protected ConnectionConfig getConnectionConfig()
getDisconnectCallbackback to summary
public IDisconnectCallback getDisconnectCallback()

Returns the currently configured disconnect callback.

Returns:IDisconnectCallback

callback or null if no callback registered

getErrorback to summary
public DBusExecutionException getError()

Return any DBus error which has been received.

Returns:DBusExecutionException

A DBusExecutionException, or null if no error is pending.

getExportedObjectback to summary
public abstract DBusInterface getExportedObject(String _source, String _path) throws DBusException

Retrieves an remote object using source and path. Will try to find suitable exported DBusInterface automatically.

Parameters
_source:String

source

_path:String

path

Returns:DBusInterface

DBusInterface compatible object

getExportedObjectback to summary
public abstract <T extends DBusInterface> T getExportedObject(String _source, String _path, Class<T> _type) throws DBusException

Retrieves an remote object using source and path. Will use the given type as object class.

Parameters
_source:String

source

_path:String

path

_type:Class<T>

class of remote object

Returns:T

DBusInterface compatible object

getExportedObjectback to summary
public String getExportedObject(DBusInterface _interface) throws DBusException
getFallbackContainerback to summary
protected FallbackContainer getFallbackContainer()
getGenericHandledSignalsback to summary
protected Map<DBusMatchRule, Queue<DBusSigHandler<DBusSignal>>> getGenericHandledSignals()
getHandledSignalsback to summary
protected Map<DBusMatchRule, Queue<DBusSigHandler<? extends DBusSignal>>> getHandledSignals()
getImportedObjectsback to summary
protected Map<DBusInterface, RemoteObject> getImportedObjects()
getInfoMapback to summary
protected Map<Thread, DBusCallInfo> getInfoMap()
getLoggerback to summary
protected Logger getLogger()
getMachineIdback to summary
public abstract String getMachineId()

The generated UUID of this machine.

Returns:String

String

getMessageFactoryback to summary
public MessageFactory getMessageFactory()
getObjectTreeback to summary
public ObjectTree getObjectTree()
getPendingCallsback to summary
protected Map<Long, MethodCall> getPendingCalls()
getPendingErrorQueueback to summary
protected Queue<Error> getPendingErrorQueue()
getReceivingServiceback to summary
protected ReceivingService getReceivingService()
getTransportback to summary
protected AbstractTransport getTransport()

The currently configured transport.

Returns:AbstractTransport

AbstractTransport

getTransportConfigback to summary
public TransportConfig getTransportConfig()

Returns the transport's configuration.

Note

changing any value will not change the transport settings!
This is read-only.

Returns:TransportConfig

transport config

internalDisconnectback to summary
protected final synchronized void internalDisconnect(IOException _connectionError)

Disconnects the DBus session. This method is final as it should never be overwritten by subclasses, otherwise we have an endless recursion when using disconnect(IDisconnectAction, IDisconnectAction) which then will cause a StackOverflowError.

Parameters
_connectionError:IOException

exception caused the disconnection (null if intended disconnect)

isConnectedback to summary
public boolean isConnected()

Whether the transport is connected.

Returns:boolean

true if connected

listenback to summary
protected void listen() throws IOException

Start reading and messages.

Exceptions
IOException:
when listening fails
readIncomingback to summary
pack-priv Message readIncoming() throws DBusException
rejectUnknownPropertyback to summary
protected void rejectUnknownProperty(final MethodCall _methodCall, Object[] _params) throws DBusException

Sends a reply on the bus to signal a non-existing property was requested.

Parameters
_methodCall:MethodCall

method call

_params:Object[]

params

Exceptions
DBusException:
when sending fails
sendMessageback to summary
public void sendMessage(Message _message)

Send a message or signal to the DBus daemon.

Parameters
_message:Message

message to send

sendMessageInternallyback to summary
private void sendMessageInternally(Message _message)

Send a message to DBus.

Parameters
_message:Message

message to send

setDisconnectCallbackback to summary
public void setDisconnectCallback(IDisconnectCallback _disconnectCallback)

Deprecated

for removal since 5.1.0 - 2024-07-12.

should be set on construction using the builder

Set the callback which will be notified when a disconnection happens. Use null to remove.

Parameters
_disconnectCallback:IDisconnectCallback

callback to execute or null to remove

Annotations
@Deprecated
since:5.1.0 - 2024-07-12
forRemoval:true
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
unExportObjectback to summary
public void unExportObject(String _objectpath)

Stop Exporting an object

Parameters
_objectpath:String

The objectpath to stop exporting.