org.apache.ignite.internal

## Class IgniteClusterAsyncImpl

- java.lang.Object
- - org.apache.ignite.internal.AsyncSupportAdapter<IgniteCluster>
  - - org.apache.ignite.internal.IgniteClusterAsyncImpl

All Implemented Interfaces:
  ClusterGroup, IgniteCluster, IgniteAsyncSupport

    public class IgniteClusterAsyncImpl
    extends AsyncSupportAdapter<IgniteCluster>
    implements IgniteCluster

### Field Summary

### Fields inherited from class org.apache.ignite.internal.AsyncSupportAdapter

`curFut`

### Constructor Summary

Constructors
Constructor and Description
`IgniteClusterAsyncImpl(IgniteKernal grid)`

### Method Summary

Methods
`ClusterGroup` `forAttribute(String name, String val)` Creates projection for nodes containing given name and value specified in user attributes.
`ClusterGroup` `forCacheNodes(String cacheName)` Creates projection for all nodes that have cache with specified name running.
`ClusterGroup` `forClientNodes(String cacheName)` Creates projection for all nodes that have cache with specified name running and cache distribution mode is `CacheDistributionMode.CLIENT_ONLY` or `CacheDistributionMode.NEAR_ONLY`.
`ClusterGroup` `forDaemons()` Gets projection consisting from the daemon nodes in this projection.
`ClusterGroup` `forDataNodes(String cacheName)` Creates projection for all nodes that have cache with specified name running and cache distribution mode is `CacheDistributionMode.PARTITIONED_ONLY` or `CacheDistributionMode.NEAR_PARTITIONED`.
`ClusterGroup` `forHost(ClusterNode node)` Gets grid projection consisting from the nodes in this projection residing on the same host as given node.
`ClusterGroup` `forLocal()` Gets monadic projection consisting from the local node.
`ClusterGroup` `forNode(ClusterNode node, ClusterNode... nodes)` Creates a grid projection for the given node.
`ClusterGroup` `forNodeId(UUID id, UUID... ids)` Creates a grid projection for a node with specified ID.
`ClusterGroup` `forNodeIds(Collection<UUID> ids)` Creates a grid projection over nodes with specified node IDs.
`ClusterGroup` `forNodes(Collection<? extends ClusterNode> nodes)` Creates a grid projection over a given set of nodes.
`ClusterGroup` `forOldest()` Creates grid projection with one oldest node in the current projection.
`ClusterGroup` `forOthers(ClusterGroup prj)` Creates a grid projection for nodes not included into given projection.
`ClusterGroup` `forOthers(ClusterNode node, ClusterNode... nodes)` Creates a grid projection for nodes other than given nodes.
`ClusterGroup` `forPredicate(IgnitePredicate<ClusterNode> p)` Creates a grid projection which includes all nodes that pass the given predicate filter.
`ClusterGroup` `forRandom()` Creates grid projection with one random node from current projection.
`ClusterGroup` `forRemotes()` Gets grid projection consisting from the nodes in this projection excluding the local node.
`ClusterGroup` `forStreamer(String streamerName, String... streamerNames)` Creates projection for all nodes that have streamer with specified name running.
`ClusterGroup` `forYoungest()` Creates grid projection with one youngest node in the current projection.
`Ignite` `ignite()` Gets instance of grid.
`ClusterNode` `localNode()` Gets local grid node.
`<K> Map<ClusterNode,Collection<K>>` `mapKeysToNodes(String cacheName, Collection<? extends K> keys)` This method provides ability to detect which cache keys are mapped to which nodes on cache instance with given name.
`<K> ClusterNode` `mapKeyToNode(String cacheName, K key)` This method provides ability to detect which cache keys are mapped to which nodes on cache instance with given name.
`ClusterMetrics` `metrics()` Gets a metrics snapshot for this projection.
`ClusterNode` `node()` Gets first node from the list of nodes in this projection.
`ClusterNode` `node(UUID id)` Gets a node for given ID from this grid projection.
`<K,V> ClusterNodeLocalMap<K,V>` `nodeLocalMap()` Gets node-local storage instance.
`Collection<ClusterNode>` `nodes()` Gets read-only collections of nodes in this projection.
`boolean` `pingNode(UUID nodeId)` Pings a remote node.
`IgnitePredicate<ClusterNode>` `predicate()` Gets predicate that defines a subset of nodes for this projection.
`void` `resetMetrics()` Resets local I/O, job, and task execution metrics.
`void` `restartNodes()` Restarts nodes satisfying optional set of predicates.
`void` `restartNodes(Collection<UUID> ids)` Restarts nodes defined by provided IDs.
`Collection<GridTuple3<String,Boolean,String>>` `startNodes(Collection<Map<String,Object>> hosts, Map<String,Object> dflts, boolean restart, int timeout, int maxConn)` Starts one or more nodes on remote host(s).
`Collection<GridTuple3<String,Boolean,String>>` `startNodes(File file, boolean restart, int timeout, int maxConn)` Starts one or more nodes on remote host(s).
`void` `stopNodes()` Stops nodes satisfying optional set of predicates.
`void` `stopNodes(Collection<UUID> ids)` Stops nodes defined by provided IDs.
`Collection<ClusterNode>` `topology(long topVer)` Gets a topology by version.
`long` `topologyVersion()` Gets current topology version.

