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.
Since:
5.0.0 - 2023-10-23
Author:
hypfvieh
  • Constructor Details

  • Method Details

    • getExportedObject

      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 - source
      _path - path
      Returns:
      DBusInterface compatible 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:
      DBusInterface compatible object
      Throws:
      DBusException
    • createReaderThread

      protected abstract IncomingMessageThread createReaderThread(BusAddress _busAddress)
      Create the read thread for reading incoming messages.
      Parameters:
      _busAddress - current bus address
      Returns:
      IncomingMessageThread, never null
    • getMachineId

      public abstract String getMachineId()
      The generated UUID of this machine.
      Returns:
      String
    • internalDisconnect

      protected final 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 - exception caused the disconnection (null if intended disconnect)
    • disconnect

      protected 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 - 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

      protected void rejectUnknownProperty(MethodCall _methodCall, Object[] _params) throws DBusException
      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

      protected FallbackContainer getFallbackContainer()
    • getAddress

      public BusAddress getAddress()
      Returns the address this connection is connected to.
      Returns:
      new BusAddress object
    • isConnected

      public boolean isConnected()
      Whether the transport is connected.
      Returns:
      true if connected
    • getTransport

      protected AbstractTransport getTransport()
      The currently configured transport.
      Returns:
      AbstractTransport
    • sendMessage

      public void sendMessage(Message _message)
      Send a message or signal to the DBus daemon.
      Parameters:
      _message - message to send
    • getExportedObject

      public String getExportedObject(DBusInterface _interface) throws DBusException
      Throws:
      DBusException
    • getError

      public DBusExecutionException getError()
      Return any DBus error which has been received.
      Returns:
      A DBusExecutionException, or null if no error is pending.
    • connect

      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:
      true if connection established or already connected, false otherwise
      Throws:
      IOException - when connection was not already established and creating the connnection failed
    • getTransportConfig

      public TransportConfig 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

      protected void listen() throws IOException
      Start reading and messages.
      Throws:
      IOException - when listening fails
    • getMessageFactory

      public MessageFactory getMessageFactory()
    • getPendingErrorQueue

      protected Queue<Error> getPendingErrorQueue()
    • getHandledSignals

      protected Map<DBusMatchRule, Queue<DBusSigHandler<? extends DBusSignal>>> getHandledSignals()
    • getGenericHandledSignals

      protected Map<DBusMatchRule, Queue<DBusSigHandler<DBusSignal>>> getGenericHandledSignals()
    • getPendingCalls

      protected Map<Long, MethodCall> getPendingCalls()
    • getImportedObjects

      protected Map<DBusInterface, RemoteObject> getImportedObjects()
    • getObjectTree

      public ObjectTree getObjectTree()
    • getCallbackManager

      protected PendingCallbackManager getCallbackManager()
    • getReceivingService

      protected ReceivingService getReceivingService()
    • getBusAddress

      protected BusAddress getBusAddress()
    • getInfoMap

      protected Map<Thread, DBusCallInfo> getInfoMap()
    • getConnectionConfig

      protected ConnectionConfig getConnectionConfig()
    • unExportObject

      public void unExportObject(String _objectpath)
      Stop Exporting an object
      Parameters:
      _objectpath - The objectpath to stop exporting.
    • getCallInfo

      public static DBusCallInfo 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

      public IDisconnectCallback 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 builder
      Set the callback which will be notified when a disconnection happens. Use null to remove.
      Parameters:
      _disconnectCallback - callback to execute or null to remove
    • close

      public void close() throws IOException
      Disconnect this session (for use in try-with-resources).
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object