public interface Grid extends GridProjection, AutoCloseable
Grid through GridGain.grid(),
or for named grids you can use GridGain.grid(String). Note that you
can have multiple instances of Grid running in the same VM by giving
each instance a different name.
Note that Grid extends GridProjection which means that it provides grid projection
functionality over the whole grid (instead os a subgroup of nodes).
In addition to GridProjection functionality, from here you can get the following:
GridCache - functionality for in-memory distributed cache.GridDataLoader - functionality for loading data large amounts of data into cache.GridDr - functionality for WAN-based Data Center Replication of in-memory cache.GridGgfs - functionality for distributed Hadoop-compliant in-memory file system and map-reduce.GridStreamer - functionality for streaming events workflow with queries and indexes into rolling windows.GridScheduler - functionality for scheduling jobs using UNIX Cron syntax.GridProduct - functionality for licence management and update and product related information.GridCompute - functionality for executing tasks and closures on all grid nodes (inherited form GridProjection).GridMessaging - functionality for topic-based message exchange on all grid nodes (inherited form GridProjection).GridEvents - functionality for querying and listening to events on all grid nodes (inherited form GridProjection).Grid also provides a handle on nodeLocalMap() which provides map-like functionality
linked to current grid node. Node-local map is useful for saving shared state between job executions
on the grid. Additionally you can also ping, start, and restart remote nodes, map keys to caching nodes,
and get other useful information about topology.| Modifier and Type | Method and Description |
|---|---|
<K,V> GridCache<K,V> |
cache(String name)
Gets the cache instance for the given name, if one does not
exist
IllegalArgumentException will be thrown. |
Collection<GridCache<?,?>> |
caches()
Gets all configured caches.
|
void |
close()
Closes
this instance of grid. |
GridConfiguration |
configuration()
Gets the configuration of this grid instance.
|
<K,V> GridDataLoader<K,V> |
dataLoader(String cacheName)
Gets a new instance of data loader associated with given cache name.
|
GridDr |
dr()
Gets an instance of Data Center Replication.
|
GridProjection |
forLocal()
Gets monadic projection consisting from the local node.
|
GridGgfs |
ggfs(String name)
Gets an instance of GGFS - GridGain In-Memory File System, if one is not
configured then
IllegalArgumentException will be thrown. |
Collection<GridGgfs> |
ggfss()
Gets all instances of the grid file systems.
|
GridNode |
localNode()
Gets local grid node.
|
GridLogger |
log()
Gets grid's logger.
|
<K> Map<GridNode,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> GridNode |
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.
|
String |
name()
Gets the name of the grid this grid instance (and correspondingly its local node) belongs to.
|
<K,V> GridNodeLocalMap<K,V> |
nodeLocalMap()
Gets node-local storage instance.
|
boolean |
pingNode(UUID nodeId)
Pings a remote node.
|
GridProduct |
product()
Gets information about product as well as license management capabilities.
|
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.
|
GridScheduler |
scheduler()
Gets an instance of cron-based scheduler.
|
GridSecurity |
security()
Gets an instance of
GridSecurity interface. |
GridFuture<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).
|
GridFuture<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.
|
GridStreamer |
streamer(String name)
Gets an instance of streamer by name, if one does not exist then
IllegalArgumentException will be thrown. |
Collection<GridStreamer> |
streamers()
Gets all instances of streamers.
|
Collection<GridNode> |
topology(long topVer)
Gets a topology by version.
|
long |
topologyVersion()
Gets current topology version.
|
compute, events, forAttribute, forCache, forDaemons, forHost, forNode, forNodeId, forNodeIds, forNodes, forOthers, forOthers, forPredicate, forRandom, forRemotes, forStreamer, grid, message, metrics, node, node, nodes, predicateString name()
If default grid instance is used, then
null is returned. Refer to GridGain documentation
for information on how to start named grids.
null for default grid.GridLogger log()
<K,V> GridNodeLocalMap<K,V> nodeLocalMap()
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.
GridConfiguration configuration()
NOTE:
SPIs obtains through this method should never be used directly. SPIs provide
internal view on the subsystem and is used internally by GridGain kernal. In rare use cases when
access to a specific implementation of this SPI is required - an instance of this SPI can be obtained
via this method to check its configuration properties or call other non-SPI
methods.
GridProjection forLocal()
GridProduct product()
GridScheduler scheduler()
GridSecurity security()
GridSecurity interface. Available in enterprise edition only.GridSecurity interface.@GridOnlyAvailableIn(value=DATA_GRID) GridDr dr()
@GridOnlyAvailableIn(value=DATA_GRID) <K,V> GridCache<K,V> cache(@Nullable String name)
IllegalArgumentException will be thrown.
Note that in case named cache instance is used as GGFS data or meta cache, IllegalStateException
will be thrown.K - Key type.V - Value type.name - Cache name.GridGgfsConfiguration,
GridGgfsConfiguration.getDataCacheName(),
GridGgfsConfiguration.getMetaCacheName()@GridOnlyAvailableIn(value=DATA_GRID) Collection<GridCache<?,?>> caches()
GridGgfsConfiguration,
GridGgfsConfiguration.getDataCacheName(),
GridGgfsConfiguration.getMetaCacheName()@GridOnlyAvailableIn(value=DATA_GRID) <K,V> GridDataLoader<K,V> dataLoader(@Nullable String cacheName)
GridDataLoader documentation.cacheName - Cache name (null for default cache).@GridOnlyAvailableIn(value=HADOOP) GridGgfs ggfs(String name)
IllegalArgumentException will be thrown.
GGFS is fully compliant with Hadoop FileSystem APIs and can
be plugged into Hadoop installations. For more information refer to
documentation on Hadoop integration shipped with GridGain.
name - GGFS name.@GridOnlyAvailableIn(value=HADOOP) Collection<GridGgfs> ggfss()
@GridOnlyAvailableIn(value=STREAMING) GridStreamer streamer(@Nullable String name)
IllegalArgumentException will be thrown.name - Streamer name.@GridOnlyAvailableIn(value=STREAMING) Collection<GridStreamer> streamers()
GridNode localNode()
boolean pingNode(UUID nodeId)
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.
nodeId - ID of a node to ping.true if node for a given ID is alive, false otherwise.GridDiscoverySpiGridFuture<Collection<GridTuple3<String,Boolean,String>>> startNodes(File file, boolean restart, int timeout, int maxConn) throws GridException
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.
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.GridException - In case of error.GridFuture<Collection<GridTuple3<String,Boolean,String>>> startNodes(Collection<Map<String,Object>> hosts, @Nullable Map<String,Object> dflts, boolean restart, int timeout, int maxConn) throws GridException
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.
|
| ggHome | String | Path to GridGain installation folder. If not defined, GRIDGAIN_HOME environment variable must be set on remote hosts. |
| cfg | String | Path to configuration file (relative to ggHome). |
| script | String |
Custom startup script file name and path (relative to ggHome).
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.
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.GridException - In case of error.void stopNodes()
throws GridException
NOTE: System.exit(GridGain.KILL_EXIT_CODE) will be executed on each
stopping node. If you have other applications running in the same JVM along with GridGain,
those applications will be stopped as well.
GridException - In case of error.void stopNodes(Collection<UUID> ids) throws GridException
NOTE: System.exit(GridGain.KILL_EXIT_CODE) will be executed on each
stopping node. If you have other applications running in the same JVM along with GridGain,
those applications will be stopped as well.
ids - IDs defining nodes to stop.GridException - In case of error.void restartNodes()
throws GridException
NOTE: this command only works for grid nodes started with GridGain
ggstart.sh or ggstart.bat scripts.
GridException - In case of error.void restartNodes(Collection<UUID> ids) throws GridException
NOTE: this command only works for grid nodes started with GridGain
ggstart.sh or ggstart.bat scripts.
ids - IDs defining nodes to restart.GridException - In case of error.long topologyVersion()
GridTcpDiscoverySpi) 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.@Nullable Collection<GridNode> topology(long topVer) throws UnsupportedOperationException
null if topology history storage doesn't contain
specified topology version (history currently keeps last 1000 snapshots).topVer - Topology version.null otherwise.UnsupportedOperationException - If underlying SPI implementation does not support
topology history. Currently only GridTcpDiscoverySpi
supports topology history.<K> Map<GridNode,Collection<K>> mapKeysToNodes(@Nullable String cacheName, @Nullable Collection<? extends K> keys) throws GridException
This method works as following:
GridCacheAffinityFunction is
used to determine which keys are mapped to which groups of nodes.
cacheName - Cache name, if null, then default cache instance is used.keys - Cache keys to map to nodes.GridException - If failed to map cache keys.@Nullable <K> GridNode mapKeyToNode(@Nullable String cacheName, K key) throws GridException
This method works as following:
GridCacheAffinityFunction
is returned.
cacheName - Cache name, if null, then default cache instance is used.key - Cache key to map to a node.null if cache with given name
is not present in the grid.GridException - If failed to map key.void resetMetrics()
void close()
throws GridException
this instance of grid. This method is identical to calling
G.stop(gridName, true).
The method is invoked automatically on objects managed by the
try-with-resources statement.
close in interface AutoCloseableGridException - If failed to stop grid.Copyright © 2014. All rights reserved.