org.apache.ignite.internal.client.impl

## Class GridClientImpl

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

All Implemented Interfaces:
  AutoCloseable, GridClient

    public class GridClientImpl
    extends Object
    implements GridClient

Client implementation.

### Field Summary

Fields
`protected GridClientConfiguration` `cfg` Client configuration.
`protected GridClientConnectionManager` `connMgr` Connection manager.
`protected GridClientTopology` `top` Topology.

### Constructor Summary

Constructors
Constructor and Description
`GridClientImpl(UUID id, GridClientConfiguration cfg0, boolean routerClient)` Creates a new client based on a given configuration.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addTopologyListener(GridClientTopologyListener lsnr)` Adds topology listener.
`void` `close()` Closes client instance.
`GridClientCompute` `compute()` Gets a default compute projection.
`boolean` `connected()` Indicates whether client is connected to remote Grid.
`GridClientConnectionManager` `connectionManager()`
`GridClientData` `data()` Gets a data projection for a default grid cache with `null` name.
`GridClientData` `data(String cacheName)` Gets a data projection for grid cache with name `cacheName`.
`UUID` `id()` Gets a unique client identifier.
`GridClientConnectionManager` `newConnectionManager(Byte marshId, boolean routerClient)`
`void` `removeTopologyListener(GridClientTopologyListener lsnr)` Removes previously added topology listener.
`GridClientClusterState` `state()` Get client cluster state projection, for perform activate/deactivate operation on cluster.
`void` `stop(boolean waitCompletion)` Closes client.
`GridClientTopology` `topology()` Gets topology instance.
`Collection<GridClientTopologyListener>` `topologyListeners()` Gets an unmodifiable snapshot of topology listeners list.
`String` `toString()`

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

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

### Field Detail

#### cfg

    protected final GridClientConfiguration cfg

Client configuration.

#### top

    protected GridClientTopology top

Topology.

#### connMgr

    protected GridClientConnectionManager connMgr

Connection manager.

### Constructor Detail

#### GridClientImpl

    public GridClientImpl(UUID id,
                          GridClientConfiguration cfg0,
                          boolean routerClient)
                   throws GridClientException

Creates a new client based on a given configuration.

Parameters:
  `id` - Client identifier.
  `cfg0` - Client configuration.
  `routerClient` - Router client flag.
Throws:
  `GridClientException` - If client configuration is incorrect.
  `GridServerUnreachableException` - If none of the servers specified in configuration can be reached.

### Method Detail

#### id

    public UUID id()

Gets a unique client identifier. This identifier is generated by factory on client creation and used in identification and authentication procedure on server node.

Specified by:
  `id` in interface `GridClient`
Returns:
  Generated client id.

#### stop

    public void stop(boolean waitCompletion)

Closes client.

Parameters:
  `waitCompletion` - If `true` will wait for all pending requests to be proceeded.

#### data

    public GridClientData data()
                        throws GridClientException

Gets a data projection for a default grid cache with `null` name.

Specified by:
  `data` in interface `GridClient`
Returns:
  Data projection for grid cache with `null` name.
Throws:
  `GridClientException` - If client was closed.

#### data

    public GridClientData data(@Nullable
                               String cacheName)
                        throws GridClientException

Gets a data projection for grid cache with name `cacheName`. If no data configuration with given name was provided at client startup, an exception will be thrown.

Specified by:
  `data` in interface `GridClient`
Parameters:
  `cacheName` - Grid cache name for which data projection should be obtained.
Returns:
  Data projection for grid cache with name `cacheName`.
Throws:
  `GridClientException` - If client was closed or no configuration with given name was provided.

#### compute

    public GridClientCompute compute()

Gets a default compute projection. Default compute projection will include all nodes in remote grid. Selection of node that will be connected to perform operations will be done according to `GridClientLoadBalancer` provided in client configuration or according to affinity if projection call involves affinity key.

More restricted projection configurations may be created with `GridClientCompute` methods.

Specified by:
  `compute` in interface `GridClient`
Returns:
  Default compute projection.
See Also:
  `GridClientCompute`

#### state

    public GridClientClusterState state()

Get client cluster state projection, for perform activate/deactivate operation on cluster.

Specified by:
  `state` in interface `GridClient`
Returns:
  Cluster state projection.
See Also:
  `GridClientClusterState`

#### addTopologyListener

    public void addTopologyListener(GridClientTopologyListener lsnr)

Adds topology listener. Remote grid topology is refreshed every `GridClientConfiguration.getTopologyRefreshFrequency()` milliseconds. If any node was added or removed, a listener will be notified.

Specified by:
  `addTopologyListener` in interface `GridClient`
Parameters:
  `lsnr` - Listener to add.

#### removeTopologyListener

    public void removeTopologyListener(GridClientTopologyListener lsnr)

Removes previously added topology listener.

Specified by:
  `removeTopologyListener` in interface `GridClient`
Parameters:
  `lsnr` - Listener to remove.

#### topologyListeners

    public Collection<GridClientTopologyListener> topologyListeners()

Gets an unmodifiable snapshot of topology listeners list.

Specified by:
  `topologyListeners` in interface `GridClient`
Returns:
  List of topology listeners.

#### connected

    public boolean connected()

Indicates whether client is connected to remote Grid. In other words it allow to determine if client is able to communicate with Grid right now. If it can't all methods on Compute and Data projections throw `GridClientDisconnectedException`.

Connection status is updated in background together with topology update. See `GridClientConfiguration.getTopologyRefreshFrequency()` for more details on how background topology update works.

Note that due to asynchronous nature of topology update and connectivity detection this method gives no guarantees for subsequent calls for projections methods. It can be used only fo diagnostic and monitoring purposes.

Specified by:
  `connected` in interface `GridClient`
Returns:
  Whether client is connected to remote Grid.

#### close

    public void close()

Closes client instance. This method is identical to `GridClientFactory.stop(clientId)`.

The method is invoked automatically on objects managed by the `try-with-resources` statement.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `GridClient`

#### topology

    public GridClientTopology topology()

Gets topology instance.

Returns:
  Topology instance.

#### connectionManager

    public GridClientConnectionManager connectionManager()

Returns:
  Connection manager.

#### newConnectionManager

    public GridClientConnectionManager newConnectionManager(@Nullable
                                                            Byte marshId,
                                                            boolean routerClient)
                                                     throws GridClientException

Returns:
  New connection manager based on current client settings.
Throws:
  `GridClientException` - If failed to start connection server.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2018 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.7.5
Release Date | : June 4 2019