Class BlockingClient

    • Constructor Detail

      • BlockingClient

        public BlockingClient​( serverAddress,
                              StreamConnection connection,
                              java.time.Duration connectTimeout,
                              java.util.Set<BlockingClient> clientSet)

        Creates a new client to the given server address using the given StreamConnection to decode the data. The given connection MUST be unique to this object. This does not block while waiting for the connection to open, but will call either the StreamConnection.connectionOpened() or StreamConnection.connectionClosed() callback on the created network event processing thread.

        connectTimeout - The connect timeout set on the connection. ZERO is interpreted as no timeout.
        socketFactory - An object that creates Socket objects on demand, which may be customised to control how this client connects to the internet. If not sure, use SocketFactory.getDefault()
        clientSet - A set which this object will add itself to after initialization, and then remove itself from
    • Method Detail

      • runReadLoop

        public static void runReadLoop​( stream,
                                       StreamConnection connection)
                                throws java.lang.Exception
        A blocking call that never returns, except by throwing an exception. It reads bytes from the input stream and feeds them to the provided StreamConnection, for example, a Peer.
      • writeBytes

        public ListenableCompletableFuture<java.lang.Void> writeBytes​(byte[] message)
        Description copied from interface: MessageWriteTarget
        Writes the given bytes to the remote server. The returned future will complete when all bytes have been written to the OS network buffer.
        Specified by:
        writeBytes in interface MessageWriteTarget
      • getConnectFuture

        public ListenableCompletableFuture<> getConnectFuture()
        Returns a future that completes once connection has occurred at the socket level or with an exception if failed to connect.