Class AbstractTransport
- java.lang.Object
-
- org.freedesktop.dbus.connections.transports.AbstractTransport
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
AbstractUnixTransport,TcpTransport
public abstract class AbstractTransport extends java.lang.Object implements java.io.CloseableBase class for all transport types.- Since:
- v3.2.0 - 2019-02-08
-
-
Field Summary
Fields Modifier and Type Field Description private BusAddressaddressprivate TransportConfigconfigprivate booleanfileDescriptorSupportedprivate org.slf4j.Loggerloggerprivate java.util.ServiceLoader<ISocketProvider>spiLoaderprivate static java.util.concurrent.atomic.AtomicLongTRANSPORT_ID_GENERATORprivate TransportConnectiontransportConnectionprivate longtransportId
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractTransport(BusAddress _address, TransportConfig _config)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private voidauthenticate(java.nio.channels.SocketChannel _sock)Helper method to authenticate to DBus using SASL.voidclose()java.nio.channels.SocketChannelconnect()Establish connection on created transport.protected abstract java.nio.channels.SocketChannelconnectImpl()Abstract method implemented by concrete sub classes to establish a connection using whatever transport type (e.g.private TransportConnectioncreateInputOutput(java.nio.channels.SocketChannel _socket)Setup message reader/writer.protected BusAddressgetAddress()Returns theBusAddressused for this transport.protected org.slf4j.LoggergetLogger()Get the logger in subclasses.protected intgetSaslAuthMode()Deprecated, for removal: This API element is subject to removal in a future version.please usegetSaslConfig().getAuthMode() insteadprotected SaslConfiggetSaslConfig()Returns the current configuration used for SASL authentication.protected SASL.SaslModegetSaslMode()Deprecated, for removal: This API element is subject to removal in a future version.please usegetSaslConfig().getMode() insteadprotected abstract booleanhasFileDescriptorSupport()Method to indicate if passing of file descriptors is allowed.private TransportConnectioninternalConnect()protected abstract booleanisAbstractAllowed()Deprecated, for removal: This API element is subject to removal in a future version.Is no longer used and will be removedbooleanisConnected()Returns true if inputReader and outputWriter are not yet closed.TransportConnectionlisten()Start listening on created transport.MessagereadMessage()Read a message from the underlying socket.voidsetPreConnectCallback(java.util.function.Consumer<AbstractTransport> _run)Set 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) insteadjava.lang.StringtoString()voidwriteMessage(Message _msg)Write a message to the underlying socket.
-
-
-
Field Detail
-
TRANSPORT_ID_GENERATOR
private static final java.util.concurrent.atomic.AtomicLong TRANSPORT_ID_GENERATOR
-
spiLoader
private final java.util.ServiceLoader<ISocketProvider> spiLoader
-
logger
private final org.slf4j.Logger logger
-
address
private final BusAddress address
-
transportConnection
private TransportConnection transportConnection
-
fileDescriptorSupported
private boolean fileDescriptorSupported
-
transportId
private final long transportId
-
config
private final TransportConfig config
-
-
Constructor Detail
-
AbstractTransport
protected AbstractTransport(BusAddress _address, TransportConfig _config)
-
-
Method Detail
-
writeMessage
public void writeMessage(Message _msg) throws java.io.IOException
Write a message to the underlying socket.- Parameters:
_msg- message to write- Throws:
java.io.IOException- on write error or if output was already closed or null
-
readMessage
public Message readMessage() throws java.io.IOException, DBusException
Read a message from the underlying socket.- Returns:
- read message, maybe null
- Throws:
java.io.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
protected abstract java.nio.channels.SocketChannel connectImpl() throws java.io.IOExceptionAbstract method implemented by concrete sub classes to establish a connection using whatever transport type (e.g. TCP/Unix socket).- Throws:
java.io.IOException- when connection fails
-
connect
public final java.nio.channels.SocketChannel connect() throws java.io.IOExceptionEstablish 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:
java.io.IOException- if connection fails
-
listen
public final TransportConnection listen() throws java.io.IOException
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:
java.io.IOException- if connection fails
-
internalConnect
private TransportConnection internalConnect() throws java.io.IOException
- Throws:
java.io.IOException
-
setPreConnectCallback
public void setPreConnectCallback(java.util.function.Consumer<AbstractTransport> _run)
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
private void authenticate(java.nio.channels.SocketChannel _sock) throws java.io.IOExceptionHelper method to authenticate to DBus using SASL.- Parameters:
_sock- socketchannel- Throws:
java.io.IOException- on any error
-
createInputOutput
private TransportConnection createInputOutput(java.nio.channels.SocketChannel _socket)
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
protected BusAddress 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
protected SaslConfig getSaslConfig()
Returns the current configuration used for SASL authentication.- Returns:
- SaslConfig, never null
-
getSaslAuthMode
@Deprecated(since="4.2.0 - 2022-07-22", forRemoval=true) protected int 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(since="4.2.0 - 2022-07-22", forRemoval=true) protected SASL.SaslMode 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(since="4.2.0 - 2022-07-22", forRemoval=true) protected void setSaslAuthMode(int _mode)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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-