Package rocks.xmpp.core.net.client
Class SocketConnection
- java.lang.Object
-
- rocks.xmpp.core.net.AbstractConnection
-
- rocks.xmpp.core.net.TcpConnection
-
- rocks.xmpp.core.net.client.SocketConnection
-
- All Implemented Interfaces:
AutoCloseable
,Connection
,StreamHandler
public final class SocketConnection extends TcpConnection
The default TCP socket connection as described in TCP Binding.If no hostname is set (null or empty) the connection tries to resolve the hostname via an SRV DNS lookup.
This class is unconditionally thread-safe.
- See Also:
- 3. TCP Binding
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletionStage<Void>
closeFuture()
Returns a future which is complete, when the connection is closed.void
compressConnection(String method, Runnable onSuccess)
Compresses the connection.void
flush()
Flushes the connection.InetSocketAddress
getRemoteAddress()
Gets the remote address of this connection.boolean
isSecure()
Indicates whether this connection is secured by TLS/SSL.boolean
isUsingAcknowledgements()
Indicates whether this connection uses acknowledgements, e.g. by means of stream management or BOSH acks.CompletionStage<Void>
open(SessionOpen sessionOpen)
Opens the XML stream to the peer entity.void
secureConnection()
This method is called from the reader thread.CompletableFuture<Void>
send(StreamElement element)
Sends an element to the peer entity.String
toString()
CompletableFuture<Void>
write(StreamElement streamElement)
Writes the element to the stream without really sending it.-
Methods inherited from class rocks.xmpp.core.net.AbstractConnection
close, closeAsync, closeAsync, getConfiguration, getStreamId, handleElement, isClosed
-
-
-
-
Method Detail
-
open
public final CompletionStage<Void> open(SessionOpen sessionOpen)
Description copied from interface:Connection
Opens the XML stream to the peer entity.- Parameters:
sessionOpen
- The session open information.- Returns:
- The completion stage, which is complete, if the session has been opened, i.e. the element has been sent.
-
isSecure
public boolean isSecure()
Description copied from interface:Connection
Indicates whether this connection is secured by TLS/SSL.- Returns:
- True, if this connection is secured.
-
secureConnection
public void secureConnection() throws IOException, CertificateException, NoSuchAlgorithmException
This method is called from the reader thread. Because it accesses shared data (socket, outputStream, inputStream) it should be synchronized.- Specified by:
secureConnection
in classTcpConnection
- Throws:
IOException
CertificateException
NoSuchAlgorithmException
-
compressConnection
public void compressConnection(String method, Runnable onSuccess) throws Exception
Description copied from class:TcpConnection
Compresses the connection.- Specified by:
compressConnection
in classTcpConnection
- Parameters:
method
- The compression method.onSuccess
- Invoked after the compression method has been chosen, but before compression is applied.- Throws:
Exception
- Any exception which may occur during compression.
-
send
public final CompletableFuture<Void> send(StreamElement element)
Description copied from interface:Connection
- Parameters:
element
- The element.- Returns:
- The future representing the send process and which allows to cancel it.
-
write
public final CompletableFuture<Void> write(StreamElement streamElement)
Description copied from interface:Connection
Writes the element to the stream without really sending it. It must be flushed.- Parameters:
streamElement
- The element.- Returns:
- The send future.
-
flush
public final void flush()
Description copied from interface:Connection
Flushes the connection. Any buffered elements written viaConnection.write(StreamElement)
are sent.
-
closeFuture
public final CompletionStage<Void> closeFuture()
Description copied from interface:Connection
Returns a future which is complete, when the connection is closed.- Returns:
- The close future.
-
getRemoteAddress
public final InetSocketAddress getRemoteAddress()
Description copied from interface:Connection
Gets the remote address of this connection.- Returns:
- The remote address.
-
isUsingAcknowledgements
public final boolean isUsingAcknowledgements()
Description copied from interface:Connection
Indicates whether this connection uses acknowledgements, e.g. by means of stream management or BOSH acks.- Specified by:
isUsingAcknowledgements
in interfaceConnection
- Overrides:
isUsingAcknowledgements
in classAbstractConnection
- Returns:
- If this connection uses acknowledgements.
-
-