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 Modifier and Type Field Description protected UUIDclientIdClient id.protected org.apache.ignite.internal.client.impl.connection.GridClientConnectionCloseReasoncloseReasonReason why connection was closed.protected GridClientTopologytopTopology
-
Constructor Summary
Constructors Modifier Constructor Description protectedGridClientConnection(UUID clientId, InetSocketAddress srvAddr, SSLContext sslCtx, GridClientTopology top, SecurityCredentials cred)Creates a facade.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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. 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.<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(ClusterState state, UUID destNodeId)Changes grid global state.abstract GridClientFuture<?>changeState(ClusterState state, UUID destNodeId, boolean forceDeactivation)Changes grid global state.protected voidcheckClosed(org.apache.ignite.internal.client.impl.connection.GridClientConnectionCloseReason reason)Check if this connection was closed and throws appropriate exception.abstract GridClientFuture<String>clusterName(UUID destNodeId)Get a cluster name.protected SecurityCredentialscredentials()Returns credentials for this client connection.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 GridClientExceptiongetCloseReasonAsException(org.apache.ignite.internal.client.impl.connection.GridClientConnectionCloseReason reason, @Nullable Throwable cause)Build appropriate exception from the given close reason.protected StringgetCloseReasonMessage(org.apache.ignite.internal.client.impl.connection.GridClientConnectionCloseReason reason, @Nullable Throwable cause)booleanisClosed()abstract GridClientFutureAdapter<?>messageBeforeStart(Object msg)Sending messages before node starts and getting a response to it.protected GridClientDataMetricsmetricsMapToMetrics(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 doublesafeDouble(Map<String,Number> map, String key)Safely gets double value by given key.protected longsafeLong(Map<String,Number> map, String key)Safely gets long value by given key.InetSocketAddressserverAddress()Gets server address this connection connected to.protected SSLContextsslContext()Gets SSLContext of this client connection.abstract GridClientFuture<ClusterState>state(UUID destNodeId)Gets current grid global state.abstract GridClientFuture<List<GridClientNode>>topology(boolean inclAttrs, boolean inclMetrics, @Nullable UUID destNodeId)Gets grid topology nodes.
-
-
-
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.nullmeans connection is still alive.
-
-
Constructor Detail
-
GridClientConnection
protected GridClientConnection(UUID clientId, InetSocketAddress srvAddr, SSLContext sslCtx, GridClientTopology top, SecurityCredentials cred)
Creates a facade.- Parameters:
clientId- Client identifier.srvAddr- Server address this connection connected to.sslCtx- SSL context to use if SSL is enabled,nullotherwise.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:
Trueif map contained more then one entry or if put succeeded in case of one entry,falseotherwise- 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(ClusterState state, UUID destNodeId) throws GridClientClosedException, GridClientConnectionResetException
Changes grid global state.- Parameters:
state- New cluster state.destNodeId- Destination node id.- Throws:
GridClientConnectionResetException- In case of error.GridClientClosedException- If client was manually closed before request was sent over network.
-
changeState
public abstract GridClientFuture<?> changeState(ClusterState state, UUID destNodeId, boolean forceDeactivation) throws GridClientClosedException, GridClientConnectionResetException
Changes grid global state.- Parameters:
state- New cluster state.destNodeId- Destination node id.forceDeactivation- Iftrue, cluster deactivation will be forced.- Throws:
GridClientConnectionResetException- In case of error.GridClientClosedException- If client was manually closed before request was sent over network.
-
state
public abstract GridClientFuture<ClusterState> state(UUID destNodeId) throws GridClientClosedException, GridClientConnectionResetException
Gets current grid global state.- Parameters:
destNodeId- Destination node id.- Throws:
GridClientConnectionResetException- In case of error.GridClientClosedException- If client was manually closed before request was sent over network.
-
clusterName
public abstract GridClientFuture<String> clusterName(UUID destNodeId) throws GridClientClosedException, GridClientConnectionResetException
Get a cluster name.- Parameters:
destNodeId- Destination node id.- Returns:
- Future to get the cluster name.
- Throws:
GridClientConnectionResetException- In case of error.GridClientClosedException- If client was manually closed before request was sent over network.
-
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 @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.
-
messageBeforeStart
public abstract GridClientFutureAdapter<?> messageBeforeStart(Object msg) throws GridClientException
Sending messages before node starts and getting a response to it.- Parameters:
msg- A raw message to send.- Returns:
- Future holding server's response.
- Throws:
GridClientException- In case of error.
-
isClosed
public boolean isClosed()
- Returns:
Trueif connection is closed.
-
sslContext
protected SSLContext sslContext()
Gets SSLContext of this client connection.- Returns:
SSLContextinstance.
-
credentials
protected SecurityCredentials 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, GridClientClosedExceptionCheck 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 @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, ornullin case of regular close.- Returns:
- Exception.
-
getCloseReasonMessage
protected String getCloseReasonMessage(org.apache.ignite.internal.client.impl.connection.GridClientConnectionCloseReason reason, @Nullable @Nullable Throwable cause)
- Parameters:
reason- Close reason.cause- Cause of connection close, ornullin case of regular close.- Returns:
- Description of close reason for logging purpose.
-
-