com.hazelcast.nio

## Interface ConnectionManager

- All Superinterfaces:
    ConnectionListenable
  All Known Implementing Classes:
    TcpIpConnectionManager

      @PrivateApi
      public interface ConnectionManager
      extends ConnectionListenable

  Responsible for managing `Connection` objects.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getActiveConnectionCount()` Gets the number of active connections.
    `int` | `getAllTextConnections()` Gets the number of text connections (rest/memcache)
    `Connection` | `getConnection(Address address)` Gets the connection for a given address.
    `int` | `getConnectionCount()` Gets the total number of connections.
    `int` | `getCurrentClientConnections()` Gets the number of client connections.
    `Connection` | `getOrConnect(Address address)` Gets the existing connection for a given address or connects.
    `Connection` | `getOrConnect(Address address, boolean silent)` Gets the existing connection for a given address.
    `void` | `onConnectionClose(Connection connection)` Deals with cleaning up a closed connection.
    `boolean` | `registerConnection(Address address, Connection connection)`
    `void` | `shutdown()` Shutdowns ConnectionManager completely.
    `void` | `start()` Starts ConnectionManager, initializes its resources, starts threads, etc.
    `void` | `stop()` Stops ConnectionManager, releases its resources, stops threads, etc.
    `boolean` | `transmit(Packet packet, Address target)` Transmits a packet to a certain address.
    `boolean` | `transmit(Packet packet, Connection connection)` Transmits a packet to a certain connection.

    - ### Methods inherited from interface com.hazelcast.nio.ConnectionListenable

      `addConnectionListener`

- - ### Method Detail

    - #### getCurrentClientConnections

          int getCurrentClientConnections()

      Gets the number of client connections.
      Returns:
        number of client connections

    - #### getAllTextConnections

          int getAllTextConnections()

      Gets the number of text connections (rest/memcache)
      Returns:
        the number of text connections

    - #### getConnectionCount

          int getConnectionCount()

      Gets the total number of connections.
      Returns:
        the total number of connections

    - #### getActiveConnectionCount

          int getActiveConnectionCount()

      Gets the number of active connections.
      Returns:
        the number of active connections

    - #### getConnection

          Connection getConnection(Address address)

      Gets the connection for a given address. If the connection does not exist, it returns null.
      Parameters:
        `address` - the remote side of the connection
      Returns:
        the found Connection, or none if one doesn't exist

    - #### getOrConnect

          Connection getOrConnect(Address address)

      Gets the existing connection for a given address or connects. This call is silent.
      Parameters:
        `address` - the address to connect to
      Returns:
        the found connection, or `null` if no connection exists
      See Also:
        `getOrConnect(Address, boolean)`

    - #### getOrConnect

          Connection getOrConnect(Address address,
                                  boolean silent)

      Gets the existing connection for a given address. If it does not exist, the system will try to connect asynchronously. In this case, it returns `null`.

      When the connection is established at some point in time, it can be retrieved using the `getConnection(Address)`.

      Parameters:
        `address` - the address to connect to
        `silent` - if logging should be done on debug level (`silent=true`) or on info level (`silent=false`)
      Returns:
        the existing connection

    - #### registerConnection

          boolean registerConnection(Address address,
                                     Connection connection)

    - #### onConnectionClose

          void onConnectionClose(Connection connection)

      Deals with cleaning up a closed connection. This method should only be called once by the `Connection.close(String, Throwable)` method where it is protected against multiple closes.

    - #### transmit

          boolean transmit(Packet packet,
                           Connection connection)

      Transmits a packet to a certain connection.

      If this method is called with a `null` connection, the call returns `false`.

      Parameters:
        `packet` - the packet to transmit
        `connection` - he connection to where the Packet should be transmitted
      Returns:
        `true` if the transmit was a success, `false` if a failure (there is no guarantee that the packet is actually going to be received since the packet perhaps is stuck in some buffer; it just means that it's buffered somewhere)
      Throws:
        `NullPointerException` - if the packet is `null`

    - #### transmit

          boolean transmit(Packet packet,
                           Address target)

      Transmits a packet to a certain address.

      If the connection to the target doesn't exist yet, the system will try to make the connection. In this case true can be returned, even though the connection eventually can't be established.

      Parameters:
        `packet` - The Packet to transmit.
        `target` - The address of the target machine where the Packet should be transmitted.
      Returns:
        true if the transmit was a success, false if a failure.
      Throws:
        `NullPointerException` - if packet or target is null.
      See Also:
        `transmit(com.hazelcast.nio.Packet, com.hazelcast.nio.Connection)`

    - #### start

          void start()

      Starts ConnectionManager, initializes its resources, starts threads, etc. After start, ConnectionManager becomes fully operational.

      If it is already started, then this method has no effect.

      Throws:
        `IllegalStateException` - if ConnectionManager is shutdown

    - #### stop

          void stop()

      Stops ConnectionManager, releases its resources, stops threads, etc. When stopped, ConnectionManager can be started again using `start()`.

      This method has no effect if it is already stopped or shutdown.

      Currently `stop` is called during the merge process to detach node from the current cluster. After node becomes ready to join to the new cluster, `start` is called to re-initialize the ConnectionManager.

    - #### shutdown

          void shutdown()

      Shutdowns ConnectionManager completely. ConnectionManager will not be operational anymore and cannot be restarted.

      This method has no effect if it is already shutdown.

Copyright © 2018. All rights reserved.