com.hazelcast.client.connection

## Class ClientConnectionStrategy

- java.lang.Object
- - com.hazelcast.client.connection.ClientConnectionStrategy

- Direct Known Subclasses:
    DefaultClientConnectionStrategy

      public abstract class ClientConnectionStrategy
      extends Object

  An abstract class called from `ClientConnectionManager` to customize how client connect to cluster, and provide various behaviours like async start or restart.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ClientConnectionStrategyConfig` | `clientConnectionStrategyConfig`
    `protected ClientContext` | `clientContext`
    `protected ILogger` | `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClientConnectionStrategy()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract void` | `beforeConnectToCluster(Address target)` If a cluster connection is established, this method will be called.
    `abstract void` | `beforeGetConnection(Address target)` The purpose of this method is to validate a connection request by target, and exit the blocking invocation.
    `abstract void` | `beforeOpenConnection(Address target)` If a new connection is required to open by `ClientConnectionManager`, this method will be called.
    `void` | `init(ClientContext clientContext)` Initialize this strategy with client context and config
    `abstract void` | `onClusterConnect()` If a cluster connection is established, this method will be called.
    `abstract void` | `onConnect(ClientConnection connection)` If the `ClientConnectionManager` opens a new connection to a member, this method will be called with the connection parameter
    `abstract void` | `onDisconnect(ClientConnection connection)` If a connection is disconnected, this method will be called with the connection parameter
    `abstract void` | `onDisconnectFromCluster()` If the cluster connection is lost for any reason, this method will be called.
    `abstract void` | `shutdown()` This will be called as the last step of the HazelcastClient's shutdown.
    `abstract void` | `start()` Starts the ClientConnectionStrategy; this will trigger connecting to the cluster.

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

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

- - ### Field Detail

    - #### clientContext

          protected ClientContext clientContext

    - #### logger

          protected ILogger logger

    - #### clientConnectionStrategyConfig

          protected ClientConnectionStrategyConfig clientConnectionStrategyConfig

  - ### Constructor Detail

    - #### ClientConnectionStrategy

          public ClientConnectionStrategy()

  - ### Method Detail

    - #### init

          public void init(ClientContext clientContext)

      Initialize this strategy with client context and config
      Parameters:
        `clientContext` - hazelcast client context to access internal services

    - #### start

          public abstract void start()

      Starts the ClientConnectionStrategy; this will trigger connecting to the cluster.

    - #### beforeGetConnection

          public abstract void beforeGetConnection(Address target)

      The purpose of this method is to validate a connection request by target, and exit the blocking invocation. For all connection requests on `ClientConnectionManager` this method will be called. The build in retry mechanism can be stopped by throwing an instance of non retryable exceptions; `IOException`, `HazelcastInstanceNotActiveException` or `RetryableException` The thrown exception will be received on the blocking user. Any blocking invocation will exit by that exception.
      Parameters:
        `target` - address of the requested connection

    - #### beforeOpenConnection

          public abstract void beforeOpenConnection(Address target)

      If a new connection is required to open by `ClientConnectionManager`, this method will be called. This request can be rejected by throwing an instance of non retryable exceptions; `IOException`, `HazelcastInstanceNotActiveException` or `RetryableException`
      Parameters:
        `target` - address of the requested connection

    - #### beforeConnectToCluster

          public abstract void beforeConnectToCluster(Address target)

      If a cluster connection is established, this method will be called.
      Parameters:
        `target` - address of the requested connection

    - #### onClusterConnect

          public abstract void onClusterConnect()

      If a cluster connection is established, this method will be called. if an exception is thrown, the already established connection will be closed.

    - #### onDisconnectFromCluster

          public abstract void onDisconnectFromCluster()

      If the cluster connection is lost for any reason, this method will be called.

    - #### onConnect

          public abstract void onConnect(ClientConnection connection)

      If the `ClientConnectionManager` opens a new connection to a member, this method will be called with the connection parameter
      Parameters:
        `connection` - the new established connection

    - #### onDisconnect

          public abstract void onDisconnect(ClientConnection connection)

      If a connection is disconnected, this method will be called with the connection parameter
      Parameters:
        `connection` - the closed connection

    - #### shutdown

          public abstract void shutdown()

      This will be called as the last step of the HazelcastClient's shutdown.

Copyright © 2020. All rights reserved.