org.apache.ignite.internal.client

## Interface GridClient

All Superinterfaces:
  AutoCloseable

All Known Implementing Classes:
  GridClientImpl, GridRouterClientImpl

    public interface GridClient
    extends AutoCloseable

Ignite Java client API.

Contains functionality to get projections for accessing remote data and compute functionality, as well as provide listeners on topology changes.

You can obtain an instance of `GridClient` through `GridClientFactory.start(GridClientConfiguration)`. Note that you can have multiple instances of `GridClient` running in the same VM. For information on how to start or stop Grid please refer to `GridClientFactory` class.

Use the following method to get access to remote cache functionality:

- `data(String)`

Use following methods to get access to remote compute functionality:

- `compute()`

# Partition awareness

One of the unique properties of the Ignite remote clients is that they are affinity aware. In other words, both compute and data APIs will optionally contact exactly the node where the data is cached based on some affinity key. This allows for collocation of computations and data and avoids extra network hops that would be necessary if non-affinity nodes were contacted.

If client can't access some of grid nodes directly (for example due to security restrictions) either dedicated Router component could be used or some of Grid nodes could act as routers. See `GridClientConfiguration.getRouters()` for more details.

See Also:
  `GridClientCompute`, `GridClientData`

### Method Summary

All Methods Instance Methods Abstract 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.
`GridClientData` `data(String cacheName)` Gets a data projection for grid cache with name `cacheName`.
`UUID` `id()` Gets a unique client identifier.
`void` `removeTopologyListener(GridClientTopologyListener lsnr)` Removes previously added topology listener.
`GridClientClusterState` `state()` Get client cluster state projection, for perform activate/deactivate operation on cluster.
`void` `throwLastError()` If client was not connected topology, throw last error encountered.
`Collection<GridClientTopologyListener>` `topologyListeners()` Gets an unmodifiable snapshot of topology listeners list.

### Method Detail

#### id

    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.

Returns:
  Generated client id.

#### data

    GridClientData data(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.

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

    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.

Returns:
  Default compute projection.
See Also:
  `GridClientCompute`

#### state

    GridClientClusterState state()

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

Returns:
  Cluster state projection.
See Also:
  `GridClientClusterState`

#### addTopologyListener

    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.

Parameters:
  `lsnr` - Listener to add.

#### removeTopologyListener

    void removeTopologyListener(GridClientTopologyListener lsnr)

Removes previously added topology listener.

Parameters:
  `lsnr` - Listener to remove.

#### topologyListeners

    Collection<GridClientTopologyListener> topologyListeners()

Gets an unmodifiable snapshot of topology listeners list.

Returns:
  List of topology listeners.

#### connected

    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.

Returns:
  Whether client is connected to remote Grid.

#### close

    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`

#### throwLastError

    void throwLastError()
                 throws GridClientException

If client was not connected topology, throw last error encountered.

Throws:
  `GridClientException` - If client was not connected

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.8.1
Release Date | : May 21 2020