### Methods inherited from class org.apache.ignite.internal.AsyncSupportAdapter

`createAsyncInstance, createFuture, future, isAsync, saveOrGet, withAsync`

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

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

### Methods inherited from interface org.apache.ignite.IgniteCluster

`withAsync`

### Methods inherited from interface org.apache.ignite.lang.IgniteAsyncSupport

`future, isAsync`

### Constructor Detail

#### IgniteClusterAsyncImpl

    public IgniteClusterAsyncImpl(IgniteKernal grid)

Parameters:
  `grid` - Grid.

### Method Detail

#### localNode

    public ClusterNode localNode()

Gets local grid node.

Specified by:
  `localNode` in interface `IgniteCluster`
Returns:
  Local grid node.

#### forLocal

    public ClusterGroup forLocal()

Gets monadic projection consisting from the local node.

Specified by:
  `forLocal` in interface `IgniteCluster`
Returns:
  Monadic projection consisting from the local node.

#### nodeLocalMap

    public <K,V> ClusterNodeLocalMap<K,V> nodeLocalMap()

Gets node-local storage instance.

Node-local values are similar to thread locals in a way that these values are not distributed and kept only on local node (similar like thread local values are attached to the current thread only). Node-local values are used primarily by closures executed from the remote nodes to keep intermediate state on the local node between executions.

There's only one instance of node local storage per local node. Node local storage is based on `ConcurrentMap` and is safe for multi-threaded access.

Specified by:
  `nodeLocalMap` in interface `IgniteCluster`
Returns:
  Node local storage instance for the local node.

#### pingNode

    public boolean pingNode(UUID nodeId)

Pings a remote node.

Discovery SPIs usually have some latency in discovering failed nodes. Hence, communication to remote nodes may fail at times if an attempt was made to establish communication with a failed node. This method can be used to check if communication has failed due to node failure or due to some other reason.

Specified by:
  `pingNode` in interface `IgniteCluster`
Parameters:
  `nodeId` - ID of a node to ping.
Returns:
  `true` if node for a given ID is alive, `false` otherwise.
See Also:
  `DiscoverySpi`

#### topologyVersion

    public long topologyVersion()

Gets current topology version. In case of TCP discovery (see `TcpDiscoverySpi`) topology versions are sequential - they start from `'1'` and get incremented every time whenever a node joins or leaves. For other discovery SPIs topology versions may not be (and likely are not) sequential.

Specified by:
  `topologyVersion` in interface `IgniteCluster`
Returns:
  Current topology version.

