Package org.freedesktop.dbus.bin
Class EmbeddedDBusDaemon
- java.lang.Object
-
- org.freedesktop.dbus.bin.EmbeddedDBusDaemon
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class EmbeddedDBusDaemon extends java.lang.Object implements java.io.CloseableSimple DBusDaemon implementation to use if no DBusDaemon is running on the OS level.
-
-
Field Summary
Fields Modifier and Type Field Description private BusAddressaddressprivate java.util.concurrent.atomic.AtomicBooleanclosedprivate java.util.concurrent.atomic.AtomicBooleanconnectionReadyprivate DBusDaemondaemonprivate static org.slf4j.LoggerLOGGERprivate TransportBuilder.SaslAuthModesaslAuthModeprivate java.lang.StringunixSocketFileGroupprivate java.lang.StringunixSocketFileOwnerprivate java.nio.file.attribute.PosixFilePermission[]unixSocketFilePermissions
-
Constructor Summary
Constructors Constructor Description EmbeddedDBusDaemon(java.lang.String _address)EmbeddedDBusDaemon(BusAddress _address)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Shutdown the running DBusDaemon instance.TransportBuilder.SaslAuthModegetSaslAuthMode()The currently configuredTransportBuilder.SaslAuthMode.booleanisRunning()Whether the DBusDaemon is still running.private voidsetDaemonAndStart(AbstractTransport _transport)voidsetSaslAuthMode(TransportBuilder.SaslAuthMode _saslAuthMode)Use this to override the default authentication mode which would be used by the transport based on theBusAddress.voidsetUnixSocketGroup(java.lang.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.voidsetUnixSocketOwner(java.lang.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.voidsetUnixSocketPermissions(java.nio.file.attribute.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.voidstartInBackground()Start the DBusDaemon in background and returns immediately.voidstartInBackgroundAndWait(long _maxWaitMillis)Starts the DBusDaemon in background.voidstartInForeground()Run the DBusDaemon in foreground.private voidstartListening()Start listening for incoming connections.
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
address
private final BusAddress address
-
daemon
private DBusDaemon daemon
-
closed
private final java.util.concurrent.atomic.AtomicBoolean closed
-
connectionReady
private final java.util.concurrent.atomic.AtomicBoolean connectionReady
-
saslAuthMode
private TransportBuilder.SaslAuthMode saslAuthMode
-
unixSocketFileOwner
private java.lang.String unixSocketFileOwner
-
unixSocketFileGroup
private java.lang.String unixSocketFileGroup
-
unixSocketFilePermissions
private java.nio.file.attribute.PosixFilePermission[] unixSocketFilePermissions
-
-
Constructor Detail
-
EmbeddedDBusDaemon
public EmbeddedDBusDaemon(BusAddress _address)
-
EmbeddedDBusDaemon
public EmbeddedDBusDaemon(java.lang.String _address) throws DBusException- Throws:
DBusException
-
-
Method Detail
-
close
public void close() throws java.io.IOExceptionShutdown the running DBusDaemon instance.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
startInForeground
public void startInForeground()
Run the DBusDaemon in foreground.This is a blocking operation.
-
startInBackground
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).
-
startInBackgroundAndWait
public void startInBackgroundAndWait(long _maxWaitMillis)
Starts the DBusDaemon in background.Will wait up to the given period of milliseconds for the background thread to get ready. If given wait time exceeded, a
RuntimeExceptionis thrown.- Parameters:
_maxWaitMillis- maximum wait time in milliseconds
-
isRunning
public boolean isRunning()
Whether the DBusDaemon is still running.- Returns:
- true if running, false otherwise
-
getSaslAuthMode
public TransportBuilder.SaslAuthMode getSaslAuthMode()
The currently configuredTransportBuilder.SaslAuthMode. When null is returned, theTransportBuilder.SaslAuthModeof the transport provider is used.- Returns:
TransportBuilder.SaslAuthModeor null
-
setSaslAuthMode
public void setSaslAuthMode(TransportBuilder.SaslAuthMode _saslAuthMode)
Use this to override the default authentication mode which would be used by the transport based on theBusAddress.- Parameters:
_saslAuthMode- auth mode, null to use default
-
setUnixSocketOwner
public void setUnixSocketOwner(java.lang.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- owner to set
-
setUnixSocketGroup
public void setUnixSocketGroup(java.lang.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- group to set
-
setUnixSocketPermissions
public void setUnixSocketPermissions(java.nio.file.attribute.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- permissions to set
-
setDaemonAndStart
private void setDaemonAndStart(AbstractTransport _transport)
-
startListening
private void startListening() throws java.io.IOException, DBusExceptionStart listening for incoming connections.Will throw
IllegalArgumentExceptionif a unsupported transport is used.- Throws:
java.io.IOException- when connection failsDBusException- when the provided bus address is wrong
-
-