org.apache.ignite.internal.client.impl.connection

## Class GridClientConnection

- java.lang.Object
- - org.apache.ignite.internal.client.impl.connection.GridClientConnection

Direct Known Subclasses:
  GridClientNioTcpConnection

    public abstract class GridClientConnection
    extends Object

Facade for all possible network communications between client and server. Introduced to hide protocol implementation (TCP, HTTP) from client code.

### Field Summary

Fields
`protected UUID` `clientId` Client id.
`protected org.apache.ignite.internal.client.impl.connection.GridClientConnectionCloseReason` `closeReason` Reason why connection was closed.
`protected GridClientTopology` `top` Topology

### Constructor Summary

Constructors
`protected` `GridClientConnection(UUID clientId, InetSocketAddress srvAddr, SSLContext sslCtx, GridClientTopology top, Object cred)` Creates a facade.

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`abstract <K,V> GridClientFutureAdapter<Boolean>` `cacheAppend(String cacheName, K key, V val, Set<GridClientCacheFlag> flags, UUID destNodeId)` Append requested value to already cached one.
`abstract <K,V> GridClientFutureAdapter<Boolean>` `cacheCompareAndSet(String cacheName, K key, V newVal, V oldVal, Set<GridClientCacheFlag> flags, UUID destNodeId)` New valueActual/old valueBehaviour null null Remove entry for key.
`<K,V> GridClientFutureAdapter<V>` `cacheGet(String cacheName, K key, Set<GridClientCacheFlag> flags, UUID destNodeId)` Gets entry from the cache for specified key.
`abstract <K,V> GridClientFutureAdapter<Map<K,V>>` `cacheGetAll(String cacheName, Collection<K> keys, Set<GridClientCacheFlag> flags, UUID destNodeId)` Gets bundle of entries for specified keys from the cache.
`abstract <K> GridClientFutureAdapter<GridClientDataMetrics>` `cacheMetrics(String cacheName, UUID destNodeId)` Gets cache metrics for the key.
`abstract <K,V> GridClientFutureAdapter<Boolean>` `cachePrepend(String cacheName, K key, V val, Set<GridClientCacheFlag> flags, UUID destNodeId)` Prepend requested value to already cached one.
`<K,V> GridClientFutureAdapter<Boolean>` `cachePut(String cacheName, K key, V val, Set<GridClientCacheFlag> flags, UUID destNodeId)` Puts key-value pair into cache.
`abstract <K,V> GridClientFutureAdapter<Boolean>` `cachePutAll(String cacheName, Map<K,V> entries, Set<GridClientCacheFlag> flags, UUID destNodeId)` Puts bundle of entries into cache.
`abstract <K> GridClientFutureAdapter<Boolean>` `cacheRemove(String cacheName, K key, Set<GridClientCacheFlag> flags, UUID destNodeId)` Removes entry from the cache for specified key.
`abstract <K> GridClientFutureAdapter<Boolean>` `cacheRemoveAll(String cacheName, Collection<K> keys, Set<GridClientCacheFlag> flags, UUID destNodeId)` Removes bundle of entries for specified keys from the cache.
`abstract <K,V> GridClientFutureAdapter<Boolean>` `cacheReplace(String cacheName, K key, V val, Set<GridClientCacheFlag> flags, UUID destNodeId)` Replace key-value pair in cache if already exist.
`abstract GridClientFuture<?>` `changeState(boolean active, UUID destNodeId)` Change grid global state.
`protected void` `checkClosed(org.apache.ignite.internal.client.impl.connection.GridClientConnectionCloseReason reason)` Check if this connection was closed and throws appropriate exception.
`protected Object` `credentials()` Returns credentials for this client connection.
`abstract GridClientFuture<Boolean>` `currentState(UUID destNodeId)` Get current grid state.
`abstract <R> GridClientFutureAdapter<R>` `execute(String taskName, Object arg, UUID destNodeId, boolean keepBinaries)` Execute task in the grid.
`abstract GridClientFutureAdapter<?>` `forwardMessage(Object body)` Forwards a message in raw form to the connected node.
`protected GridClientException` `getCloseReasonAsException(org.apache.ignite.internal.client.impl.connection.GridClientConnectionCloseReason reason, Throwable cause)` Build appropriate exception from the given close reason.
`protected String` `getCloseReasonMessage(org.apache.ignite.internal.client.impl.connection.GridClientConnectionCloseReason reason, Throwable cause)`
`boolean` `isClosed()`
`protected GridClientDataMetrics` `metricsMapToMetrics(Map<String,Number> metricsMap)` Converts metrics map to metrics object.
`abstract GridClientFuture<GridClientNode>` `node(String ipAddr, boolean inclAttrs, boolean includeMetrics, UUID destNodeId)` Gets node by node IP.
`abstract GridClientFuture<GridClientNode>` `node(UUID id, boolean inclAttrs, boolean inclMetrics, UUID destNodeId)` Gets node by node ID.
`protected double` `safeDouble(Map<String,Number> map, String key)` Safely gets double value by given key.
`protected long` `safeLong(Map<String,Number> map, String key)` Safely gets long value by given key.
`InetSocketAddress` `serverAddress()` Gets server address this connection connected to.
`protected SSLContext` `sslContext()` Gets SSLContext of this client connection.
`abstract GridClientFuture<List<GridClientNode>>` `topology(boolean inclAttrs, boolean inclMetrics, UUID destNodeId)` Gets grid topology nodes.

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

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