#### topology

    @Nullable
    public Collection<ClusterNode> topology(long topVer)

Gets a topology by version. Returns `null` if topology history storage doesn't contain specified topology version (history currently keeps last `1000` snapshots).

Specified by:
  `topology` in interface `IgniteCluster`
Parameters:
  `topVer` - Topology version.
Returns:
  Collection of grid nodes which represented by specified topology version, if it is present in history storage, `null` otherwise.

#### mapKeysToNodes

    public <K> Map<ClusterNode,Collection<K>> mapKeysToNodes(@Nullable
                                                    String cacheName,
                                                    @Nullable
                                                    Collection<? extends K> keys)

This method provides ability to detect which cache keys are mapped to which nodes on cache instance with given name. Use it to determine which nodes are storing which keys prior to sending jobs that access these keys.

This method works as following:

- For local caches it returns only local node mapped to all keys.
- For fully replicated caches, `CacheAffinityFunction` is used to determine which keys are mapped to which groups of nodes.
- For partitioned caches, the returned map represents node-to-key affinity.

Specified by:
  `mapKeysToNodes` in interface `IgniteCluster`
Parameters:
  `cacheName` - Cache name, if `null`, then default cache instance is used.
  `keys` - Cache keys to map to nodes.
Returns:
  Map of nodes to cache keys or empty map if there are no alive nodes for this cache.

#### mapKeyToNode

    @Nullable
    public <K> ClusterNode mapKeyToNode(@Nullable
                                        String cacheName,
                                        K key)

This method provides ability to detect which cache keys are mapped to which nodes on cache instance with given name. Use it to determine which nodes are storing which keys prior to sending jobs that access these keys.

This method works as following:

- For local caches it returns only local node ID.
- For fully replicated caches first node ID returned by `CacheAffinityFunction` is returned.
- For partitioned caches, the returned node ID is the primary node for the key.

Specified by:
  `mapKeyToNode` in interface `IgniteCluster`
Parameters:
  `cacheName` - Cache name, if `null`, then default cache instance is used.
  `key` - Cache key to map to a node.
Returns:
  Primary node for the key or `null` if cache with given name is not present in the grid.

#### startNodes

    public Collection<GridTuple3<String,Boolean,String>> startNodes(File file,
                                                           boolean restart,
                                                           int timeout,
                                                           int maxConn)

Starts one or more nodes on remote host(s).

This method takes INI file which defines all startup parameters. It can contain one or more sections, each for a host or for range of hosts (note that they must have different names) and a special '`defaults`' section with default values. They are applied to undefined parameters in host's sections.

Returned result is collection of tuples. Each tuple corresponds to one node start attempt and contains hostname, success flag and error message if attempt was not successful. Note that successful attempt doesn't mean that node was actually started and joined topology. For large topologies (> 100s nodes) it can take over 10 minutes for all nodes to start. See individual node logs for details.

Supports asynchronous execution (see `IgniteAsyncSupport`).

Specified by:
  `startNodes` in interface `IgniteCluster`
Parameters:
  `file` - Configuration file.
  `restart` - Whether to stop existing nodes. If `true`, all existing nodes on the host will be stopped before starting new ones. If `false`, nodes will be started only if there are less nodes on the host than expected.
  `timeout` - Connection timeout.
  `maxConn` - Number of parallel SSH connections to one host.
Returns:
  Collection of tuples, each containing host name, result (success of failure) and error message (if any).

#### startNodes

    public Collection<GridTuple3<String,Boolean,String>> startNodes(Collection<Map<String,Object>> hosts,
                                                           @Nullable
                                                           Map<String,Object> dflts,
                                                           boolean restart,
                                                           int timeout,
                                                           int maxConn)

Starts one or more nodes on remote host(s).

Each map in `hosts` collection defines startup parameters for one host or for a range of hosts. The following parameters are supported:

