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` | `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` | `onConnect(ClientConnection connection)` If the `ClientConnectionManager` opens a new connection to a member, this method will be called with the connection parameter
    `abstract void` | `onConnectToCluster()` If a cluster connection is established, this method will be called.
    `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` | `onHeartbeatResumed(ClientConnection connection)` The `ClientConnectionManager` will inform this method that the provided connection's heartbeat resumed
    `abstract void` | `onHeartbeatStopped(ClientConnection connection)` The `ClientConnectionManager` will inform this method that the provided connection's heartbeat stopped
    `abstract void` | `shutdown()` The `ClientConnectionManager` will call this method as a last step of its shutdown.
    `abstract void` | `start()` Called after `ClientConnectionManager` started.

    - ### 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 final 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()

      Called after `ClientConnectionManager` started. Connecting to cluster can be triggered from this method using one of `ClientConnectionManager.connectToCluster()` or `ClientConnectionManager.connectToClusterAsync()`

    - #### 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

    - #### onConnectToCluster

          public abstract void onConnectToCluster()

      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

    - #### onHeartbeatStopped

          public abstract void onHeartbeatStopped(ClientConnection connection)

      The `ClientConnectionManager` will inform this method that the provided connection's heartbeat stopped
      Parameters:
        `connection` - the connection that heartbeat failed

    - #### onHeartbeatResumed

          public abstract void onHeartbeatResumed(ClientConnection connection)

      The `ClientConnectionManager` will inform this method that the provided connection's heartbeat resumed
      Parameters:
        `connection` - the connection that heartbeat resumed

    - #### shutdown

          public abstract void shutdown()

      The `ClientConnectionManager` will call this method as a last step of its shutdown.

Copyright © 2018. All rights reserved.