### Field Detail

#### top

    protected GridClientTopology top

Topology

#### clientId

    protected final UUID clientId

Client id.

#### closeReason

    protected volatile org.apache.ignite.internal.client.impl.connection.GridClientConnectionCloseReason closeReason

Reason why connection was closed. `null` means connection is still alive.

### Constructor Detail

#### GridClientConnection

    protected GridClientConnection(UUID clientId,
                                   InetSocketAddress srvAddr,
                                   SSLContext sslCtx,
                                   GridClientTopology top,
                                   Object cred)

Creates a facade.

Parameters:
  `clientId` - Client identifier.
  `srvAddr` - Server address this connection connected to.
  `sslCtx` - SSL context to use if SSL is enabled, `null` otherwise.
  `top` - Topology.
  `cred` - Client credentials.

### Method Detail

#### serverAddress

    public InetSocketAddress serverAddress()

Gets server address this connection connected to.

Returns:
  Server address this connection connected to.

#### cachePut

    public <K,V> GridClientFutureAdapter<Boolean> cachePut(String cacheName,
                                                           K key,
                                                           V val,
                                                           Set<GridClientCacheFlag> flags,
                                                           UUID destNodeId)
                                                    throws GridClientConnectionResetException,
                                                           GridClientClosedException

Puts key-value pair into cache.

Parameters:
  `cacheName` - Cache name.
  `key` - Key.
  `val` - Value.
  `flags` - Cache flags to be enabled.
  `destNodeId` - Destination node ID.
Returns:
  If value was actually put.
Throws:
  `GridClientConnectionResetException` - In case of error.
  `GridClientClosedException` - If client was manually closed before request was sent over network.

#### cacheGet

    public <K,V> GridClientFutureAdapter<V> cacheGet(String cacheName,
                                                     K key,
                                                     Set<GridClientCacheFlag> flags,
                                                     UUID destNodeId)
                                              throws GridClientConnectionResetException,
                                                     GridClientClosedException

Gets entry from the cache for specified key.

Parameters:
  `cacheName` - Cache name.
  `key` - Key.
  `flags` - Cache flags to be enabled.
  `destNodeId` - Destination node ID.
Returns:
  Value.
Throws:
  `GridClientConnectionResetException` - In case of error.
  `GridClientClosedException` - If client was manually closed before request was sent over network.

#### cacheRemove

    public abstract <K> GridClientFutureAdapter<Boolean> cacheRemove(String cacheName,
                                                                     K key,
                                                                     Set<GridClientCacheFlag> flags,
                                                                     UUID destNodeId)
                                                              throws GridClientConnectionResetException,
                                                                     GridClientClosedException

Removes entry from the cache for specified key.

Parameters:
  `cacheName` - Cache name.
  `key` - Key.
  `flags` - Cache flags to be enabled.
  `destNodeId` - Destination node ID.
Returns:
  Whether entry was actually removed.
