Interface TcpConnection


  • public interface TcpConnection
    The interface provides methods for sending and receiving data via TCP connection. Also methods to start and stop the sending and receiving data, send and receive data, set timeouts, set maximum queue size, set thread names and set a listener to listen for events.
    • Method Detail

      • startSender

        void startSender()
        Starts the sending data.
      • startReceiver

        void startReceiver()
                    throws IOException
        Starts the receiving data.
        Throws:
        IOException - if an I/O error occurs.
      • send

        void send​(ByteBuffer byteBuffer)
        Sends the given ByteBuffer through the connection.
        Parameters:
        byteBuffer - the buffer to be sent.
      • setListener

        void setListener​(TcpConnection.Listener listener)
        Sets the listener to listen for events.
        Parameters:
        listener - the listener to be set.
      • close

        void close()
        Closes the connection.
      • isClosed

        boolean isClosed()
        Returns true if the connection is closed, false otherwise.
        Returns:
        true if the connection is closed, false otherwise.
      • isSenderStillInactive

        boolean isSenderStillInactive()
        Returns true if no data is sent and it remains inactive, false otherwise.
        Returns:
        true if no data is sent and it remains inactive, false otherwise.
      • getOutQueueBytes

        long getOutQueueBytes()
        Returns the number of bytes in the out queue to be send.
        Returns:
        the number of bytes in the out queue to be send.
      • setSenderTimeout

        void setSenderTimeout​(long timeout,
                              TimeUnit timeUnit)
        Sets the timeout for the sending data.
        Parameters:
        timeout - the timeout value, in case it is 0, the timeout will never elapse.
        timeUnit - the time unit for the timeout value.
      • setReceiverTimeout

        void setReceiverTimeout​(long timeout,
                                TimeUnit timeUnit)
        Sets the timeout for the receiving data.
        Parameters:
        timeout - the timeout value, in case it is 0, the timeout will never elapse.
        timeUnit - the time unit for the timeout value.
      • setSenderSpinningTimeout

        void setSenderSpinningTimeout​(long timeout,
                                      TimeUnit timeUnit)
        Sets the sending data spinning timeout.
        Parameters:
        timeout - the timeout value.
        timeUnit - the time unit for the timeout value.
      • setReceiverSpinningTimeout

        void setReceiverSpinningTimeout​(long timeout,
                                        TimeUnit timeUnit)
        Sets the receiving data spinning timeout.
        Parameters:
        timeout - the timeout value.
        timeUnit - the time unit for the timeout value.
      • setSendQueueMaxSize

        void setSendQueueMaxSize​(int size)
        Sets the maximum size for the send queue.

        If the max size of the sending queue is reached the send(ByteBuffer) method call will throw an exception

        Parameters:
        size - the maximum size for the send queue.
      • setReceiverThreadName

        void setReceiverThreadName​(String name)
        Sets the name for the receiver thread if the connection use ConnectionMode.DEDICATED_THREADS mode.
        Parameters:
        name - the name of the receiver thread.
      • setTcpSendingChunkSize

        void setTcpSendingChunkSize​(int size)
        TCP sending chunk size, in bytes.

        Limits the amount of data that can be sent in a single send operation. The default value 0 (zero) means no such limit.

        Parameters:
        size - The limit.
      • getTcpSendingChunkSize

        int getTcpSendingChunkSize()
        Returns TCP sending chunk size, in bytes.
        Returns:
        TCP sending chunk size, in bytes.