Class DirectConnection
- java.lang.Object
-
- org.freedesktop.dbus.connections.AbstractConnection
-
- org.freedesktop.dbus.connections.impl.DirectConnection
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class DirectConnection extends AbstractConnection
Handles a peer to peer connection between two applications without a bus daemon.Signal Handlers and method calls from remote objects are run in their own threads, you MUST handle the concurrency issues.
-
-
Field Summary
Fields Modifier and Type Field Description private org.slf4j.Loggerloggerprivate java.lang.StringmachineId-
Fields inherited from class org.freedesktop.dbus.connections.AbstractConnection
BUSNAME_REGEX, CONNID_REGEX, DOLLAR_PATTERN, FLOAT_SUPPORT, MAX_ARRAY_LENGTH, MAX_NAME_LENGTH, OBJECT_REGEX_PATTERN, TCP_ADDRESS_PROPERTY, TCP_CONNECT_TIMEOUT
-
-
Constructor Summary
Constructors Constructor Description DirectConnection(java.lang.String _address)Deprecated, for removal: This API element is subject to removal in a future version.DirectConnection(java.lang.String _address, int _timeout)Deprecated, for removal: This API element is subject to removal in a future version.DirectConnection(TransportConfig _transportCfg, ReceivingServiceConfig _rsCfg)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected java.lang.AutoCloseableaddGenericSigHandler(DBusMatchRule _rule, DBusSigHandler<DBusSignal> _handler)Adds aDBusMatchRuleto with a generic signal handler.protected <T extends DBusSignal>
java.lang.AutoCloseableaddSigHandler(DBusMatchRule _rule, DBusSigHandler<T> _handler)Add a signal handler with the givenDBusMatchRuleto DBus.private java.lang.StringcreateMachineId()(package private) static TransportConfigcreateTransportConfig(java.lang.String _address, int _timeout)Deprecated, for removal: This API element is subject to removal in a future version.(package private) <T extends DBusInterface>
TdynamicProxy(java.lang.String _path, java.lang.Class<T> _type)(package private) <T extends DBusInterface>
TgetExportedObject(java.lang.String _path, java.lang.Class<T> _type)DBusInterfacegetExportedObject(java.lang.String _source, java.lang.String _path)Retrieves an remote object using source and path.<T extends DBusInterface>
TgetExportedObject(java.lang.String _source, java.lang.String _path, java.lang.Class<T> _type)Retrieves an remote object using source and path.java.lang.StringgetMachineId()The generated UUID of this machine.DBusInterfacegetRemoteObject(java.lang.String _objectPath)Return a reference to a remote object.<T extends DBusInterface>
TgetRemoteObject(java.lang.String _objectPath, java.lang.Class<T> _type)Return a reference to a remote object.voidlisten()Use this method when running on server side.protected voidremoveGenericSigHandler(DBusMatchRule _rule, DBusSigHandler<DBusSignal> _handler)Remove a generic signal handler with the givenDBusMatchRule.protected <T extends DBusSignal>
voidremoveSigHandler(DBusMatchRule _rule, DBusSigHandler<T> _handler)Remove a match rule with the givenDBusSigHandler.-
Methods inherited from class org.freedesktop.dbus.connections.AbstractConnection
addFallback, addSigHandler, addSigHandler, addSigHandlerWithoutMatch, callMethodAsync, callWithCallback, changeThreadCount, close, disconnect, disconnect, exportObject, exportObject, findMatchingTypes, getAddress, getCallInfo, getDisconnectCallback, getEndianness, getError, getExportedObject, getExportedObjects, getGenericHandledSignals, getHandledSignals, getImportedObjects, getObjectTree, getPendingCalls, getPendingErrorQueue, getSystemEndianness, handleException, internalDisconnect, isConnected, queueCallback, removeFallback, removeSigHandler, removeSigHandler, sendMessage, setDisconnectCallback, setEndianness, setWeakReferences, toString, unExportObject
-
-
-
-
Constructor Detail
-
DirectConnection
@Deprecated(since="4.1.0", forRemoval=true) public DirectConnection(java.lang.String _address) throws DBusExceptionDeprecated, for removal: This API element is subject to removal in a future version.Create a direct connection to another application.- Parameters:
_address- The address to connect to. This is a standard D-Bus address, except that the additional parameter 'listen=true' should be added in the application which is creating the socket.- Throws:
DBusException- on error
-
DirectConnection
@Deprecated(since="4.1.0", forRemoval=true) public DirectConnection(java.lang.String _address, int _timeout) throws DBusExceptionDeprecated, for removal: This API element is subject to removal in a future version.Create a direct connection to another application.- Parameters:
_address- The address to connect to. This is a standard D-Bus address, except that the additional parameter 'listen=true' should be added in the application which is creating the socket._timeout- the timeout set for the underlying socket. 0 will block forever on the underlying socket.- Throws:
DBusException- on error
-
DirectConnection
DirectConnection(TransportConfig _transportCfg, ReceivingServiceConfig _rsCfg) throws DBusException
- Throws:
DBusException
-
-
Method Detail
-
createTransportConfig
@Deprecated(since="4.2.0", forRemoval=true) static TransportConfig createTransportConfig(java.lang.String _address, int _timeout)Deprecated, for removal: This API element is subject to removal in a future version.
-
listen
public void listen()
Use this method when running on server side. Call will block.- Overrides:
listenin classAbstractConnection
-
createMachineId
private java.lang.String createMachineId()
-
dynamicProxy
<T extends DBusInterface> T dynamicProxy(java.lang.String _path, java.lang.Class<T> _type) throws DBusException
- Throws:
DBusException
-
getExportedObject
<T extends DBusInterface> T getExportedObject(java.lang.String _path, java.lang.Class<T> _type) throws DBusException
- Throws:
DBusException
-
getRemoteObject
public DBusInterface getRemoteObject(java.lang.String _objectPath) throws DBusException
Return a reference to a remote object. This method will always refer to the well known name (if given) rather than resolving it to a unique bus name. In particular this means that if a process providing the well known name disappears and is taken over by another process proxy objects gained by this method will make calls on the new proccess. This method will use bus introspection to determine the interfaces on a remote object and so may block and may fail. The resulting proxy object will, however, be castable to any interface it implements. It will also autostart the process if applicable. Also note that the resulting proxy may fail to execute the correct method with overloaded methods and that complex types may fail in interesting ways. Basically, if something odd happens, try specifying the interface explicitly.- Parameters:
_objectPath- The path on which the process is exporting the object.- Returns:
- A reference to a remote object.
- Throws:
java.lang.ClassCastException- If type is not a sub-type of DBusInterfaceDBusException- If busname or objectpath are incorrectly formatted.
-
getRemoteObject
public <T extends DBusInterface> T getRemoteObject(java.lang.String _objectPath, java.lang.Class<T> _type) throws DBusException
Return a reference to a remote object. This method will always refer to the well known name (if given) rather than resolving it to a unique bus name. In particular this means that if a process providing the well known name disappears and is taken over by another process proxy objects gained by this method will make calls on the new proccess.- Type Parameters:
T- class which extends DBusInterface- Parameters:
_objectPath- The path on which the process is exporting the object._type- The interface they are exporting it on. This type must have the same full class name and exposed method signatures as the interface the remote object is exporting.- Returns:
- A reference to a remote object.
- Throws:
java.lang.ClassCastException- If type is not a sub-type of DBusInterfaceDBusException- If busname or objectpath are incorrectly formatted or type is not in a package.
-
removeSigHandler
protected <T extends DBusSignal> void removeSigHandler(DBusMatchRule _rule, DBusSigHandler<T> _handler) throws DBusException
Description copied from class:AbstractConnectionRemove a match rule with the givenDBusSigHandler. The rule will only be removed from DBus if no other additional handlers are registered to the same rule.- Specified by:
removeSigHandlerin classAbstractConnection- Type Parameters:
T- signal type- Parameters:
_rule- rule to remove_handler- handler to remove- Throws:
DBusException- on error
-
addSigHandler
protected <T extends DBusSignal> java.lang.AutoCloseable addSigHandler(DBusMatchRule _rule, DBusSigHandler<T> _handler) throws DBusException
Description copied from class:AbstractConnectionAdd a signal handler with the givenDBusMatchRuleto DBus. The rule will be added to DBus if it was not added before. If the rule was already added, the signal handler is added to the internal map receiving the same signal as the first (and additional) handlers for this rule.- Specified by:
addSigHandlerin classAbstractConnection- Type Parameters:
T- signal type- Parameters:
_rule- rule to add_handler- handler to use- Returns:
- closeable that removes signal handler
- Throws:
DBusException- on error
-
removeGenericSigHandler
protected void removeGenericSigHandler(DBusMatchRule _rule, DBusSigHandler<DBusSignal> _handler) throws DBusException
Description copied from class:AbstractConnectionRemove a generic signal handler with the givenDBusMatchRule. The rule will only be removed from DBus if no other additional handlers are registered to the same rule.- Specified by:
removeGenericSigHandlerin classAbstractConnection- Parameters:
_rule- rule to remove_handler- handler to remove- Throws:
DBusException- on error
-
addGenericSigHandler
protected java.lang.AutoCloseable addGenericSigHandler(DBusMatchRule _rule, DBusSigHandler<DBusSignal> _handler) throws DBusException
Description copied from class:AbstractConnectionAdds aDBusMatchRuleto with a generic signal handler. Generic signal handlers allow receiving different signals with the same handler. If the rule was already added, the signal handler is added to the internal map receiving the same signal as the first (and additional) handlers for this rule.- Specified by:
addGenericSigHandlerin classAbstractConnection- Parameters:
_rule- rule to add_handler- handler to use- Returns:
- closeable that removes signal handler
- Throws:
DBusException- on error
-
getExportedObject
public <T extends DBusInterface> T getExportedObject(java.lang.String _source, java.lang.String _path, java.lang.Class<T> _type) throws DBusException
Description copied from class:AbstractConnectionRetrieves an remote object using source and path. Will use the given type as object class.- Specified by:
getExportedObjectin classAbstractConnection- Parameters:
_source- source_path- path_type- class of remote object- Returns:
DBusInterfacecompatible object- Throws:
DBusException
-
getMachineId
public java.lang.String getMachineId()
Description copied from class:AbstractConnectionThe generated UUID of this machine.- Specified by:
getMachineIdin classAbstractConnection- Returns:
- String
-
getExportedObject
public DBusInterface getExportedObject(java.lang.String _source, java.lang.String _path) throws DBusException
Description copied from class:AbstractConnectionRetrieves an remote object using source and path. Will try to find suitable exported DBusInterface automatically.- Specified by:
getExportedObjectin classAbstractConnection- Parameters:
_source- source_path- path- Returns:
DBusInterfacecompatible object- Throws:
DBusException
-
-