Throws:
  `GridClientConnectionResetException` - In case of error.
  `GridClientClosedException` - If client was manually closed before request was sent over network.

#### cachePutAll

    public abstract <K,V> GridClientFutureAdapter<Boolean> cachePutAll(String cacheName,
                                                                       Map<K,V> entries,
                                                                       Set<GridClientCacheFlag> flags,
                                                                       UUID destNodeId)
                                                                throws GridClientConnectionResetException,
                                                                       GridClientClosedException

Puts bundle of entries into cache.

Parameters:
  `cacheName` - Cache name.
  `entries` - Entries.
  `flags` - Cache flags to be enabled.
  `destNodeId` - Destination node ID.
Returns:
  `True` if map contained more then one entry or if put succeeded in case of one entry, `false` otherwise
Throws:
  `GridClientConnectionResetException` - In case of error.
  `GridClientClosedException` - If client was manually closed before request was sent over network.

#### cacheGetAll

    public abstract <K,V> GridClientFutureAdapter<Map<K,V>> cacheGetAll(String cacheName,
                                                                        Collection<K> keys,
                                                                        Set<GridClientCacheFlag> flags,
                                                                        UUID destNodeId)
                                                                 throws GridClientConnectionResetException,
                                                                        GridClientClosedException

Gets bundle of entries for specified keys from the cache.

Parameters:
  `cacheName` - Cache name.
  `keys` - Keys.
  `flags` - Cache flags to be enabled.
  `destNodeId` - Destination node ID.
Returns:
  Entries.
Throws:
  `GridClientConnectionResetException` - In case of error.
  `GridClientClosedException` - If client was manually closed before request was sent over network.

#### cacheRemoveAll

    public abstract <K> GridClientFutureAdapter<Boolean> cacheRemoveAll(String cacheName,
                                                                        Collection<K> keys,
                                                                        Set<GridClientCacheFlag> flags,
                                                                        UUID destNodeId)
                                                                 throws GridClientConnectionResetException,
                                                                        GridClientClosedException

Removes bundle of entries for specified keys from the cache.

Parameters:
  `cacheName` - Cache name.
  `keys` - Keys.
  `flags` - Cache flags to be enabled.
  `destNodeId` - Destination node ID.
Returns:
  Whether entries were actually removed
Throws:
  `GridClientConnectionResetException` - In case of error.
  `GridClientClosedException` - If client was manually closed before request was sent over network.

#### cacheReplace

    public abstract <K,V> GridClientFutureAdapter<Boolean> cacheReplace(String cacheName,
                                                                        K key,
                                                                        V val,
                                                                        Set<GridClientCacheFlag> flags,
                                                                        UUID destNodeId)
                                                                 throws GridClientConnectionResetException,
                                                                        GridClientClosedException

Replace key-value pair in cache if already exist.

Parameters:
  `cacheName` - Cache name.
  `key` - Key.
  `val` - Value.
  `flags` - Cache flags to be enabled.
  `destNodeId` - Destination node ID.
Returns:
  Whether value was actually replaced.
Throws:
  `GridClientConnectionResetException` - In case of error.
  `GridClientClosedException` - If client was manually closed before request was sent over network.

#### cacheCompareAndSet

    public abstract <K,V> GridClientFutureAdapter<Boolean> cacheCompareAndSet(String cacheName,
                                                                              K key,
                                                                              V newVal,
                                                                              V oldVal,
                                                                              Set<GridClientCacheFlag> flags,
                                                                              UUID destNodeId)
                                                                       throws GridClientConnectionResetException,
                                                                              GridClientClosedException

New value | Actual/old value | Behaviour
--- | --- | ---
null | null | Remove entry for key.
newVal | null | Put newVal into cache if such key doesn't exist.
null | oldVal | Remove if actual value oldVal is equals to value in cache.
newVal | oldVal | Replace if actual value oldVal is equals to value in cache.

Parameters:
  `cacheName` - Cache name.
  `key` - Key.
  `newVal` - Value 1.
  `oldVal` - Value 2.
  `flags` - Cache flags to be enabled.
  `destNodeId` - Destination node ID.
Returns:
  Whether new value was actually set.
Throws:
  `GridClientConnectionResetException` - In case of error.
  `GridClientClosedException` - If client was manually closed before request was sent over network.

