Top Description Fields Constructors Methods
org.freedesktop.dbus.bin

public Class EmbeddedDBusDaemon

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
org.freedesktop.dbus.connections.BusAddress, org.freedesktop.dbus.connections.transports.AbstractTransport, .TransportBuilder, .TransportBuilder.SaslAuthMode, .TransportConnection, org.freedesktop.dbus.exceptions.AuthenticationException, .DBusException, .InvalidBusAddressException, .SocketClosedException, org.freedesktop.dbus.spi.transport.ITransportProvider, org.slf4j.Logger, .LoggerFactory, java.io.Closeable, .IOException, java.nio.file.attribute.PosixFilePermission, java.util.Objects, .ServiceLoader, java.util.concurrent.CountDownLatch, .TimeUnit, java.util.concurrent.atomic.AtomicBoolean, java.util.function.Consumer

Simple DBusDaemon implementation to use if no DBusDaemon is running on the OS level.

Field Summary

Modifier and TypeField and Description
private final BusAddress
private Consumer<AbstractTransport>
private final AtomicBoolean
private Consumer<AbstractTransport>
private DBusDaemon
private static final Logger
private TransportBuilder.SaslAuthMode
private ClassLoader
private ModuleLayer
private CountDownLatch
private String
private String
private PosixFilePermission[]

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
close()

Implements java.io.Closeable.close.

Shutdown the running DBusDaemon instance.

public Consumer<AbstractTransport>

Returns:

Consumer or null
getBindCallback
()

Configured bind callback.

public Consumer<AbstractTransport>

Returns:

Consumer or null
getConnectCallback
()

Configured pre-connect callback.

public TransportBuilder.SaslAuthMode

Returns:

SaslAuthMode or null
getSaslAuthMode
()

The currently configured SaslAuthMode.

public synchronized boolean

Returns:

true if running, false otherwise
isRunning
()

Whether the DBusDaemon is still running.

public void
setBindCallback(Consumer<AbstractTransport> _callback)

Callback which will be called by transport right after the server socket was bound.

public void
setConnectCallback(Consumer<AbstractTransport>
callback or null to disable
_connectCallback
)

Callback which will be called by transport right before the socket is bound and connections will be accepted.

private synchronized void
public void
setSaslAuthMode(TransportBuilder.SaslAuthMode
auth mode, null to use default
_saslAuthMode
)

Use this to override the default authentication mode which would be used by the transport based on the BusAddress.

public void
setServiceLoaderClassLoader(ClassLoader
class loader
_serviceLoaderClassLoader
)

ClassLoader to use for ServiceLoader to find ITransportProvider implementations.

public void
setServiceLoaderModuleLayer(ModuleLayer
module layer
_serviceLoaderModuleLayer
)

Module Layer to use for ServiceLoader to find ITransportProvider implementations.

public void
setUnixSocketGroup(String
group to set
_group
)

The file group for the created unix socket.

public void
setUnixSocketOwner(String
owner to set
_owner
)

The file owner for the created unix socket.

public void
setUnixSocketPermissions(PosixFilePermission...
permissions to set
_permissions
)

The file permissions for the created unix socket.

public void
startInBackground()

Start the DBusDaemon in background and returns immediately.

public void
startInBackgroundAndWait(long
maximum wait time in milliseconds
_maxWaitMillis
)

Starts the DBusDaemon in background.

public void
startInBackgroundAndWait()

Starts the DBusDaemon in background.

public void
startInForeground()

Run the DBusDaemon in foreground.

private void
startListening()

Start listening for incoming connections.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

addressback to summary
private final BusAddress address
bindCallbackback to summary
private Consumer<AbstractTransport> bindCallback
closedback to summary
private final AtomicBoolean closed
connectCallbackback to summary
private Consumer<AbstractTransport> connectCallback
daemonback to summary
private DBusDaemon daemon
LOGGERback to summary
private static final Logger LOGGER
saslAuthModeback to summary
private TransportBuilder.SaslAuthMode saslAuthMode
serviceLoaderClassLoaderback to summary
private ClassLoader serviceLoaderClassLoader
serviceLoaderModuleLayerback to summary
private ModuleLayer serviceLoaderModuleLayer
startupLatchback to summary
private CountDownLatch startupLatch
unixSocketFileGroupback to summary
private String unixSocketFileGroup
unixSocketFileOwnerback to summary
private String unixSocketFileOwner
unixSocketFilePermissionsback to summary
private PosixFilePermission[] unixSocketFilePermissions

Constructor Detail

EmbeddedDBusDaemonback to summary
public EmbeddedDBusDaemon(BusAddress _address)
EmbeddedDBusDaemonback to summary
public EmbeddedDBusDaemon(String _address) throws InvalidBusAddressException

