Class NetSocket

  • All Implemented Interfaces:
    ReadStream<Buffer>, StreamBase, WriteStream<Buffer>

    public class NetSocket
    extends Object
    implements ReadStream<Buffer>, WriteStream<Buffer>
    Represents a socket-like interface to a TCP connection on either the client or the server side.

    Instances of this class are created on the client side by an NetClient when a connection to a server is made, or on the server side by a NetServer when a server accepts a connection.

    It implements both and so it can be used with Pipe to pipe data with flow control.

    NOTE: This class has been automatically generated from the original non Mutiny-ified interface using Vert.x codegen.

    • Constructor Detail

      • NetSocket

        public NetSocket​(io.vertx.core.net.NetSocket delegate)
      • NetSocket

        public NetSocket​(Object delegate)
    • Method Detail

      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • pipeTo

        public io.smallrye.mutiny.Uni<Void> pipeTo​(WriteStream<Buffer> dst)
        Pipe this ReadStream to the WriteStream.

        Elements emitted by this stream will be written to the write stream until this stream ends or fails.

        Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Specified by:
        pipeTo in interface ReadStream<Buffer>
        Parameters:
        dst - the destination write stream
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • pipeToAndAwait

        public Void pipeToAndAwait​(WriteStream<Buffer> dst)
        Blocking variant of io.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Specified by:
        pipeToAndAwait in interface ReadStream<Buffer>
        Parameters:
        dst - the destination write stream
        Returns:
        the Void instance produced by the operation.
      • pipeToAndForget

        public void pipeToAndForget​(WriteStream<Buffer> dst)
        Variant of io.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream) that ignores the result of the operation.

        This method subscribes on the result of io.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from io.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream) but you don't need to compose it with other operations.

        Specified by:
        pipeToAndForget in interface ReadStream<Buffer>
        Parameters:
        dst - the destination write stream
      • end

        public io.smallrye.mutiny.Uni<Void> end​(Buffer data)
        Same as but with an handler called when the operation completes

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Specified by:
        end in interface WriteStream<Buffer>
        Parameters:
        data -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • endAndAwait

        public Void endAndAwait​(Buffer data)
        Blocking variant of io.vertx.mutiny.core.streams.WriteStream#end(io.vertx.mutiny.core.buffer.Buffer).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Specified by:
        endAndAwait in interface WriteStream<Buffer>
        Parameters:
        data -
        Returns:
        the Void instance produced by the operation.
      • endAndForget

        public void endAndForget​(Buffer data)
        Variant of io.vertx.mutiny.core.streams.WriteStream#end(io.vertx.mutiny.core.buffer.Buffer) that ignores the result of the operation.

        This method subscribes on the result of io.vertx.mutiny.core.streams.WriteStream#end(io.vertx.mutiny.core.buffer.Buffer), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from io.vertx.mutiny.core.streams.WriteStream#end(io.vertx.mutiny.core.buffer.Buffer) but you don't need to compose it with other operations.

        Specified by:
        endAndForget in interface WriteStream<Buffer>
        Parameters:
        data -
      • pause

        public NetSocket pause()
        Specified by:
        pause in interface ReadStream<Buffer>
        Returns:
        a reference to this, so the API can be used fluently
      • fetch

        public NetSocket fetch​(long amount)
        Specified by:
        fetch in interface ReadStream<Buffer>
        Returns:
        a reference to this, so the API can be used fluently
      • setWriteQueueMaxSize

        public NetSocket setWriteQueueMaxSize​(int maxSize)
        Specified by:
        setWriteQueueMaxSize in interface WriteStream<Buffer>
        Parameters:
        maxSize - the max size of the write stream
        Returns:
        a reference to this, so the API can be used fluently
      • writeHandlerID

        public String writeHandlerID()
        Returns:
        the write handler ID
      • write

        public io.smallrye.mutiny.Uni<Void> write​(String str)
        Same as write(java.lang.String) but with an handler called when the operation completes

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        str -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • writeAndAwait

        public Void writeAndAwait​(String str)
        Blocking variant of write(String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        str -
        Returns:
        the Void instance produced by the operation.
      • writeAndForget

        public void writeAndForget​(String str)
        Variant of write(String) that ignores the result of the operation.

        This method subscribes on the result of write(String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from write(String) but you don't need to compose it with other operations.

        Parameters:
        str -
      • write

        public io.smallrye.mutiny.Uni<Void> write​(String str,
                                                  String enc)
        Same as write(java.lang.String) but with an handler called when the operation completes

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        str -
        enc -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • writeAndAwait

        public Void writeAndAwait​(String str,
                                  String enc)
        Blocking variant of write(String,String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        str -
        enc -
        Returns:
        the Void instance produced by the operation.
      • writeAndForget

        public void writeAndForget​(String str,
                                   String enc)
        Variant of write(String,String) that ignores the result of the operation.

        This method subscribes on the result of write(String,String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from write(String,String) but you don't need to compose it with other operations.

        Parameters:
        str -
        enc -
      • write

        public io.smallrye.mutiny.Uni<Void> write​(Buffer message)
        Like WriteStream.write(T) but with an handler called when the message has been written or failed to be written.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Specified by:
        write in interface WriteStream<Buffer>
        Parameters:
        message -
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • writeAndAwait

        public Void writeAndAwait​(Buffer message)
        Blocking variant of io.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Specified by:
        writeAndAwait in interface WriteStream<Buffer>
        Parameters:
        message -
        Returns:
        the Void instance produced by the operation.
      • writeAndForget

        public void writeAndForget​(Buffer message)
        Variant of io.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer) that ignores the result of the operation.

        This method subscribes on the result of io.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from io.vertx.mutiny.core.streams.WriteStream#write(io.vertx.mutiny.core.buffer.Buffer) but you don't need to compose it with other operations.

        Specified by:
        writeAndForget in interface WriteStream<Buffer>
        Parameters:
        message -
      • sendFile

        public io.smallrye.mutiny.Uni<Void> sendFile​(String filename)
        Same as sendFile(java.lang.String) but also takes a handler that will be called when the send has completed or a failure has occurred

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        filename - file name of the file to send
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendFileAndAwait

        public Void sendFileAndAwait​(String filename)
        Blocking variant of sendFile(String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        filename - file name of the file to send
        Returns:
        the Void instance produced by the operation.
      • sendFileAndForget

        public NetSocket sendFileAndForget​(String filename)
        Variant of sendFile(String) that ignores the result of the operation.

        This method subscribes on the result of sendFile(String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from sendFile(String) but you don't need to compose it with other operations.

        Parameters:
        filename - file name of the file to send
        Returns:
        the instance of NetSocket to chain method calls.
      • sendFile

        public io.smallrye.mutiny.Uni<Void> sendFile​(String filename,
                                                     long offset)
        Same as sendFile(java.lang.String) but also takes a handler that will be called when the send has completed or a failure has occurred

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        filename - file name of the file to send
        offset - offset
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendFileAndAwait

        public Void sendFileAndAwait​(String filename,
                                     long offset)
        Blocking variant of sendFile(String,long).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        filename - file name of the file to send
        offset - offset
        Returns:
        the Void instance produced by the operation.
      • sendFileAndForget

        public NetSocket sendFileAndForget​(String filename,
                                           long offset)
        Variant of sendFile(String,long) that ignores the result of the operation.

        This method subscribes on the result of sendFile(String,long), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from sendFile(String,long) but you don't need to compose it with other operations.

        Parameters:
        filename - file name of the file to send
        offset - offset
        Returns:
        the instance of NetSocket to chain method calls.
      • sendFile

        public io.smallrye.mutiny.Uni<Void> sendFile​(String filename,
                                                     long offset,
                                                     long length)
        Same as sendFile(java.lang.String) but also takes a handler that will be called when the send has completed or a failure has occurred

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        filename - file name of the file to send
        offset - offset
        length - length
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • sendFileAndAwait

        public Void sendFileAndAwait​(String filename,
                                     long offset,
                                     long length)
        Blocking variant of sendFile(String,long,long).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        filename - file name of the file to send
        offset - offset
        length - length
        Returns:
        the Void instance produced by the operation.
      • sendFileAndForget

        public NetSocket sendFileAndForget​(String filename,
                                           long offset,
                                           long length)
        Variant of sendFile(String,long,long) that ignores the result of the operation.

        This method subscribes on the result of sendFile(String,long,long), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from sendFile(String,long,long) but you don't need to compose it with other operations.

        Parameters:
        filename - file name of the file to send
        offset - offset
        length - length
        Returns:
        the instance of NetSocket to chain method calls.
      • remoteAddress

        public SocketAddress remoteAddress()
        Returns:
        the remote address for this connection, possibly null (e.g a server bound on a domain socket). If useProxyProtocol is set to true, the address returned will be of the actual connecting client.
      • localAddress

        public SocketAddress localAddress()
        Returns:
        the local address for this connection, possibly null (e.g a server bound on a domain socket) If useProxyProtocol is set to true, the address returned will be of the proxy.
      • end

        public io.smallrye.mutiny.Uni<Void> end()
        Calls end(io.vertx.mutiny.core.buffer.Buffer).

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Specified by:
        end in interface WriteStream<Buffer>
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • endAndAwait

        public Void endAndAwait()
        Blocking variant of WriteStream.end().

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Specified by:
        endAndAwait in interface WriteStream<Buffer>
        Returns:
        the Void instance produced by the operation.
      • endAndForget

        public void endAndForget()
        Variant of WriteStream.end() that ignores the result of the operation.

        This method subscribes on the result of WriteStream.end(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from WriteStream.end() but you don't need to compose it with other operations.

        Specified by:
        endAndForget in interface WriteStream<Buffer>
      • close

        public io.smallrye.mutiny.Uni<Void> close()
        Close the NetSocket and notify the handler when the operation completes.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • closeAndAwait

        public Void closeAndAwait()
        Blocking variant of close().

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Returns:
        the Void instance produced by the operation.
      • closeAndForget

        public void closeAndForget()
        Variant of close() that ignores the result of the operation.

        This method subscribes on the result of close(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from close() but you don't need to compose it with other operations.

      • closeHandler

        public NetSocket closeHandler​(Runnable handler)
        Parameters:
        handler - the handler
        Returns:
      • upgradeToSsl

        public io.smallrye.mutiny.Uni<Void> upgradeToSsl()
        Upgrade channel to use SSL/TLS. Be aware that for this to work SSL must be configured.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • upgradeToSslAndAwait

        public Void upgradeToSslAndAwait()
        Blocking variant of upgradeToSsl().

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Returns:
        the Void instance produced by the operation.
      • upgradeToSslAndForget

        public NetSocket upgradeToSslAndForget()
        Variant of upgradeToSsl() that ignores the result of the operation.

        This method subscribes on the result of upgradeToSsl(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from upgradeToSsl() but you don't need to compose it with other operations.

        Returns:
        the instance of NetSocket to chain method calls.
      • upgradeToSsl

        public io.smallrye.mutiny.Uni<Void> upgradeToSsl​(String serverName)
        Upgrade channel to use SSL/TLS. Be aware that for this to work SSL must be configured.

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        serverName - the server name
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • upgradeToSslAndAwait

        public Void upgradeToSslAndAwait​(String serverName)
        Blocking variant of upgradeToSsl(String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        serverName - the server name
        Returns:
        the Void instance produced by the operation.
      • upgradeToSslAndForget

        public NetSocket upgradeToSslAndForget​(String serverName)
        Variant of upgradeToSsl(String) that ignores the result of the operation.

        This method subscribes on the result of upgradeToSsl(String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from upgradeToSsl(String) but you don't need to compose it with other operations.

        Parameters:
        serverName - the server name
        Returns:
        the instance of NetSocket to chain method calls.
      • isSsl

        public boolean isSsl()
        Returns:
        true if this NetSocket is encrypted via SSL/TLS.
      • indicatedServerName

        public String indicatedServerName()
        Returns:
        the indicated server name
      • applicationLayerProtocol

        public String applicationLayerProtocol()
        Returns:
        the application-level protocol negotiated during the TLS handshake
      • sslSession

        public SSLSession sslSession()
        Returns:
        SSLSession associated with the underlying socket. Returns null if connection is not SSL.
      • toBlockingStream

        public Stream<Buffer> toBlockingStream()
      • newInstance

        public static NetSocket newInstance​(io.vertx.core.net.NetSocket arg)