org.apache.ignite.internal.client.impl

## Class GridClientClusterStateImpl

- java.lang.Object
- - org.apache.ignite.internal.client.impl.GridClientClusterStateImpl

All Implemented Interfaces:
  GridClientClusterState

    public class GridClientClusterStateImpl
    extends Object
    implements GridClientClusterState

### Nested Class Summary

Nested Classes
`protected static interface` `GridClientAbstractProjection.ClientProjectionClosure<R>` Closure to execute reconnect-handling code.
`protected static interface` `GridClientAbstractProjection.ProjectionFactory<X extends org.apache.ignite.internal.client.impl.GridClientAbstractProjection>` Factory for new projection creation.

### Field Summary

Fields
`protected GridClientLoadBalancer` `balancer` Balancer to be used in this projection.
`protected GridClientImpl` `client` Client instance.
`protected GridClientPredicate<? super GridClientNode>` `filter` Node filter to be applied for this projection.
`protected Collection<GridClientNode>` `nodes` List of nodes included in this projection.

### Constructor Summary

Constructors
Constructor and Description
`GridClientClusterStateImpl(GridClientImpl client, Collection<GridClientNode> nodes, GridClientPredicate<? super GridClientNode> filter, GridClientLoadBalancer balancer)` Creates projection with specified client.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected boolean` `checkNodeAlive(UUID nodeId)` Tries to refresh node on every possible connection in topology.
`String` `clusterName()` Get the cluster name.
`protected T` `createProjection(@Nullable Collection<GridClientNode> nodes, @Nullable GridClientPredicate<? super GridClientNode> filter, @Nullable GridClientLoadBalancer balancer, GridClientAbstractProjection.ProjectionFactory<T> factory)` Creates a sub-projection for current projection.
`UUID` `id()` Unique identifier of cluster STATE command was sent to.
`Collection<? extends GridClientNode>` `projectionNodes()` Gets most recently refreshed topology.
`protected Collection<? extends GridClientNode>` `projectionNodes(@Nullable GridClientPredicate<GridClientNode> pred)` Gets most recently refreshed topology.
`ClusterState` `state()`
`void` `state(ClusterState newState, boolean forceDeactivation)` Changes cluster state to `newState`.
`String` `tag()` User-defined tag of cluster STATE command was sent to.
`protected <R> GridClientFuture<R>` `withReconnectHandling(GridClientAbstractProjection.ClientProjectionClosure<R> c)` This method executes request to a communication layer and handles connection error, if it occurs.
`protected <R> GridClientFuture<R>` `withReconnectHandling(GridClientAbstractProjection.ClientProjectionClosure<R> c, String cacheName, @Nullable Object affKey)` This method executes request to a communication layer and handles connection error, if it occurs.

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

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

### Field Detail

#### nodes

    protected Collection<GridClientNode> nodes

List of nodes included in this projection. If null, all nodes in topology are included.

#### filter

    protected GridClientPredicate<? super GridClientNode> filter

Node filter to be applied for this projection.

#### balancer

    protected GridClientLoadBalancer balancer

Balancer to be used in this projection.

#### client

    protected GridClientImpl client

Client instance.

### Constructor Detail

#### GridClientClusterStateImpl

    public GridClientClusterStateImpl(GridClientImpl client,
                                      Collection<GridClientNode> nodes,
                                      GridClientPredicate<? super GridClientNode> filter,
                                      GridClientLoadBalancer balancer)

Creates projection with specified client.

Parameters:
  `client` - Client instance to use.
  `nodes` - Collections of nodes included in this projection.
  `filter` - Node filter to be applied.
  `balancer` - Balancer to use.

### Method Detail

#### state

    public ClusterState state()
                       throws GridClientException

Specified by:
  `state` in interface `GridClientClusterState`
Returns:
  Current cluster state.
Throws:
  `GridClientException` - If the request to get the cluster state failed.

#### state

    public void state(ClusterState newState,
                      boolean forceDeactivation)
               throws GridClientException

Changes cluster state to `newState`.

Specified by:
  `state` in interface `GridClientClusterState`
Parameters:
  `newState` - New cluster state.
  `forceDeactivation` - If `true`, cluster deactivation will be forced.
Throws:
  `GridClientException` - If the request to change the cluster state failed.
See Also:
  `ClusterState.INACTIVE`

#### id

    public UUID id()
            throws GridClientException

Unique identifier of cluster STATE command was sent to.

Specified by:
  `id` in interface `GridClientClusterState`
Returns:
  ID of the cluster.
Throws:
  `GridClientException`

#### tag

    public String tag()
               throws GridClientException

User-defined tag of cluster STATE command was sent to.

Specified by:
  `tag` in interface `GridClientClusterState`
Returns:
  Tag of the cluster.
Throws:
  `GridClientException`

#### clusterName

    public String clusterName()
                       throws GridClientException

Get the cluster name.

Specified by:
  `clusterName` in interface `GridClientClusterState`
Returns:
  The name of the cluster.
Throws:
  `GridClientException` - If the request to get the cluster name failed.

#### withReconnectHandling

    protected <R> GridClientFuture<R> withReconnectHandling(GridClientAbstractProjection.ClientProjectionClosure<R> c)

This method executes request to a communication layer and handles connection error, if it occurs. In case of communication exception client instance is notified and new instance of client is created. If none of the grid servers can be reached, an exception is thrown.

Type Parameters:
  `R` - Result future type.
Parameters:
  `c` - Closure to be executed.
Returns:
  Future returned by closure.

#### withReconnectHandling

    protected <R> GridClientFuture<R> withReconnectHandling(GridClientAbstractProjection.ClientProjectionClosure<R> c,
                                                            String cacheName,
                                                            @Nullable
                                                            @Nullable Object affKey)

This method executes request to a communication layer and handles connection error, if it occurs. Server is picked up according to the projection affinity and key given. Connection will be made with the node on which key is cached. In case of communication exception client instance is notified and new instance of client is created. If none of servers can be reached, an exception is thrown.

Type Parameters:
  `R` - Type of result in future.
Parameters:
  `c` - Closure to be executed.
  `cacheName` - Cache name for which mapped node will be calculated.
  `affKey` - Affinity key.
Returns:
  Operation future.

#### checkNodeAlive

    protected boolean checkNodeAlive(UUID nodeId)
                              throws GridClientException,
                                     InterruptedException

Tries to refresh node on every possible connection in topology.

Parameters:
  `nodeId` - Node id to check.
Returns:
  `True` if response was received, `false` if either `null` response received or no nodes can be contacted at all.
Throws:
  `GridClientException` - If failed to refresh topology or if client was closed manually.
  `InterruptedException` - If interrupted.

#### projectionNodes

    public Collection<? extends GridClientNode> projectionNodes()
                                                         throws GridClientException

Gets most recently refreshed topology. If this compute instance is a projection, then only nodes that satisfy projection criteria will be returned.

Returns:
  Most recently refreshed topology.
Throws:
  `GridClientException` - If failed to refresh topology.

#### projectionNodes

    protected Collection<? extends GridClientNode> projectionNodes(@Nullable
                                                                   @Nullable GridClientPredicate<GridClientNode> pred)
                                                            throws GridClientException

Gets most recently refreshed topology. If this compute instance is a projection, then only nodes that satisfy projection criteria will be returned.

Parameters:
  `pred` - Predicate to additionally filter projection nodes, if `null` just return projection.
Returns:
  Most recently refreshed topology.
Throws:
  `GridClientException` - If failed to refresh topology.

#### createProjection

    protected T createProjection(@Nullable
                                 @Nullable Collection<GridClientNode> nodes,
                                 @Nullable
                                 @Nullable GridClientPredicate<? super GridClientNode> filter,
                                 @Nullable
                                 @Nullable GridClientLoadBalancer balancer,
                                 GridClientAbstractProjection.ProjectionFactory<T> factory)
                          throws GridClientException

Creates a sub-projection for current projection.

Parameters:
  `nodes` - Collection of nodes that sub-projection will be restricted to. If `null`, created projection is dynamic and will take nodes from topology.
  `filter` - Filter to be applied to nodes in projection. If `null` - no filter applied.
  `balancer` - Balancer to use in projection. If `null` - inherit balancer from the current projection.
  `factory` - Factory to create new projection.
Returns:
  Created projection.
Throws:
  `GridClientException` - If resulting projection is empty. Note that this exception may only be thrown on case of static projections, i.e. where collection of nodes is not null.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.14.0
Release Date | : September 29 2022