Class AbstractConnectionBase
java.lang.Object
org.freedesktop.dbus.connections.base.AbstractConnectionBase
- All Implemented Interfaces:
Closeable, AutoCloseable
- Direct Known Subclasses:
ConnectionMethodInvocation
public abstract sealed class AbstractConnectionBase
extends Object
implements Closeable
permits ConnectionMethodInvocation
Class containing most parts required for a arbitrary connection.
It is not intended to be used directly, therefore it is sealed.
It is not intended to be used directly, therefore it is sealed.
- Since:
- 5.0.0 - 2023-10-23
- Author:
- hypfvieh
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractConnectionBase(ConnectionConfig _conCfg, TransportConfig _transportConfig, ReceivingServiceConfig _rsCfg) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Disconnect this session (for use in try-with-resources).booleanconnect()Connects the underlying transport if it is not already connected.protected abstract IncomingMessageThreadcreateReaderThread(BusAddress _busAddress) Create the read thread for reading incoming messages.voidDisconnect from the Bus.protected voiddisconnect(IDisconnectAction _before, IDisconnectAction _after) Special disconnect method which may be used whenever some cleanup before or after disconnection to DBus is required.protected <X extends Throwable>
voiddoWithExportedObjects(Class<X> _exClz, IThrowingConsumer<Map<String, ExportedObject>, X> _action) Do some action with the currently exported objects in a synchronized manor.protected <T, X extends Throwable>
TdoWithExportedObjectsAndReturn(Class<X> _exClz, IThrowingFunction<Map<String, ExportedObject>, T, X> _action) Do some action with the currently exported objects in a synchronized manor.Returns the address this connection is connected to.protected BusAddressprotected PendingCallbackManagerstatic DBusCallInfoReturns a structure with information on the current method call.protected ConnectionConfigReturns the currently configured disconnect callback.getError()Return any DBus error which has been received.abstract DBusInterfacegetExportedObject(String _source, String _path) Retrieves an remote object using source and path.abstract <T extends DBusInterface>
TgetExportedObject(String _source, String _path, Class<T> _type) Retrieves an remote object using source and path.getExportedObject(DBusInterface _interface) protected FallbackContainerprotected Map<DBusMatchRule, Queue<DBusSigHandler<DBusSignal>>> protected Map<DBusMatchRule, Queue<DBusSigHandler<? extends DBusSignal>>> protected Map<DBusInterface, RemoteObject> protected Map<Thread, DBusCallInfo> protected org.slf4j.Loggerabstract StringThe generated UUID of this machine.protected Map<Long, MethodCall> protected ReceivingServiceprotected AbstractTransportThe currently configured transport.Returns the transport's configuration.
Please note: changing any value will not change the transport settings!protected final voidinternalDisconnect(IOException _connectionError) Disconnects the DBus session.booleanWhether the transport is connected.protected voidlisten()Start reading and messages.protected voidrejectUnknownProperty(MethodCall _methodCall, Object[] _params) Sends a reply on the bus to signal a non-existing property was requested.voidsendMessage(Message _message) Send a message or signal to the DBus daemon.voidsetDisconnectCallback(IDisconnectCallback _disconnectCallback) Deprecated, for removal: This API element is subject to removal in a future version.should be set on construction using the buildertoString()voidunExportObject(String _objectpath) Stop Exporting an object
-
Constructor Details
-
AbstractConnectionBase
protected AbstractConnectionBase(ConnectionConfig _conCfg, TransportConfig _transportConfig, ReceivingServiceConfig _rsCfg) throws DBusException - Throws:
DBusException
-
-
Method Details
-
getExportedObject
Retrieves an remote object using source and path. Will try to find suitable exported DBusInterface automatically.- Parameters:
_source- source_path- path- Returns:
DBusInterfacecompatible object- Throws:
DBusException
-
getExportedObject
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- source_path- path_type- class of remote object- Returns:
DBusInterfacecompatible object- Throws:
DBusException
-
createReaderThread
Create the read thread for reading incoming messages.- Parameters:
_busAddress- current bus address- Returns:
- IncomingMessageThread, never
null
-
getMachineId
-
internalDisconnect
Disconnects the DBus session. This method is final as it should never be overwritten by subclasses, otherwise we have an endless recursion when usingdisconnect(IDisconnectAction, IDisconnectAction)which then will cause a StackOverflowError.- Parameters:
_connectionError- exception caused the disconnection (null if intended disconnect)
-
disconnect
Special disconnect method which may be used whenever some cleanup before or after disconnection to DBus is required.- Parameters:
_before- action execute before actual disconnect, null if not needed_after- action execute after disconnect, null if not needed
-
disconnect
public void disconnect()Disconnect from the Bus. -
rejectUnknownProperty
Sends a reply on the bus to signal a non-existing property was requested.- Parameters:
_methodCall- method call_params- params- Throws:
DBusException- when sending fails
-
doWithExportedObjectsAndReturn
protected <T, X extends Throwable> T doWithExportedObjectsAndReturn(Class<X> _exClz, IThrowingFunction<Map<String, ExportedObject>, T, X> _action) throws X Do some action with the currently exported objects in a synchronized manor.- Type Parameters:
X- type of exception- Parameters:
_exClz- exception type which may be thrown_action- action to execute- Returns:
- whatever the action returns
- Throws:
X- thrown when action throws
-
doWithExportedObjects
protected <X extends Throwable> void doWithExportedObjects(Class<X> _exClz, IThrowingConsumer<Map<String, ExportedObject>, X> _action) throws X Do some action with the currently exported objects in a synchronized manor.- Type Parameters:
X- type of exception- Parameters:
_exClz- exception type which may be thrown_action- action to execute- Throws:
X- thrown when action throws
-
getLogger
protected org.slf4j.Logger getLogger() -
getFallbackContainer
-
getAddress
Returns the address this connection is connected to.- Returns:
- new
BusAddressobject
-
isConnected
public boolean isConnected()Whether the transport is connected.- Returns:
- true if connected
-
getTransport
The currently configured transport.- Returns:
- AbstractTransport
-
sendMessage
Send a message or signal to the DBus daemon.- Parameters:
_message- message to send
-
getExportedObject
- Throws:
DBusException
-
getError
Return any DBus error which has been received.- Returns:
- A DBusExecutionException, or null if no error is pending.
-
connect
Connects the underlying transport if it is not already connected.Will work for both, client and server (listening) connections.
- Returns:
- true if connection established or already connected, false otherwise
- Throws:
IOException- when connection was not already established and creating the connnection failed
-
getTransportConfig
Returns the transport's configuration.
Please note: changing any value will not change the transport settings!
This is read-only.- Returns:
- transport config
-
listen
Start reading and messages.- Throws:
IOException- when listening fails
-
getMessageFactory
-
getPendingErrorQueue
-
getHandledSignals
-
getGenericHandledSignals
-
getPendingCalls
-
getImportedObjects
-
getObjectTree
-
getCallbackManager
-
getReceivingService
-
getBusAddress
-
getInfoMap
-
getConnectionConfig
-
unExportObject
Stop Exporting an object- Parameters:
_objectpath- The objectpath to stop exporting.
-
getCallInfo
Returns a structure with information on the current method call.- Returns:
- the DBusCallInfo for this method call, or null if we are not in a method call.
-
getDisconnectCallback
Returns the currently configured disconnect callback.- Returns:
- callback or null if no callback registered
-
setDisconnectCallback
@Deprecated(since="5.1.0 - 2024-07-12", forRemoval=true) public void setDisconnectCallback(IDisconnectCallback _disconnectCallback) Deprecated, for removal: This API element is subject to removal in a future version.should be set on construction using the builderSet the callback which will be notified when a disconnection happens. Use null to remove.- Parameters:
_disconnectCallback- callback to execute or null to remove
-
close
Disconnect this session (for use in try-with-resources).- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
toString
-