#### cacheMetrics

    public abstract <K> GridClientFutureAdapter<GridClientDataMetrics> cacheMetrics(String cacheName,
                                                                                    UUID destNodeId)
                                                                             throws GridClientConnectionResetException,
                                                                                    GridClientClosedException

Gets cache metrics for the key.

Parameters:
  `cacheName` - Cache name.
  `destNodeId` - Destination node ID.
Returns:
  Metrics.
Throws:
  `GridClientConnectionResetException` - In case of error.
  `GridClientClosedException` - If client was manually closed before request was sent over network.

#### cacheAppend

    public abstract <K,V> GridClientFutureAdapter<Boolean> cacheAppend(String cacheName,
                                                                       K key,
                                                                       V val,
                                                                       Set<GridClientCacheFlag> flags,
                                                                       UUID destNodeId)
                                                                throws GridClientConnectionResetException,
                                                                       GridClientClosedException

Append requested value to already cached one.

Parameters:
  `cacheName` - Cache name.
  `key` - Key.
  `val` - Value to append to the cached one.
  `flags` - Cache flags to be enabled.
  `destNodeId` - Destination node ID.
Returns:
  Whether new value was actually set.
Throws:
  `GridClientConnectionResetException` - In case of error.
  `GridClientClosedException` - If client was manually closed before request was sent over network.

#### cachePrepend

    public abstract <K,V> GridClientFutureAdapter<Boolean> cachePrepend(String cacheName,
                                                                        K key,
                                                                        V val,
                                                                        Set<GridClientCacheFlag> flags,
                                                                        UUID destNodeId)
                                                                 throws GridClientConnectionResetException,
                                                                        GridClientClosedException

Prepend requested value to already cached one.

Parameters:
  `cacheName` - Cache name.
  `key` - Key.
  `val` - Value to prepend to the cached one.
  `flags` - Cache flags to be enabled.
  `destNodeId` - Destination node ID.
Returns:
  Whether new value was actually set.
Throws:
  `GridClientConnectionResetException` - In case of error.
  `GridClientClosedException` - If client was manually closed before request was sent over network.

#### execute

    public abstract <R> GridClientFutureAdapter<R> execute(String taskName,
                                                           Object arg,
                                                           UUID destNodeId,
                                                           boolean keepBinaries)
                                                    throws GridClientConnectionResetException,
                                                           GridClientClosedException

Execute task in the grid.

Parameters:
  `taskName` - Task name.
  `arg` - Task argument.
  `destNodeId` - Destination node ID.
  `keepBinaries` - Keep binary flag.
Returns:
  Task execution result.
Throws:
  `GridClientConnectionResetException` - In case of error.
  `GridClientClosedException` - If client was manually closed before request was sent over network.

#### changeState

    public abstract GridClientFuture<?> changeState(boolean active,
                                                    UUID destNodeId)
                                             throws GridClientClosedException,
                                                    GridClientConnectionResetException

Change grid global state.

Parameters:
  `active` - Active.
  `destNodeId` - Destination node id.
Throws:
  `GridClientClosedException`
  `GridClientConnectionResetException`

#### currentState

    public abstract GridClientFuture<Boolean> currentState(UUID destNodeId)
                                                    throws GridClientClosedException,
                                                           GridClientConnectionResetException

Get current grid state.

Parameters:
  `destNodeId` - Destination node id.
Throws:
  `GridClientClosedException`
  `GridClientConnectionResetException`

#### node

    public abstract GridClientFuture<GridClientNode> node(UUID id,
                                                          boolean inclAttrs,
                                                          boolean inclMetrics,
                                                          UUID destNodeId)
                                                   throws GridClientConnectionResetException,
                                                          GridClientClosedException

Gets node by node ID.

Parameters:
  `id` - Node ID.
  `inclAttrs` - Whether to include attributes.
  `inclMetrics` - Whether to include metrics.
  `destNodeId` - Destination node ID.
Returns:
  Node.
Throws:
  `GridClientConnectionResetException` - In case of error.
  `GridClientClosedException` - If client was manually closed before request was sent over network.

