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.voidcompressConnection(String method, Runnable onSuccess)Compresses the connection.voidflush()Flushes the connection.InetSocketAddressgetRemoteAddress()Gets the remote address of this connection.booleanisSecure()Indicates whether this connection is secured by TLS/SSL.booleanisUsingAcknowledgements()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.voidsecureConnection()This method is called from the reader thread.CompletableFuture<Void>send(StreamElement element)Sends an element to the peer entity.StringtoString()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:ConnectionOpens 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:ConnectionIndicates whether this connection is secured by TLS/SSL.- Returns:
- True, if this connection is secured.
-
secureConnection
public void secureConnection() throws IOException, CertificateException, NoSuchAlgorithmExceptionThis method is called from the reader thread. Because it accesses shared data (socket, outputStream, inputStream) it should be synchronized.- Specified by:
secureConnectionin classTcpConnection- Throws:
IOExceptionCertificateExceptionNoSuchAlgorithmException
-
compressConnection
public void compressConnection(String method, Runnable onSuccess) throws Exception
Description copied from class:TcpConnectionCompresses the connection.- Specified by:
compressConnectionin 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:ConnectionWrites 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:ConnectionFlushes the connection. Any buffered elements written viaConnection.write(StreamElement)are sent.
-
closeFuture
public final CompletionStage<Void> closeFuture()
Description copied from interface:ConnectionReturns a future which is complete, when the connection is closed.- Returns:
- The close future.
-
getRemoteAddress
public final InetSocketAddress getRemoteAddress()
Description copied from interface:ConnectionGets the remote address of this connection.- Returns:
- The remote address.
-
isUsingAcknowledgements
public final boolean isUsingAcknowledgements()
Description copied from interface:ConnectionIndicates whether this connection uses acknowledgements, e.g. by means of stream management or BOSH acks.- Specified by:
isUsingAcknowledgementsin interfaceConnection- Overrides:
isUsingAcknowledgementsin classAbstractConnection- Returns:
- If this connection uses acknowledgements.
-
-