Name | Type | Description
--- | --- | ---
host | String | Hostname (required). Can define several hosts if their IPs are sequential. E.g., `10.0.0.1~5` defines range of five IP addresses. Other parameters are applied to all hosts equally.
port | Integer | Port number (default is `22`).
uname | String | Username (if not defined, current local username will be used).
passwd | String | Password (if not defined, private key file must be defined).
key | File | Private key file (if not defined, password must be defined).
nodes | Integer | Expected number of nodes on the host. If some nodes are started already, then only remaining nodes will be started. If current count of nodes is equal to this number, and `restart` flag is `false`, then nothing will happen.
igniteHome | String | Path to Ignite installation folder. If not defined, IGNITE_HOME environment variable must be set on remote hosts.
cfg | String | Path to configuration file (relative to `igniteHome`).
script | String | Custom startup script file name and path (relative to `igniteHome`). You can also specify a space-separated list of parameters in the same string (for example: `"bin/my-custom-script.sh -v"`).

`dflts` map defines default values. They are applied to undefined parameters in `hosts` collection.

Returned result is collection of tuples. Each tuple corresponds to one node start attempt and contains hostname, success flag and error message if attempt was not successful. Note that successful attempt doesn't mean that node was actually started and joined topology. For large topologies (> 100s nodes) it can take over 10 minutes for all nodes to start. See individual node logs for details.

Supports asynchronous execution (see `IgniteAsyncSupport`).

Specified by:
  `startNodes` in interface `IgniteCluster`
Parameters:
  `hosts` - Startup parameters.
  `dflts` - Default values.
  `restart` - Whether to stop existing nodes. If `true`, all existing nodes on the host will be stopped before starting new ones. If `false`, nodes will be started only if there are less nodes on the host than expected.
  `timeout` - Connection timeout in milliseconds.
  `maxConn` - Number of parallel SSH connections to one host.
Returns:
  Collection of tuples, each containing host name, result (success of failure) and error message (if any).

#### stopNodes

    public void stopNodes()

Stops nodes satisfying optional set of predicates.

NOTE: `System.exit(Ignition.KILL_EXIT_CODE)` will be executed on each stopping node. If you have other applications running in the same JVM along with Ignition, those applications will be stopped as well.

Specified by:
  `stopNodes` in interface `IgniteCluster`

#### stopNodes

    public void stopNodes(Collection<UUID> ids)

Stops nodes defined by provided IDs.

NOTE: `System.exit(Ignition.KILL_EXIT_CODE)` will be executed on each stopping node. If you have other applications running in the same JVM along with Ignition, those applications will be stopped as well.

Specified by:
  `stopNodes` in interface `IgniteCluster`
Parameters:
  `ids` - IDs defining nodes to stop.

#### restartNodes

    public void restartNodes()

Restarts nodes satisfying optional set of predicates.

NOTE: this command only works for grid nodes started with Ignition `ignite.sh` or `ignite.bat` scripts.

Specified by:
  `restartNodes` in interface `IgniteCluster`

#### restartNodes

    public void restartNodes(Collection<UUID> ids)

Restarts nodes defined by provided IDs.

NOTE: this command only works for grid nodes started with Ignition `ignite.sh` or `ignite.bat` scripts.

Specified by:
  `restartNodes` in interface `IgniteCluster`
Parameters:
  `ids` - IDs defining nodes to restart.

#### resetMetrics

    public void resetMetrics()

Resets local I/O, job, and task execution metrics.

Specified by:
  `resetMetrics` in interface `IgniteCluster`

#### ignite

    public Ignite ignite()

Gets instance of grid.

Specified by:
  `ignite` in interface `ClusterGroup`
Returns:
  Grid instance.

#### forNodes

    public ClusterGroup forNodes(Collection<? extends ClusterNode> nodes)

Creates a grid projection over a given set of nodes.

Specified by:
  `forNodes` in interface `ClusterGroup`
Parameters:
  `nodes` - Collection of nodes to create a projection from.
Returns:
  Projection over provided grid nodes.

