com.h3c.util.net.msg

## Class Connection

- java.lang.Object
- - com.h3c.util.net.msg.Connection

-     public class Connection
      extends Object

  Class to provide asynchronous conversation-aware message exchange platform over the specified input and output streams.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `int` | `messageBacklog`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Tear down the connection and de-allocate any internal resources.
    `Map<Integer,Conversation>` | `conversations()` Provides an unmodifiable view of the ongoing conversations on this connection.
    `void` | `endConversation(Conversation conversation)` Conclude the specified conversation.
    `protected void` | `finalize()` Close the connection when we go out of referential scope.
    `InetAddress` | `inetAddress()` Get the remote network address to which this connection leads.
    `ConnectionListener` | `listener()` Gets the listener delegate on this connection.
    `InetAddress` | `localAddress()` Get the local network address on which this connection is bound.
    `int` | `port()` Get the remote network port to which this connection leads.
    `ConversationProvider` | `provider()` Get the conversation provider associated with this connection.
    `ThroughputTracker` | `receivedBytes()` Get throughput tracker for received bytes.
    `ThroughputTracker` | `receivedMessages()` Get throughput tracker for received messages.
    `void` | `resetMetrics()` Resets all message and bytes trackers.
    `void` | `sendMessage(Conversation conversation, byte[] message)` Send a byte array message in the context of the specified conversation.
    `void` | `sendMessage(Conversation conversation, Writable message)` Send a writable message in the context of the specified conversation.
    `void` | `setListener(ConnectionListener listener)` Sets the listener delegate on this connection.
    `Conversation` | `startConversation(String topic, int cid, int parentId)` Initiate a conversation on the specified topic.
    `ThroughputTracker` | `transmittedBytes()` Get throughput tracker for transmitted bytes.
    `ThroughputTracker` | `transmittedMessages()` Get throughput tracker for transmitted messages.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### messageBacklog

          public int messageBacklog

  - ### Method Detail

    - #### provider

          public ConversationProvider provider()

      Get the conversation provider associated with this connection.
      Returns:
        conversation provider associated with the connection

    - #### inetAddress

          public InetAddress inetAddress()

      Get the remote network address to which this connection leads.
      Returns:
        remote network address; null if the connection is not backed by socket input and output streams

    - #### localAddress

          public InetAddress localAddress()

      Get the local network address on which this connection is bound.
      Returns:
        local network address; null if the connection is not backed by socket input and output streams

    - #### port

          public int port()

      Get the remote network port to which this connection leads.
      Returns:
        remote tcp/ip port; 0 if the connection is not backed by socket input and output streams

    - #### finalize

          protected void finalize()
                           throws Throwable

      Close the connection when we go out of referential scope.
      Overrides:
        `finalize` in class `Object`
      Throws:
        `Throwable`

    - #### close

          public void close()

      Tear down the connection and de-allocate any internal resources.

    - #### startConversation

          public Conversation startConversation(String topic,
                                       int cid,
                                       int parentId)

      Initiate a conversation on the specified topic.
      Parameters:
        `topic` - name of the topic
        `cid` - conversation id
        `parentId` - parent conversation id
      Returns:
        conversation context for the given topic

    - #### endConversation

          public void endConversation(Conversation conversation)

      Conclude the specified conversation.
      Parameters:
        `conversation` - conversation to be ended

    - #### sendMessage

          public void sendMessage(Conversation conversation,
                         Writable message)

      Send a writable message in the context of the specified conversation.
      Parameters:
        `conversation` - conversation context
        `message` - writable message to send

    - #### sendMessage

          public void sendMessage(Conversation conversation,
                         byte[] message)

      Send a byte array message in the context of the specified conversation.
      Parameters:
        `conversation` - conversation context
        `message` - byte array to transmit

    - #### listener

          public ConnectionListener listener()

      Gets the listener delegate on this connection.
      Returns:
        listener to which notifications are being sent

    - #### setListener

          public void setListener(ConnectionListener listener)

      Sets the listener delegate on this connection.
      Parameters:
        `listener` - listener to which notifications will be sent

    - #### receivedBytes

          public ThroughputTracker receivedBytes()

      Get throughput tracker for received bytes.
      Returns:
        received bytes tracker

    - #### receivedMessages

          public ThroughputTracker receivedMessages()

      Get throughput tracker for received messages.
      Returns:
        received messages tracker

    - #### transmittedBytes

          public ThroughputTracker transmittedBytes()

      Get throughput tracker for transmitted bytes.
      Returns:
        transmitted bytes tracker

    - #### transmittedMessages

          public ThroughputTracker transmittedMessages()

      Get throughput tracker for transmitted messages.
      Returns:
        transmitted messages tracker

    - #### resetMetrics

          public void resetMetrics()

      Resets all message and bytes trackers.

    - #### conversations

          public Map<Integer,Conversation> conversations()

      Provides an unmodifiable view of the ongoing conversations on this connection.
      Returns:
        ongoing conversations

Copyright © 2014. All Rights Reserved.