Class AbstractTransport
java.lang.Object
org.freedesktop.dbus.connections.transports.AbstractTransport
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
AbstractUnixTransport,TcpTransport
Base class for all transport types.
- Since:
- v3.2.0 - 2019-02-08
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BusAddressprivate final TransportConfigprivate booleanprivate final org.slf4j.Loggerprivate final ServiceLoader<ISocketProvider> private static final AtomicLongprivate TransportConnectionprivate final long -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractTransport(BusAddress _address, TransportConfig _config) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidauthenticate(SocketChannel _sock) Helper method to authenticate to DBus using SASL.voidclose()final SocketChannelconnect()Establish connection on created transport.protected abstract SocketChannelAbstract method implemented by concrete sub classes to establish a connection using whatever transport type (e.g.private TransportConnectioncreateInputOutput(SocketChannel _socket) Setup message reader/writer.protected BusAddressReturns theBusAddressused for this transport.protected org.slf4j.LoggerGet the logger in subclasses.protected intDeprecated, for removal: This API element is subject to removal in a future version.protected SaslConfigReturns the current configuration used for SASL authentication.protected SASL.SaslModeDeprecated, for removal: This API element is subject to removal in a future version.please usegetSaslConfig().getMode() insteadprotected abstract booleanMethod to indicate if passing of file descriptors is allowed.private TransportConnectionprotected abstract booleanDeprecated, for removal: This API element is subject to removal in a future version.Is no longer used and will be removedbooleanReturns true if inputReader and outputWriter are not yet closed.final TransportConnectionlisten()Start listening on created transport.Read a message from the underlying socket.voidSet a callback which will be called right before the connection will be established to the transport.protected voidsetSaslAuthMode(int _mode) Deprecated, for removal: This API element is subject to removal in a future version.please usegetSaslConfig().setSaslAuthMode(int) insteadprotected voidsetSaslMode(SASL.SaslMode _saslMode) Deprecated, for removal: This API element is subject to removal in a future version.please usegetSaslConfig().setMode(int) insteadtoString()voidwriteMessage(Message _msg) Write a message to the underlying socket.
-
Field Details
-
TRANSPORT_ID_GENERATOR
-
spiLoader
-
logger
private final org.slf4j.Logger logger -
address
-
transportConnection
-
fileDescriptorSupported
private boolean fileDescriptorSupported -
transportId
private final long transportId -
config
-
-
Constructor Details
-
AbstractTransport
-
-
Method Details
-
writeMessage
Write a message to the underlying socket.- Parameters:
_msg- message to write- Throws:
IOException- on write error or if output was already closed or null
-
readMessage
Read a message from the underlying socket.- Returns:
- read message, maybe null
- Throws:
IOException- when input already close or nullDBusException- when message could not be converted to a DBus message
-
isConnected
public boolean isConnected()Returns true if inputReader and outputWriter are not yet closed.- Returns:
- boolean
-
hasFileDescriptorSupport
protected abstract boolean hasFileDescriptorSupport()Method to indicate if passing of file descriptors is allowed.- Returns:
- true to allow FD passing, false otherwise
-
isAbstractAllowed
@Deprecated(forRemoval=true, since="4.2.0 - 2022-07-18") protected abstract boolean isAbstractAllowed()Deprecated, for removal: This API element is subject to removal in a future version.Is no longer used and will be removedReturn true if the transport supports 'abstract' sockets.- Returns:
- true if abstract sockets supported, false otherwise
-
connectImpl
Abstract method implemented by concrete sub classes to establish a connection using whatever transport type (e.g. TCP/Unix socket).- Throws:
IOException- when connection fails
-
connect
Establish connection on created transport.
This method can only be used for non-listening connections.
Trying to use this with listening addresses will throw anInvalidBusAddressException.- Returns:
SocketChannelof the created connection- Throws:
IOException- if connection fails
-
listen
Start listening on created transport.
This method can only be used for listening connections.
Trying to use this with non-listening addresses will throw anInvalidBusAddressException.Will return the
TransportConnectionas soon as a client connects.
Therefore this method should be called in a loop to accept multiple clients- Returns:
TransportConnectioncontaining createdSocketChannelandIMessageReader/IMessageWriter- Throws:
IOException- if connection fails
-
internalConnect
- Throws:
IOException
-
setPreConnectCallback
Set a callback which will be called right before the connection will be established to the transport.- Parameters:
_run- runnable to execute, null if no callback should be executed- Since:
- 4.2.0 - 2022-07-20
-
authenticate
Helper method to authenticate to DBus using SASL.- Parameters:
_sock- socketchannel- Throws:
IOException- on any error
-
createInputOutput
Setup message reader/writer. Will look for SPI provider first, if none is found default implementation is used. The default implementation does not support file descriptor passing!- Parameters:
_socket- socket to use- Returns:
- TransportConnection with configured socket channel, reader and writer
-
getAddress
Returns theBusAddressused for this transport.- Returns:
- BusAddress, never null
-
getLogger
protected org.slf4j.Logger getLogger()Get the logger in subclasses.- Returns:
- Logger, never null
-
getSaslConfig
Returns the current configuration used for SASL authentication.- Returns:
- SaslConfig, never null
-
getSaslAuthMode
Deprecated, for removal: This API element is subject to removal in a future version.please usegetSaslConfig().getAuthMode() insteadSet the SASL authentication mode. -
getSaslMode
Deprecated, for removal: This API element is subject to removal in a future version.please usegetSaslConfig().getMode() insteadSet the SASL authentication mode. -
setSaslMode
@Deprecated(since="4.2.0 - 2022-07-22", forRemoval=true) protected void setSaslMode(SASL.SaslMode _saslMode) Deprecated, for removal: This API element is subject to removal in a future version.please usegetSaslConfig().setMode(int) insteadSet the SASL mode (server or client).- Parameters:
_saslMode- mode to set
-
setSaslAuthMode
Deprecated, for removal: This API element is subject to removal in a future version.please usegetSaslConfig().setSaslAuthMode(int) insteadSet the SASL authentication mode.- Parameters:
_mode- mode to set
-
toString
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getSaslConfig().getAuthMode() instead