Class GridClientDataImpl
- java.lang.Object
-
- org.apache.ignite.internal.client.impl.GridClientDataImpl
-
- All Implemented Interfaces:
GridClientData
public class GridClientDataImpl extends Object implements GridClientData
Data projection that serves one cache instance and handles communication errors.
-
-
Field Summary
Fields Modifier and Type Field Description protected GridClientLoadBalancerbalancerBalancer to be used in this projection.protected GridClientImplclientClient instance.protected GridClientPredicate<? super GridClientNode>filterNode filter to be applied for this projection.protected Collection<GridClientNode>nodesList of nodes included in this projection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <K> UUIDaffinity(K key)Gets affinity node ID for provided key.<K,V>
booleanappend(K key, V val)Append requested value to already cached one.<K,V>
GridClientFuture<Boolean>appendAsync(K key, V val)Append requested value to already cached one.GridClientDataMetricscachedMetrics()Tries to get metrics from local cache.StringcacheName()Gets name of the remote cache.<K,V>
booleancas(K key, V val1, V val2)Sets entry value toval1if current value isval2with following conditions: Ifval1isnullandval2is equal to current value, entry is removed from cache.<K,V>
GridClientFuture<Boolean>casAsync(K key, V val1, V val2)Asynchronously sets entry value toval1if current value isval2with following conditions: Ifval1isnullandval2is equal to current value, entry is removed from cache.protected booleancheckNodeAlive(UUID nodeId)Tries to refresh node on every possible connection in topology.protected TcreateProjection(@Nullable Collection<GridClientNode> nodes, @Nullable GridClientPredicate<? super GridClientNode> filter, @Nullable GridClientLoadBalancer balancer, org.apache.ignite.internal.client.impl.GridClientAbstractProjection.ProjectionFactory<T> factory)Creates a sub-projection for current projection.Set<GridClientCacheFlag>flags()Gets cache flags enabled on this data projection.GridClientDataflagsOff(GridClientCacheFlag... flags)Creates new client data object with disabled cache flags.GridClientDataflagsOn(GridClientCacheFlag... flags)Creates new client data object with enabled cache flags.<K,V>
Vget(K key)Gets value from cache on remote node.<K,V>
Map<K,V>getAll(Collection<K> keys)Gets entries from cache on remote grid.<K,V>
GridClientFuture<Map<K,V>>getAllAsync(Collection<K> keys)Asynchronously gets entries from cache on remote grid.<K,V>
GridClientFuture<V>getAsync(K key)Asynchronously gets value from cache on remote grid.GridClientDataMetricsmetrics()Fetches metrics for cache from remote grid.GridClientFuture<GridClientDataMetrics>metricsAsync()Asynchronously fetches metrics for cache from remote grid.Collection<GridClientNode>pinnedNodes()Gets pinned node ornullif no nodes were pinned.GridClientDatapinNodes(GridClientNode node, GridClientNode... nodes)Gets client data projection which will only contact specified remote grid node.<K,V>
booleanprepend(K key, V val)Prepend requested value to already cached one.<K,V>
GridClientFuture<Boolean>prependAsync(K key, V val)Prepend requested value to already cached one.Collection<? extends GridClientNode>projectionNodes()Gets most recently refreshed topology.protected Collection<? extends GridClientNode>projectionNodes(@Nullable GridClientPredicate<GridClientNode> pred)Gets most recently refreshed topology.<K,V>
booleanput(K key, V val)Puts value to cache on remote grid.<K,V>
voidputAll(Map<K,V> entries)Puts entries to cache on remote grid.<K,V>
GridClientFuture<?>putAllAsync(Map<K,V> entries)Asynchronously puts entries to cache on remote grid.<K,V>
GridClientFuture<Boolean>putAsync(K key, V val)Asynchronously puts value to cache on remote node.<K> booleanremove(K key)Removes value from cache on remote node.<K> voidremoveAll(Collection<K> keys)Removes entries from cache on remote node.<K> GridClientFuture<?>removeAllAsync(Collection<K> keys)Asynchronously removes entries from cache on remote grid.<K> GridClientFuture<Boolean>removeAsync(K key)Asynchronously removes value from cache on remote grid.<K,V>
booleanreplace(K key, V val)Replaces value in cache on remote grid only if there was anon-nullvalue associated with this key.<K,V>
GridClientFuture<Boolean>replaceAsync(K key, V val)Asynchronously replaces value in cache on remote grid only if there was anon-nullvalue associated with this key.protected <R> GridClientFuture<R>withReconnectHandling(org.apache.ignite.internal.client.impl.GridClientAbstractProjection.ClientProjectionClosure<R> c)This method executes request to a communication layer and handles connection error, if it occurs.protected <R> GridClientFuture<R>withReconnectHandling(org.apache.ignite.internal.client.impl.GridClientAbstractProjection.ClientProjectionClosure<R> c, String cacheName, @Nullable Object affKey)This method executes request to a communication layer and handles connection error, if it occurs.
-
-
-
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.
-
-
Method Detail
-
cacheName
public String cacheName()
Gets name of the remote cache. The cache name for this projection was specified viaGridClient.data(String)method at the time of creation.- Specified by:
cacheNamein interfaceGridClientData- Returns:
- Name of the remote cache.
-
pinNodes
public GridClientData pinNodes(GridClientNode node, GridClientNode... nodes) throws GridClientException
Gets client data projection which will only contact specified remote grid node. By default, remote node is determined based onGridClientDataAffinityprovided - this method allows to override default behavior and use only specified server for all cache operations.Use this method when there are other than
key-affinityreasons why a certain node should be contacted.- Specified by:
pinNodesin interfaceGridClientData- Parameters:
node- Node to be contacted (optional).nodes- Additional nodes (optional).- Returns:
- Client data which will only contact server with given node ID.
- Throws:
GridClientException- If resulting projection is empty.
-
pinnedNodes
public Collection<GridClientNode> pinnedNodes()
Gets pinned node ornullif no nodes were pinned.- Specified by:
pinnedNodesin interfaceGridClientData- Returns:
- Pinned node.
-
put
public <K,V> boolean put(K key, V val) throws GridClientExceptionPuts value to cache on remote grid.Note that this operation is affinity-aware and will immediately contact exactly the remote node on which this key is supposed to be cached (unless some nodes were
pinned).- Specified by:
putin interfaceGridClientData- Parameters:
key- Key to put in cache.val- Value to put in cache.- Returns:
- Whether value was actually put to cache.
- Throws:
GridClientException- In case of error.GridServerUnreachableException- If none of the servers can be reached.GridClientClosedException- If client was closed manually.
-
putAsync
public <K,V> GridClientFuture<Boolean> putAsync(K key, V val)
Asynchronously puts value to cache on remote node.Note that this operation is affinity-aware and will immediately contact exactly the remote node on which this key is supposed to be cached (unless some nodes were
pinned).- Specified by:
putAsyncin interfaceGridClientData- Parameters:
key- Key to put in cache.val- Value to put in cache.- Returns:
- Future whether value was actually put to cache.
-
putAll
public <K,V> void putAll(Map<K,V> entries) throws GridClientException
Puts entries to cache on remote grid.Note that this operation is affinity-aware and will immediately contact exactly the remote nodes on which these keys are supposed to be cached (unless some nodes were
pinned). If entries do not map to one node, then the node which has most mapped entries will be contacted.- Specified by:
putAllin interfaceGridClientData- Parameters:
entries- Entries to put in cache.- Throws:
GridClientException- In case of error.GridServerUnreachableException- If none of the servers can be reached.GridClientClosedException- If client was closed manually.
-
putAllAsync
public <K,V> GridClientFuture<?> putAllAsync(Map<K,V> entries)
Asynchronously puts entries to cache on remote grid.Note that this operation is affinity-aware and will immediately contact exactly the remote nodes on which these keys are supposed to be cached (unless some nodes were
pinned). If entries do not map to one node, then the node which has most mapped entries will be contacted.- Specified by:
putAllAsyncin interfaceGridClientData- Parameters:
entries- Entries to put in cache.- Returns:
- Future whether this operation completes.
-
get
public <K,V> V get(K key) throws GridClientExceptionGets value from cache on remote node.Note that this operation is affinity-aware and will immediately contact exactly the remote node on which this key is supposed to be cached (unless some nodes were
pinned).- Specified by:
getin interfaceGridClientData- Parameters:
key- Key to get from cache.- Returns:
- Value for given key or
nullif no value was cached. - Throws:
GridClientException- In case of error.GridServerUnreachableException- If none of the servers can be reached.GridClientClosedException- If client was closed manually.
-
getAsync
public <K,V> GridClientFuture<V> getAsync(K key)
Asynchronously gets value from cache on remote grid.Note that this operation is affinity-aware and will immediately contact exactly the remote node on which this key is supposed to be cached (unless some nodes were
pinned).- Specified by:
getAsyncin interfaceGridClientData- Parameters:
key- Key to get from cache.- Returns:
- Future with value for given key or with
nullif no value was cached.
-
getAll
public <K,V> Map<K,V> getAll(Collection<K> keys) throws GridClientException
Gets entries from cache on remote grid.Note that this operation is affinity-aware and will immediately contact exactly the remote nodes on which these keys are supposed to be cached (unless some nodes were
pinned). If entries do not map to one node, then the node which has most mapped entries will be contacted.- Specified by:
getAllin interfaceGridClientData- Parameters:
keys- Keys to get.- Returns:
- Entries retrieved from remote cache nodes.
- Throws:
GridClientException- In case of error.GridServerUnreachableException- If none of the servers can be reached.GridClientClosedException- If client was closed manually.
-
getAllAsync
public <K,V> GridClientFuture<Map<K,V>> getAllAsync(Collection<K> keys)
Asynchronously gets entries from cache on remote grid.Note that this operation is affinity-aware and will immediately contact exactly the remote nodes on which these keys are supposed to be cached (unless some nodes were
pinned). If entries do not map to one node, then the node which has most mapped entries will be contacted.- Specified by:
getAllAsyncin interfaceGridClientData- Parameters:
keys- Keys to get.- Returns:
- Future with entries retrieved from remote cache nodes.
-
remove
public <K> boolean remove(K key) throws GridClientExceptionRemoves value from cache on remote node.Note that this operation is affinity-aware and will immediately contact exactly the remote node on which this key is supposed to be cached (unless some nodes were
pinned).- Specified by:
removein interfaceGridClientData- Parameters:
key- Key to remove.- Returns:
- Whether value was actually removed.
- Throws:
GridClientException- In case of error.GridServerUnreachableException- If none of the servers can be reached.GridClientClosedException- If client was closed manually.
-
removeAsync
public <K> GridClientFuture<Boolean> removeAsync(K key)
Asynchronously removes value from cache on remote grid.Note that this operation is affinity-aware and will immediately contact exactly the remote node on which this key is supposed to be cached (unless some nodes were
pinned).- Specified by:
removeAsyncin interfaceGridClientData- Parameters:
key- Key to remove.- Returns:
- Future whether value was actually removed.
-
removeAll
public <K> void removeAll(Collection<K> keys) throws GridClientException
Removes entries from cache on remote node.Note that this operation is affinity-aware and will immediately contact exactly the remote nodes on which these keys are supposed to be cached (unless some nodes were
pinned). If entries do not map to one node, then the node which has most mapped entries will be contacted.- Specified by:
removeAllin interfaceGridClientData- Parameters:
keys- Keys to remove.- Throws:
GridClientException- In case of error.GridServerUnreachableException- If none of the servers can be reached.GridClientClosedException- If client was closed manually.
-
removeAllAsync
public <K> GridClientFuture<?> removeAllAsync(Collection<K> keys)
Asynchronously removes entries from cache on remote grid.Note that this operation is affinity-aware and will immediately contact exactly the remote nodes on which these keys are supposed to be cached (unless some nodes were
pinned). If entries do not map to one node, then the node which has most mapped entries will be contacted.- Specified by:
removeAllAsyncin interfaceGridClientData- Parameters:
keys- Keys to remove.- Returns:
- Future whether operation finishes.
-
replace
public <K,V> boolean replace(K key, V val) throws GridClientExceptionReplaces value in cache on remote grid only if there was anon-nullvalue associated with this key.Note that this operation is affinity-aware and will immediately contact exactly the remote node on which this key is supposed to be cached (unless some nodes were
pinned).- Specified by:
replacein interfaceGridClientData- Parameters:
key- Key to replace.val- Value to replace.- Returns:
- Whether value was actually replaced.
- Throws:
GridClientException- In case of error.GridServerUnreachableException- If none of the servers can be reached.GridClientClosedException- If client was closed manually.
-
replaceAsync
public <K,V> GridClientFuture<Boolean> replaceAsync(K key, V val)
Asynchronously replaces value in cache on remote grid only if there was anon-nullvalue associated with this key.Note that this operation is affinity-aware and will immediately contact exactly the remote node on which this key is supposed to be cached (unless some nodes were
pinned).- Specified by:
replaceAsyncin interfaceGridClientData- Parameters:
key- Key to replace.val- Value to replace.- Returns:
- Future whether value was actually replaced.
-
cas
public <K,V> boolean cas(K key, V val1, V val2) throws GridClientExceptionSets entry value toval1if current value isval2with following conditions:-
If
val1isnullandval2is equal to current value, entry is removed from cache. -
If
val2isnull, entry is created if it doesn't exist. -
If both
val1andval2arenull, entry is removed.
pinned).- Specified by:
casin interfaceGridClientData- Parameters:
key- Key to set.val1- Value to set.val2- Check value.- Returns:
- Whether value of entry was changed.
- Throws:
GridClientException- In case of error.GridServerUnreachableException- If none of the servers can be reached.GridClientClosedException- If client was closed manually.
-
If
-
casAsync
public <K,V> GridClientFuture<Boolean> casAsync(K key, V val1, V val2)
Asynchronously sets entry value toval1if current value isval2with following conditions:-
If
val1isnullandval2is equal to current value, entry is removed from cache. -
If
val2isnull, entry is created if it doesn't exist. -
If both
val1andval2arenull, entry is removed.
pinned).- Specified by:
casAsyncin interfaceGridClientData- Parameters:
key- Key to set.val1- Value to set.val2- Check value.- Returns:
- Future whether value of entry was changed.
-
If
-
affinity
public <K> UUID affinity(K key) throws GridClientException
Gets affinity node ID for provided key. This method will returnnullif no affinity was configured for the given cache for this client or there are no nodes in topology with cache enabled.- Specified by:
affinityin interfaceGridClientData- Parameters:
key- Key.- Returns:
- Node ID.
- Throws:
GridClientException- In case of error.
-
metrics
public GridClientDataMetrics metrics() throws GridClientException
Fetches metrics for cache from remote grid.- Specified by:
metricsin interfaceGridClientData- Returns:
- Cache metrics.
- Throws:
GridClientException- In case of error.GridServerUnreachableException- If none of the servers can be reached.GridClientClosedException- If client was closed manually.
-
metricsAsync
public GridClientFuture<GridClientDataMetrics> metricsAsync()
Asynchronously fetches metrics for cache from remote grid.- Specified by:
metricsAsyncin interfaceGridClientData- Returns:
- Future with cache metrics.
-
cachedMetrics
public GridClientDataMetrics cachedMetrics() throws GridClientException
Tries to get metrics from local cache.Local cache is updated on every
GridClientData.metrics()orGridClientData.metricsAsync()call ifGridClientConfiguration.isEnableMetricsCache()is enabled. If it is disabled then this method will always returnnull.- Specified by:
cachedMetricsin interfaceGridClientData- Returns:
- Cached metrics or
nullif no cached metrics available. - Throws:
GridClientException- In case of error.GridServerUnreachableException- If none of the servers can be reached.GridClientClosedException- If client was closed manually.
-
append
public <K,V> boolean append(K key, V val) throws GridClientExceptionAppend requested value to already cached one. This method supports work with strings, lists and maps.Note that this operation is affinity-aware and will immediately contact exactly the remote node on which this key is supposed to be cached (unless some nodes were
pinned).- Specified by:
appendin interfaceGridClientData- Parameters:
key- Key to manipulate cache value for.val- Value to append to the cached one.- Returns:
- Whether value of entry was changed.
- Throws:
GridClientException- In case of error.
-
appendAsync
public <K,V> GridClientFuture<Boolean> appendAsync(K key, V val) throws GridClientException
Append requested value to already cached one. This method supports work with strings, lists and maps.Note that this operation is affinity-aware and will immediately contact exactly the remote node on which this key is supposed to be cached (unless some nodes were
pinned).- Specified by:
appendAsyncin interfaceGridClientData- Parameters:
key- Key to manipulate cache value for.val- Value to append to the cached one.- Returns:
- Future whether value of entry was changed.
- Throws:
GridClientException- In case of error.
-
prepend
public <K,V> boolean prepend(K key, V val) throws GridClientExceptionPrepend requested value to already cached one. This method supports work with strings, lists and maps.Note that this operation is affinity-aware and will immediately contact exactly the remote node on which this key is supposed to be cached (unless some nodes were
pinned).- Specified by:
prependin interfaceGridClientData- Parameters:
key- Key to manipulate cache value for.val- Value to prepend to the cached one.- Returns:
- Whether value of entry was changed.
- Throws:
GridClientException- In case of error.
-
prependAsync
public <K,V> GridClientFuture<Boolean> prependAsync(K key, V val) throws GridClientException
Prepend requested value to already cached one. This method supports work with strings, lists and maps.Note that this operation is affinity-aware and will immediately contact exactly the remote node on which this key is supposed to be cached (unless some nodes were
pinned).- Specified by:
prependAsyncin interfaceGridClientData- Parameters:
key- Key to manipulate cache value for.val- Value to prepend to the cached one.- Returns:
- Future whether value of entry was changed.
- Throws:
GridClientException- In case of error.
-
flags
public Set<GridClientCacheFlag> flags()
Gets cache flags enabled on this data projection.- Specified by:
flagsin interfaceGridClientData- Returns:
- Flags for this data projection (empty set if no flags have been set).
-
flagsOn
public GridClientData flagsOn(GridClientCacheFlag... flags) throws GridClientException
Creates new client data object with enabled cache flags.- Specified by:
flagsOnin interfaceGridClientData- Parameters:
flags- Optional cache flags to be enabled.- Returns:
- New client data object.
- Throws:
GridClientException- In case of error.
-
flagsOff
public GridClientData flagsOff(GridClientCacheFlag... flags) throws GridClientException
Creates new client data object with disabled cache flags.- Specified by:
flagsOffin interfaceGridClientData- Parameters:
flags- Cache flags to be disabled.- Returns:
- New client data object.
- Throws:
GridClientException- In case of error.
-
withReconnectHandling
protected <R> GridClientFuture<R> withReconnectHandling(org.apache.ignite.internal.client.impl.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(org.apache.ignite.internal.client.impl.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:
Trueif response was received,falseif eithernullresponse 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, ifnulljust 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, org.apache.ignite.internal.client.impl.GridClientAbstractProjection.ProjectionFactory<T> factory) throws GridClientExceptionCreates a sub-projection for current projection.- Parameters:
nodes- Collection of nodes that sub-projection will be restricted to. Ifnull, created projection is dynamic and will take nodes from topology.filter- Filter to be applied to nodes in projection. Ifnull- no filter applied.balancer- Balancer to use in projection. Ifnull- 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.
-
-