Package rocks.xmpp.nio.netty.net
Class NettyChannelConnection
- java.lang.Object
-
- rocks.xmpp.core.net.AbstractConnection
-
- rocks.xmpp.core.net.TcpConnection
-
- rocks.xmpp.nio.netty.net.NettyChannelConnection
-
- All Implemented Interfaces:
AutoCloseable,Connection,StreamHandler
public class NettyChannelConnection extends TcpConnection
A NIO connection based on Netty.
-
-
Constructor Summary
Constructors Constructor Description NettyChannelConnection(io.netty.channel.Channel channel, StreamHandler streamHandler, Session session, List<ReaderInterceptor> readerInterceptors, Function<Locale,javax.xml.bind.Unmarshaller> unmarshallerSupplier, List<WriterInterceptor> writerInterceptors, Supplier<javax.xml.bind.Marshaller> marshallerSupplier, Consumer<Throwable> onException, ConnectionConfiguration connectionConfiguration)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletionStage<Void>closeFuture()Returns a future which is complete, when the connection is closed.static <T> CompletableFuture<T>completableFutureFromNettyFuture(io.netty.util.concurrent.Future<T> future)Converts aFutureto aCompletableFuture.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.CompletionStage<Void>open(SessionOpen sessionOpen)Opens the XML stream to the peer entity.voidsecureConnection()Secures the connection with TLS.CompletionStage<Void>send(StreamElement streamElement)Sends an element to the peer entity.StringtoString()CompletionStage<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, isUsingAcknowledgements
-
-
-
-
Constructor Detail
-
NettyChannelConnection
public NettyChannelConnection(io.netty.channel.Channel channel, StreamHandler streamHandler, Session session, List<ReaderInterceptor> readerInterceptors, Function<Locale,javax.xml.bind.Unmarshaller> unmarshallerSupplier, List<WriterInterceptor> writerInterceptors, Supplier<javax.xml.bind.Marshaller> marshallerSupplier, Consumer<Throwable> onException, ConnectionConfiguration connectionConfiguration)
-
-
Method Detail
-
completableFutureFromNettyFuture
public static <T> CompletableFuture<T> completableFutureFromNettyFuture(io.netty.util.concurrent.Future<T> future)
Converts aFutureto aCompletableFuture.- Type Parameters:
T- The type.- Parameters:
future- The Netty Future.- Returns:
- The
CompletableFuture.
-
getRemoteAddress
public final InetSocketAddress getRemoteAddress()
Description copied from interface:ConnectionGets the remote address of this connection.- Returns:
- The remote address.
-
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.
-
send
public final CompletionStage<Void> send(StreamElement streamElement)
Description copied from interface:Connection- Parameters:
streamElement- The element.- Returns:
- The future representing the send process and which allows to cancel it.
-
write
public final CompletionStage<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.
-
secureConnection
public void secureConnection() throws ExceptionDescription copied from class:TcpConnectionSecures the connection with TLS.- Specified by:
secureConnectionin classTcpConnection- Throws:
Exception- Any exception which may occur during TLS handshake.
-
compressConnection
public final void compressConnection(String method, Runnable onSuccess)
Compresses the connection.- Specified by:
compressConnectionin classTcpConnection- Parameters:
method- The compression method. Supported methods are: "zlib", "deflate" and "gzip".onSuccess- Invoked after the compression method has been chosen, but before compression is applied.- Throws:
IllegalArgumentException- If the compression method is unknown.
-
isSecure
public final boolean isSecure()
Description copied from interface:ConnectionIndicates whether this connection is secured by TLS/SSL.- Returns:
- True, if this connection is secured.
-
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.
-
-