com.hazelcast.client.connection.nio

## Class ClientConnectionManagerImpl

- java.lang.Object
- - com.hazelcast.client.connection.nio.ClientConnectionManagerImpl

- All Implemented Interfaces:
    ClientConnectionManager, ConnectionListenable

      public class ClientConnectionManagerImpl
      extends Object
      implements ClientConnectionManager

  Implementation of `ClientConnectionManager`.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `alive`
    `protected AtomicInteger` | `connectionIdGen`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClientConnectionManagerImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl client)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addConnectionListener(ConnectionListener connectionListener)` Registers a ConnectionListener.
    `void` | `beforeClusterSwitch(com.hazelcast.client.impl.clientside.CandidateClusterContext context)`
    `protected ClientConnection` | `createSocketConnection(Address remoteAddress)`
    `Connection` | `getActiveConnection(Address target)`
    `Collection<ClientConnection>` | `getActiveConnections()`
    `ClientConnectionStrategy` | `getConnectionStrategy()`
    `Credentials` | `getLastCredentials()`
    `com.hazelcast.internal.networking.nio.NioNetworking` | `getNetworking()`
    `Connection` | `getOrConnect(Address address)`
    `Connection` | `getOrConnect(Address address, boolean asOwner)`
    `Connection` | `getOrTriggerConnect(Address target, boolean acquiresResources)`
    `ClientConnection` | `getOwnerConnection()`
    `Address` | `getOwnerConnectionAddress()`
    `com.hazelcast.client.impl.client.ClientPrincipal` | `getPrincipal()`
    `protected com.hazelcast.internal.networking.nio.NioNetworking` | `initNetworking(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl client)`
    `boolean` | `isAlive()` Check if client connection manager is alive.
    `void` | `setCandidateClusterContext(com.hazelcast.client.impl.clientside.CandidateClusterContext context)`
    `void` | `shutdown()`
    `void` | `start()`
    `protected void` | `startNetworking()`
    `protected void` | `stopNetworking()`

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

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

- - ### Field Detail

    - #### connectionIdGen

          protected final AtomicInteger connectionIdGen

    - #### alive

          protected volatile boolean alive

  - ### Constructor Detail

    - #### ClientConnectionManagerImpl

          public ClientConnectionManagerImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl client)

  - ### Method Detail

    - #### getNetworking

          public com.hazelcast.internal.networking.nio.NioNetworking getNetworking()

    - #### initNetworking

          protected com.hazelcast.internal.networking.nio.NioNetworking initNetworking(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl client)

    - #### getConnectionStrategy

          public ClientConnectionStrategy getConnectionStrategy()

    - #### getActiveConnections

          public Collection<ClientConnection> getActiveConnections()

      Specified by:
        `getActiveConnections` in interface `ClientConnectionManager`

    - #### isAlive

          public boolean isAlive()

      Description copied from interface: `ClientConnectionManager`
      Check if client connection manager is alive. ClientConnectionManager is not alive only when client is closing.
      Specified by:
        `isAlive` in interface `ClientConnectionManager`
      Returns:
        true if alive, false otherwise.

    - #### start

          public void start()

    - #### startNetworking

          protected void startNetworking()

    - #### shutdown

          public void shutdown()

    - #### getPrincipal

          public com.hazelcast.client.impl.client.ClientPrincipal getPrincipal()

      Specified by:
        `getPrincipal` in interface `ClientConnectionManager`

    - #### stopNetworking

          protected void stopNetworking()

    - #### getActiveConnection

          public Connection getActiveConnection(Address target)

      Specified by:
        `getActiveConnection` in interface `ClientConnectionManager`
      Parameters:
        `target` - to be connected
      Returns:
        connection if available, null otherwise

    - #### getOrConnect

          public Connection getOrConnect(Address address)
                                  throws IOException

      Specified by:
        `getOrConnect` in interface `ClientConnectionManager`
      Parameters:
        `address` - to be connected
      Returns:
        associated connection if available, creates new connection otherwise
      Throws:
        `IOException` - if connection is not established

    - #### getOrTriggerConnect

          public Connection getOrTriggerConnect(Address target,
                                                boolean acquiresResources)
                                         throws IOException

      Specified by:
        `getOrTriggerConnect` in interface `ClientConnectionManager`
      Parameters:
        `target` - to be connected
      Returns:
        associated connection if available, returns null and triggers new connection creation otherwise
      Throws:
        `IOException` - if connection is not able to triggered

    - #### getOwnerConnectionAddress

          public Address getOwnerConnectionAddress()

      Specified by:
        `getOwnerConnectionAddress` in interface `ClientConnectionManager`

    - #### getOrConnect

          public Connection getOrConnect(Address address,
                                         boolean asOwner)

    - #### getOwnerConnection

          public ClientConnection getOwnerConnection()

      Specified by:
        `getOwnerConnection` in interface `ClientConnectionManager`

    - #### createSocketConnection

          protected ClientConnection createSocketConnection(Address remoteAddress)
                                                     throws IOException

      Throws:
        `IOException`

    - #### addConnectionListener

          public void addConnectionListener(ConnectionListener connectionListener)

      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:
        `connectionListener` - the ConnectionListener to add.

    - #### getLastCredentials

          public Credentials getLastCredentials()

    - #### setCandidateClusterContext

          public void setCandidateClusterContext(com.hazelcast.client.impl.clientside.CandidateClusterContext context)

      Specified by:
        `setCandidateClusterContext` in interface `ClientConnectionManager`

    - #### beforeClusterSwitch

          public void beforeClusterSwitch(com.hazelcast.client.impl.clientside.CandidateClusterContext context)

      Specified by:
        `beforeClusterSwitch` in interface `ClientConnectionManager`

Copyright © 2019. All rights reserved.