#### forNode

    public ClusterGroup forNode(ClusterNode node,
                       ClusterNode... nodes)

Creates a grid projection for the given node.

Specified by:
  `forNode` in interface `ClusterGroup`
Parameters:
  `node` - Node to get projection for.
  `nodes` - Optional additional nodes to include into projection.
Returns:
  Grid projection for the given node.

#### forOthers

    public ClusterGroup forOthers(ClusterNode node,
                         ClusterNode... nodes)

Creates a grid projection for nodes other than given nodes.

Specified by:
  `forOthers` in interface `ClusterGroup`
Parameters:
  `node` - Node to exclude from new grid projection.
  `nodes` - Optional additional nodes to exclude from projection.
Returns:
  Projection that will contain all nodes that original projection contained excluding given nodes.

#### forOthers

    public ClusterGroup forOthers(ClusterGroup prj)

Creates a grid projection for nodes not included into given projection.

Specified by:
  `forOthers` in interface `ClusterGroup`
Parameters:
  `prj` - Projection to exclude from new grid projection.
Returns:
  Projection for nodes not included into given projection.

#### forNodeIds

    public ClusterGroup forNodeIds(Collection<UUID> ids)

Creates a grid projection over nodes with specified node IDs.

Specified by:
  `forNodeIds` in interface `ClusterGroup`
Parameters:
  `ids` - Collection of node IDs.
Returns:
  Projection over nodes with specified node IDs.

#### forNodeId

    public ClusterGroup forNodeId(UUID id,
                         UUID... ids)

Creates a grid projection for a node with specified ID.

Specified by:
  `forNodeId` in interface `ClusterGroup`
Parameters:
  `id` - Node ID to get projection for.
  `ids` - Optional additional node IDs to include into projection.
Returns:
  Projection over node with specified node ID.

#### forPredicate

    public ClusterGroup forPredicate(IgnitePredicate<ClusterNode> p)

Creates a grid projection which includes all nodes that pass the given predicate filter.

Specified by:
  `forPredicate` in interface `ClusterGroup`
Parameters:
  `p` - Predicate filter for nodes to include into this projection.
Returns:
  Grid projection for nodes that passed the predicate filter.

#### forAttribute

    public ClusterGroup forAttribute(String name,
                            @Nullable
                            String val)

Creates projection for nodes containing given name and value specified in user attributes.

User attributes for every node are optional and can be specified in grid node configuration. See `IgniteConfiguration.getUserAttributes()` for more information.

Specified by:
  `forAttribute` in interface `ClusterGroup`
Parameters:
  `name` - Name of the attribute.
  `val` - Optional attribute value to match.
Returns:
  Grid projection for nodes containing specified attribute.

#### forCacheNodes

    public ClusterGroup forCacheNodes(String cacheName)

Creates projection for all nodes that have cache with specified name running.

Specified by:
  `forCacheNodes` in interface `ClusterGroup`
Parameters:
  `cacheName` - Cache name.
Returns:
  Projection over nodes that have specified cache running.

#### forDataNodes

    public ClusterGroup forDataNodes(String cacheName)

Creates projection for all nodes that have cache with specified name running and cache distribution mode is `CacheDistributionMode.PARTITIONED_ONLY` or `CacheDistributionMode.NEAR_PARTITIONED`.

Specified by:
  `forDataNodes` in interface `ClusterGroup`
Parameters:
  `cacheName` - Cache name.
Returns:
  Projection over nodes that have specified cache running.
See Also:
  `CacheConfiguration.getDistributionMode()`

#### forClientNodes

    public ClusterGroup forClientNodes(String cacheName)

Creates projection for all nodes that have cache with specified name running and cache distribution mode is `CacheDistributionMode.CLIENT_ONLY` or `CacheDistributionMode.NEAR_ONLY`.

Specified by:
  `forClientNodes` in interface `ClusterGroup`
Parameters:
  `cacheName` - Cache name.
Returns:
  Projection over nodes that have specified cache running.
