com.hazelcast.nio.tcp

## Class TcpIpConnectionManager

- java.lang.Object
- - com.hazelcast.nio.tcp.TcpIpConnectionManager

- All Implemented Interfaces:
    ConnectionListenable, ConnectionManager, com.hazelcast.spi.impl.PacketHandler

      public class TcpIpConnectionManager
      extends Object
      implements ConnectionManager, com.hazelcast.spi.impl.PacketHandler

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TcpIpConnectionManager(IOService ioService, ServerSocketChannel serverSocketChannel, LoggingService loggingService, com.hazelcast.internal.metrics.MetricsRegistry metricsRegistry, com.hazelcast.internal.networking.EventLoopGroup eventLoopGroup)`
    `TcpIpConnectionManager(IOService ioService, ServerSocketChannel serverSocketChannel, LoggingService loggingService, com.hazelcast.internal.metrics.MetricsRegistry metricsRegistry, com.hazelcast.internal.networking.EventLoopGroup eventLoopGroup, HazelcastProperties properties)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addConnectionListener(ConnectionListener listener)` Registers a ConnectionListener.
    `int` | `getActiveConnectionCount()` Gets the number of active connections.
    `Set<TcpIpConnection>` | `getActiveConnections()`
    `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.
    `com.hazelcast.internal.networking.EventLoopGroup` | `getEventLoopGroup()`
    `IOService` | `getIoService()`
    `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` | `handle(Packet packet)` Signals the PacketHandler that there is a packet to be handled.
    `void` | `incrementTextConnections()`
    `boolean` | `isLive()`
    `void` | `onConnectionClose(Connection connection)` Deals with cleaning up a closed connection.
    `boolean` | `registerConnection(Address remoteEndPoint, 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.
    `String` | `toString()`
    `boolean` | `transmit(Packet packet, Address target)` Retries sending packet maximum 5 times until connection to target becomes available.
    `boolean` | `transmit(Packet packet, Connection connection)` Transmits a packet to a certain connection.

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

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

- - ### Constructor Detail

    - #### TcpIpConnectionManager

          public TcpIpConnectionManager(IOService ioService,
                                        ServerSocketChannel serverSocketChannel,
                                        LoggingService loggingService,
                                        com.hazelcast.internal.metrics.MetricsRegistry metricsRegistry,
                                        com.hazelcast.internal.networking.EventLoopGroup eventLoopGroup)

    - #### TcpIpConnectionManager

          public TcpIpConnectionManager(IOService ioService,
                                        ServerSocketChannel serverSocketChannel,
                                        LoggingService loggingService,
                                        com.hazelcast.internal.metrics.MetricsRegistry metricsRegistry,
                                        com.hazelcast.internal.networking.EventLoopGroup eventLoopGroup,
                                        HazelcastProperties properties)

  - ### Method Detail

    - #### getIoService

          public IOService getIoService()

    - #### getEventLoopGroup

          public com.hazelcast.internal.networking.EventLoopGroup getEventLoopGroup()

    - #### getActiveConnections

          public Set<TcpIpConnection> getActiveConnections()

    - #### getActiveConnectionCount

          public int getActiveConnectionCount()

      Description copied from interface: `ConnectionManager`
      Gets the number of active connections.
      Specified by:
        `getActiveConnectionCount` in interface `ConnectionManager`
      Returns:
        the number of active connections

    - #### getAllTextConnections

          public int getAllTextConnections()

      Description copied from interface: `ConnectionManager`
      Gets the number of text connections (rest/memcache)
      Specified by:
        `getAllTextConnections` in interface `ConnectionManager`
      Returns:
        the number of text connections

    - #### getConnectionCount

          public int getConnectionCount()

      Description copied from interface: `ConnectionManager`
      Gets the total number of connections.
      Specified by:
        `getConnectionCount` in interface `ConnectionManager`
      Returns:
        the total number of connections

    - #### incrementTextConnections

          public void incrementTextConnections()

    - #### addConnectionListener

          public void addConnectionListener(ConnectionListener listener)

      Description copied from interface: `ConnectionListenable`
      Registers a ConnectionListener. If the same listener is registered multiple times, it will be notified multiple times.
      Specified by:
        `addConnectionListener` in interface `ConnectionListenable`
      Parameters:
        `listener` - the ConnectionListener to add.

    - #### handle

          public void handle(Packet packet)
                      throws Exception

      Description copied from interface: `com.hazelcast.spi.impl.PacketHandler`
      Signals the PacketHandler that there is a packet to be handled.
      Specified by:
        `handle` in interface `com.hazelcast.spi.impl.PacketHandler`
      Parameters:
        `packet` - the response packet to handle
      Throws:
        `Exception`

    - #### registerConnection

          public boolean registerConnection(Address remoteEndPoint,
                                            Connection connection)

      Specified by:
        `registerConnection` in interface `ConnectionManager`

    - #### getConnection

          public Connection getConnection(Address address)

      Description copied from interface: `ConnectionManager`
      Gets the connection for a given address. If the connection does not exist, it returns null.
      Specified by:
        `getConnection` in interface `ConnectionManager`
      Parameters:
        `address` - the remote side of the connection
      Returns:
        the found Connection, or none if one doesn't exist

    - #### getOrConnect

          public Connection getOrConnect(Address address)

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

    - #### getOrConnect

          public Connection getOrConnect(Address address,
                                         boolean silent)

      Description copied from interface: `ConnectionManager`
      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 `ConnectionManager.getConnection(Address)`.

      Specified by:
        `getOrConnect` in interface `ConnectionManager`
      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

    - #### onConnectionClose

          public void onConnectionClose(Connection connection)

      Deals with cleaning up a closed connection. This method should only be called once by the `TcpIpConnection.close(String, Throwable)` method where it is protected against multiple closes.
      Specified by:
        `onConnectionClose` in interface `ConnectionManager`

    - #### start

          public void start()

      Description copied from interface: `ConnectionManager`
      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.

      Specified by:
        `start` in interface `ConnectionManager`

    - #### stop

          public void stop()

      Description copied from interface: `ConnectionManager`
      Stops ConnectionManager, releases its resources, stops threads, etc. When stopped, ConnectionManager can be started again using `ConnectionManager.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.

      Specified by:
        `stop` in interface `ConnectionManager`

    - #### shutdown

          public void shutdown()

      Description copied from interface: `ConnectionManager`
      Shutdowns ConnectionManager completely. ConnectionManager will not be operational anymore and cannot be restarted.

      This method has no effect if it is already shutdown.

      Specified by:
        `shutdown` in interface `ConnectionManager`

    - #### getCurrentClientConnections

          public int getCurrentClientConnections()

      Description copied from interface: `ConnectionManager`
      Gets the number of client connections.
      Specified by:
        `getCurrentClientConnections` in interface `ConnectionManager`
      Returns:
        number of client connections

    - #### isLive

          public boolean isLive()

    - #### transmit

          public boolean transmit(Packet packet,
                                  Connection connection)

      Description copied from interface: `ConnectionManager`
      Transmits a packet to a certain connection.

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

      Specified by:
        `transmit` in interface `ConnectionManager`
      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)

    - #### transmit

          public boolean transmit(Packet packet,
                                  Address target)

      Retries sending packet maximum 5 times until connection to target becomes available.
      Specified by:
        `transmit` in interface `ConnectionManager`
      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.
      See Also:
        `ConnectionManager.transmit(com.hazelcast.nio.Packet, com.hazelcast.nio.Connection)`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2018. All rights reserved.