#### node

    public abstract GridClientFuture<GridClientNode> node(String ipAddr,
                                                          boolean inclAttrs,
                                                          boolean includeMetrics,
                                                          UUID destNodeId)
                                                   throws GridClientConnectionResetException,
                                                          GridClientClosedException

Gets node by node IP.

Parameters:
  `ipAddr` - IP address.
  `inclAttrs` - Whether to include attributes.
  `includeMetrics` - Whether to include metrics.
  `destNodeId` - Destination node ID.
Returns:
  Node.
Throws:
  `GridClientConnectionResetException` - In case of error.
  `GridClientClosedException` - If client was manually closed before request was sent over network.

#### topology

    public abstract GridClientFuture<List<GridClientNode>> topology(boolean inclAttrs,
                                                                    boolean inclMetrics,
                                                                    @Nullable
                                                                    UUID destNodeId)
                                                             throws GridClientConnectionResetException,
                                                                    GridClientClosedException

Gets grid topology nodes.

Parameters:
  `inclAttrs` - Whether to include attributes.
  `inclMetrics` - Whether to include metrics.
  `destNodeId` - Destination node ID.
Returns:
  Nodes.
Throws:
  `GridClientConnectionResetException` - In case of error.
  `GridClientClosedException` - If client was manually closed before request was sent over network.

#### forwardMessage

    public abstract GridClientFutureAdapter<?> forwardMessage(Object body)
                                                       throws GridClientException

Forwards a message in raw form to the connected node. This method supposed to be used only inside router. The exact types of acceptable arguments and return values depend on connection implementation.

Parameters:
  `body` - A raw message to send.
Returns:
  Future holding server's response.
Throws:
  `GridClientException` - If message forwarding failed.

#### isClosed

    public boolean isClosed()

Returns:
  `True` if connection is closed.

#### sslContext

    protected SSLContext sslContext()

Gets SSLContext of this client connection.

Returns:
  `SSLContext` instance.

#### credentials

    protected Object credentials()

Returns credentials for this client connection.

Returns:
  Credentials.

#### safeLong

    protected long safeLong(Map<String,Number> map,
                            String key)

Safely gets long value by given key.

Parameters:
  `map` - Map to get value from.
  `key` - Metrics name.
Returns:
  Value or -1, if not found.

#### safeDouble

    protected double safeDouble(Map<String,Number> map,
                                String key)

Safely gets double value by given key.

Parameters:
  `map` - Map to get value from.
  `key` - Metrics name.
Returns:
  Value or -1, if not found.

#### metricsMapToMetrics

    protected GridClientDataMetrics metricsMapToMetrics(Map<String,Number> metricsMap)

Converts metrics map to metrics object.

Parameters:
  `metricsMap` - Map to convert.
Returns:
  Metrics object.

#### checkClosed

    protected void checkClosed(org.apache.ignite.internal.client.impl.connection.GridClientConnectionCloseReason reason)
                        throws GridConnectionIdleClosedException,
                               GridClientConnectionResetException,
                               GridClientClosedException

Check if this connection was closed and throws appropriate exception. This method should be used for synchronous connection state check.

Parameters:
  `reason` - Close reason.
Throws:
  `GridConnectionIdleClosedException` - If connection was closed as idle.
  `GridClientClosedException` - If client was closed by by external call.
  `GridClientConnectionResetException` - If connection was closed because of failure.

#### getCloseReasonAsException

    protected GridClientException getCloseReasonAsException(org.apache.ignite.internal.client.impl.connection.GridClientConnectionCloseReason reason,
                                                            @Nullable
                                                            Throwable cause)

Build appropriate exception from the given close reason. This method should be used as a factory for exception to finish futures asynchronously.

Parameters:
  `reason` - Close reason.
  `cause` - Cause of connection close, or `null` in case of regular close.
Returns:
  Exception.

#### getCloseReasonMessage

    protected String getCloseReasonMessage(org.apache.ignite.internal.client.impl.connection.GridClientConnectionCloseReason reason,
                                           @Nullable
                                           Throwable cause)

Parameters:
  `reason` - Close reason.
  `cause` - Cause of connection close, or `null` in case of regular close.
Returns:
  Description of close reason for logging purpose.

2018 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.6.0
Release Date | : July 10 2018