Method Detail

closeback to summary
public synchronized void close() throws IOException

Implements java.io.Closeable.close.

Shutdown the running DBusDaemon instance.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Closeable.close.

if an I/O error occurs

getBindCallbackback to summary
public Consumer<AbstractTransport> getBindCallback()

Configured bind callback.

Returns:Consumer<AbstractTransport>

Consumer or null

getConnectCallbackback to summary
public Consumer<AbstractTransport> getConnectCallback()

Configured pre-connect callback.

Returns:Consumer<AbstractTransport>

Consumer or null

getSaslAuthModeback to summary
public TransportBuilder.SaslAuthMode getSaslAuthMode()

The currently configured SaslAuthMode. When null is returned, the SaslAuthMode of the transport provider is used.

Returns:TransportBuilder.SaslAuthMode

SaslAuthMode or null

isRunningback to summary
public synchronized boolean isRunning()

Whether the DBusDaemon is still running.

Returns:boolean

true if running, false otherwise

setBindCallbackback to summary
public void setBindCallback(Consumer<AbstractTransport> _callback)

Callback which will be called by transport right after the server socket was bound.
Server will not yet accept connections at this point, but it started listening on the configured address.

setConnectCallbackback to summary
public void setConnectCallback(Consumer<AbstractTransport> _connectCallback)

Callback which will be called by transport right before the socket is bound and connections will be accepted.

Parameters
_connectCallback:Consumer<AbstractTransport>

callback or null to disable

setDaemonAndStartback to summary
private synchronized void setDaemonAndStart(AbstractTransport _transport)
setSaslAuthModeback to summary
public void setSaslAuthMode(TransportBuilder.SaslAuthMode _saslAuthMode)

Use this to override the default authentication mode which would be used by the transport based on the BusAddress.

Parameters
_saslAuthMode:TransportBuilder.SaslAuthMode

auth mode, null to use default

setServiceLoaderClassLoaderback to summary
public void setServiceLoaderClassLoader(ClassLoader _serviceLoaderClassLoader)

ClassLoader to use for ServiceLoader to find ITransportProvider implementations.

Parameters
_serviceLoaderClassLoader:ClassLoader

class loader

setServiceLoaderModuleLayerback to summary
public void setServiceLoaderModuleLayer(ModuleLayer _serviceLoaderModuleLayer)

Module Layer to use for ServiceLoader to find ITransportProvider implementations.

Parameters
_serviceLoaderModuleLayer:ModuleLayer

module layer

setUnixSocketGroupback to summary
public void setUnixSocketGroup(String _group)

The file group for the created unix socket.
Ignored if TCP is used.

Will only work if currently running JVM process user has suitable permissions to change the group.

Parameters
_group:String

group to set

setUnixSocketOwnerback to summary
public void setUnixSocketOwner(String _owner)

The file owner for the created unix socket.
Ignored if TCP is used.

Will only work if currently running JVM process user has suitable permissions to change the owner.

Parameters
_owner:String

owner to set

setUnixSocketPermissionsback to summary
public void setUnixSocketPermissions(PosixFilePermission... _permissions)

The file permissions for the created unix socket.
Ignored if TCP is used or if the OS is Windows.

Will only work if currently running JVM process user has suitable permissions to change the permissions.

Parameters
_permissions:PosixFilePermission[]

permissions to set

startInBackgroundback to summary
public void startInBackground()

Start the DBusDaemon in background and returns immediately.

This method may return before the background thread is ready. To ensure the the background thread is running on return use startInBackgroundAndWait(long).

startInBackgroundAndWaitback to summary
public void startInBackgroundAndWait(long _maxWaitMillis) throws IllegalStateException

Starts the DBusDaemon in background.

Will wait up to the given period of milliseconds for the background thread to get ready.

Parameters
_maxWaitMillis:long

maximum wait time in milliseconds

Exceptions
IllegalStateException:
when interrupted or wait for daemon timed out
startInBackgroundAndWaitback to summary
public void startInBackgroundAndWait() throws IllegalStateException

Starts the DBusDaemon in background.

Waits until the daemon is ready before return indefinitely. If given wait time exceeded, a RuntimeException is thrown.

Exceptions
IllegalStateException:
when interrupted while waiting for daemon to start
Since
5.0.0 - 2023-10-20
startInForegroundback to summary
public void startInForeground()

Run the DBusDaemon in foreground.

This is a blocking operation.

startListeningback to summary
private void startListening() throws IOException, DBusException

Start listening for incoming connections.

Will throw IllegalArgumentException if a unsupported transport is used.

Exceptions
IOException:
when connection fails
DBusException:
when the provided bus address is wrong