See Also:
  `CacheConfiguration.getDistributionMode()`

#### forStreamer

    public ClusterGroup forStreamer(String streamerName,
                           @Nullable
                           String... streamerNames)

Creates projection for all nodes that have streamer with specified name running.

Specified by:
  `forStreamer` in interface `ClusterGroup`
Parameters:
  `streamerName` - Streamer name.
  `streamerNames` - Optional additional streamer names to include into projection.
Returns:
  Projection over nodes that have specified streamer running.

#### forRemotes

    public ClusterGroup forRemotes()

Gets grid projection consisting from the nodes in this projection excluding the local node.

Specified by:
  `forRemotes` in interface `ClusterGroup`
Returns:
  Grid projection consisting from the nodes in this projection excluding the local node, if any.

#### forHost

    public ClusterGroup forHost(ClusterNode node)

Gets grid projection consisting from the nodes in this projection residing on the same host as given node.

Specified by:
  `forHost` in interface `ClusterGroup`
Parameters:
  `node` - Node residing on the host for which projection is created.
Returns:
  Projection for nodes residing on the same host as passed in node.

#### forDaemons

    public ClusterGroup forDaemons()

Gets projection consisting from the daemon nodes in this projection.

Daemon nodes are the usual grid nodes that participate in topology but not visible on the main APIs, i.e. they are not part of any projections. The only way to see daemon nodes is to use this method.

Daemon nodes are used primarily for management and monitoring functionality that is build on Ignite and needs to participate in the topology but also needs to be excluded from "normal" topology so that it won't participate in task execution or in-memory data grid storage.

Specified by:
  `forDaemons` in interface `ClusterGroup`
Returns:
  Grid projection consisting from the daemon nodes in this projection.

#### forRandom

    public ClusterGroup forRandom()

Creates grid projection with one random node from current projection.

Specified by:
  `forRandom` in interface `ClusterGroup`
Returns:
  Grid projection with one random node from current projection.

#### forOldest

    public ClusterGroup forOldest()

Creates grid projection with one oldest node in the current projection. The resulting projection is dynamic and will always pick the next oldest node if the previous one leaves topology even after the projection has been created.

Specified by:
  `forOldest` in interface `ClusterGroup`
Returns:
  Grid projection with one oldest node from the current projection.

#### forYoungest

    public ClusterGroup forYoungest()

Creates grid projection with one youngest node in the current projection. The resulting projection is dynamic and will always pick the newest node in the topology, even if more nodes entered after the projection has been created.

Specified by:
  `forYoungest` in interface `ClusterGroup`
Returns:
  Grid projection with one youngest node from the current projection.

#### nodes

    public Collection<ClusterNode> nodes()

Gets read-only collections of nodes in this projection.

Specified by:
  `nodes` in interface `ClusterGroup`
Returns:
  All nodes in this projection.

#### node

    @Nullable
    public ClusterNode node(UUID id)

Gets a node for given ID from this grid projection.

Specified by:
  `node` in interface `ClusterGroup`
Parameters:
  `id` - Node ID.
Returns:
  Node with given ID from this projection or `null` if such node does not exist in this projection.

#### node

    @Nullable
    public ClusterNode node()

Gets first node from the list of nodes in this projection. This method is specifically useful for projection over one node only.

Specified by:
  `node` in interface `ClusterGroup`
Returns:
  First node from the list of nodes in this projection or `null` if projection is empty.

#### predicate

    public IgnitePredicate<ClusterNode> predicate()

Gets predicate that defines a subset of nodes for this projection.

Specified by:
  `predicate` in interface `ClusterGroup`
Returns:
  Predicate that defines a subset of nodes for this projection.

#### metrics

    public ClusterMetrics metrics()

Gets a metrics snapshot for this projection.

Specified by:
  `metrics` in interface `ClusterGroup`
Returns:
  Grid projection metrics snapshot.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0-RC1
Release Date | : February 17 2015