Class BaseConnectionBuilder<R extends BaseConnectionBuilder<R,C>, C extends AbstractConnection>

java.lang.Object
org.freedesktop.dbus.connections.impl.BaseConnectionBuilder<R,C>
Type Parameters:
R - concrete type of connection builder
Direct Known Subclasses:
DBusConnectionBuilder, DirectConnectionBuilder

public abstract class BaseConnectionBuilder<R extends BaseConnectionBuilder<R,C>, C extends AbstractConnection> extends Object
Base class for connection builders containing commonly used options.
Since:
4.2.0 - 2022-07-13
Author:
hypfvieh
  • Constructor Details

    • BaseConnectionBuilder

      protected BaseConnectionBuilder(Class<R> _returnType, BusAddress _address)
  • Method Details

    • buildThreadConfig

      protected ReceivingServiceConfig buildThreadConfig()
      Creates the configuration to use for ReceivingService.
      Returns:
      config
    • buildTransportConfig

      protected TransportConfig buildTransportConfig()
      Creates the configuration to use for TransportBuilder.
      Returns:
      config
    • getConnectionConfig

      protected ConnectionConfig getConnectionConfig()
      Returns the currently configured connection configuration.
      Returns:
      config
    • receivingThreadConfig

      public ReceivingServiceConfigBuilder<R> receivingThreadConfig()
      Returns the builder to configure the receiving thread pools.
      Returns:
      builder
    • transportConfig

      public TransportConfigBuilder<?,R> transportConfig()
      Returns the builder to configure the used transport.
      Returns:
      builder
    • withWeakReferences

      @Deprecated(forRemoval=true, since="5.1.0 - 2024-07-12") public R withWeakReferences(boolean _weakRef)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Enable/Disable weak references on connection. Default is false.
      Parameters:
      _weakRef - true to enable
      Returns:
      this
    • withExportWeakReferences

      public R withExportWeakReferences(boolean _weakRef)
      Enable/Disable usage of weak references for exported objects.

      Exported objects are objects provided by the application to DBus and are used through DBus by other applications.

      Using weak references may allow the Garbage Collector to remove exported objects when they are no longer reachable. Enabling this feature may cause dbus-java to be forced to re-create exported objects because the GC already cleaned up the old references.
      Use with caution!

      Default is false.
      Parameters:
      _weakRef - true to enable
      Returns:
      this
    • withImportWeakReferences

      public R withImportWeakReferences(boolean _weakRef)
      Enable/Disable usage of weak references for imported objects.

      Imported objects are all objects which are created when calling interfaces which belong to any object provided by DBus.
      E.g. when you want to use Bluetooth, you will query the bluez interfaces on the bus which will create a proxy object in dbus-java.
      These objects are stored in an internal Map so re-querying the same object will return the cached object instead of creating a new proxy.

      Usually all imported objects are dropped when the connection gets closed (by either side).
      If the application will not close the connection and run for a long time the default behavior may cause high memory usage.
      Enabling weak references may allow the Garbage Collector to remove imported objects when they are no longer reachable.
      This will free up memory when no other references are kept on the remote imported object.

      The current default is false.
      Anyway it is considered to enable weak references for imported objects as default in the future.

      Parameters:
      _weakRef - true to enable
      Returns:
      this
    • withDisconnectCallback

      public R withDisconnectCallback(IDisconnectCallback _disconnectCallback)
      Set the given disconnect callback to the created connection.
      Parameters:
      _disconnectCallback - callback
      Returns:
      this
    • withUnknownSignalHandler

      public R withUnknownSignalHandler(Consumer<DBusSignal> _handler)
      Configures a consumer which will receive any signal which could not be handled.

      By default, no handler is configured, so unknown/unhandled signals will be ignored and only be logged as warn message.

      Parameters:
      _handler - callback which receives all unknown signals
      Returns:
      this
      Since:
      5.1.1 - 2024-09-11
    • build

      public abstract C build() throws DBusException
      Throws:
      DBusException
    • getSystemEndianness

      public static byte getSystemEndianness()
      Get the default system endianness.
      Returns:
      LITTLE or BIG