public class GridSpringBean extends org.gridgain.grid.util.lang.GridMetadataAwareAdapter implements Grid, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, Externalizable
GridGain methods.
In other words, this bean class allows to inject new grid instance from
Spring configuration file directly without invoking static
GridGain methods. This class can be wired directly from
Spring and can be referenced from within other Spring beans.
By virtue of implementing DisposableBean and InitializingBean
interfaces, GridSpringBean automatically starts and stops underlying
grid instance.
<bean id="mySpringBean" class="org.gridgain.grid.GridSpringBean" scope="singleton">
<property name="configuration">
<bean id="grid.cfg" class="org.gridgain.grid.GridConfiguration" scope="singleton">
<property name="gridName" value="mySpringGrid"/>
</bean>
</property>
</bean>
Or use default configuration:
<bean id="mySpringBean" class="org.gridgain.grid.GridSpringBean" scope="singleton"/>
AbstractApplicationContext ctx = new FileSystemXmlApplicationContext("/path/to/spring/file");
// Register Spring hook to destroy bean automatically.
ctx.registerShutdownHook();
Grid grid = (Grid)ctx.getBean("mySpringBean");
| Constructor and Description |
|---|
GridSpringBean() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
<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. |
GridCompute |
compute()
Gets
compute functionality over this grid projection. |
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.
|
void |
destroy() |
GridDr |
dr()
Gets an instance of Data Center Replication.
|
GridEvents |
events()
Gets
events functionality over this grid projection. |
GridProjection |
forAttribute(String name,
String val)
Creates projection for nodes containing given name and value
specified in user attributes.
|
GridProjection |
forCache(String cacheName,
String... cacheNames)
Creates projection for all nodes that have cache with specified name running.
|
GridProjection |
forDaemons()
Gets projection consisting from the daemon nodes in this projection.
|
GridProjection |
forHost(GridNode node)
Gets grid projection consisting from the nodes in this projection residing on the
same host as given node.
|
GridProjection |
forLocal()
Gets monadic projection consisting from the local node.
|
GridProjection |
forNode(GridNode node,
GridNode... nodes)
Creates a grid projection for the given node.
|
GridProjection |
forNodeId(UUID nodeId,
UUID... nodeIds)
Creates a grid projection for a node with specified ID.
|
GridProjection |
forNodeIds(Collection<UUID> ids)
Creates a grid projection over nodes with specified node IDs.
|
GridProjection |
forNodes(Collection<? extends GridNode> nodes)
Creates a grid projection over a given set of nodes.
|
GridProjection |
forOthers(GridNode node,
GridNode... nodes)
Creates a grid projection for nodes other than given nodes.
|
GridProjection |
forOthers(GridProjection prj)
Creates a grid projection for nodes not included into given projection.
|
GridProjection |
forPredicate(GridPredicate<GridNode> p)
Creates a grid projection which includes all nodes that pass the given predicate filter.
|
GridProjection |
forRandom()
Creates grid projection with one random node from current projection.
|
GridProjection |
forRemotes()
Gets grid projection consisting from the nodes in this projection excluding the local node.
|
GridProjection |
forStreamer(String streamerName,
String... streamerNames)
Creates projection for all nodes that have streamer with specified name running.
|
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.
|
Grid |
grid()
Gets instance of grid.
|
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.
|
GridMessaging |
message()
Gets
messaging functionality over this grid projection. |
GridProjectionMetrics |
metrics()
Gets a metrics snapshot for this projection.
|
String |
name()
Gets the name of the grid this grid instance (and correspondingly its local node) belongs to.
|
GridNode |
node()
Gets first node from the list of nodes in this projection.
|
GridNode |
node(UUID nid)
Gets a node for given ID from this grid projection.
|
<K,V> GridNodeLocalMap<K,V> |
nodeLocalMap()
Gets node-local storage instance.
|
Collection<GridNode> |
nodes()
Gets read-only collections of nodes in this projection.
|
boolean |
pingNode(UUID nodeId)
Pings a remote node.
|
GridPredicate<GridNode> |
predicate()
Gets predicate that defines a subset of nodes for this projection.
|
GridProduct |
product()
Gets information about product as well as license management capabilities.
|
void |
readExternal(ObjectInput in) |
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.
|
void |
setApplicationContext(org.springframework.context.ApplicationContext ctx) |
void |
setConfiguration(GridConfiguration cfg)
Sets grid configuration.
|
GridFuture<Collection<org.gridgain.grid.util.lang.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<org.gridgain.grid.util.lang.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.
|
String |
toString() |
void |
writeExternal(ObjectOutput out) |
public 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.
configuration in interface Gridpublic void setConfiguration(GridConfiguration cfg)
cfg - Grid configuration.public void setApplicationContext(org.springframework.context.ApplicationContext ctx)
throws org.springframework.beans.BeansException
setApplicationContext in interface org.springframework.context.ApplicationContextAwareorg.springframework.beans.BeansExceptionpublic Grid grid()
grid in interface GridProjectionpublic void destroy()
throws Exception
destroy in interface org.springframework.beans.factory.DisposableBeanExceptionpublic void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanExceptionpublic GridLogger log()
public <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.
nodeLocalMap in interface Gridpublic GridProduct product()
public GridProjection forLocal()
@Nullable public GridDr dr()
public Collection<GridCache<?,?>> caches()
caches in interface GridGridGgfsConfiguration,
GridGgfsConfiguration.getDataCacheName(),
GridGgfsConfiguration.getMetaCacheName()public Collection<GridStreamer> streamers()
public GridNode localNode()
@Nullable public GridNode node(UUID nid)
node in interface GridProjectionnid - Node ID.null if such node does not exist in this
projection.public 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.
stopNodes in interface GridGridException - In case of error.public void restartNodes()
throws GridException
NOTE: this command only works for grid nodes started with GridGain
ggstart.sh or ggstart.bat scripts.
restartNodes in interface GridGridException - In case of error.public GridCompute compute()
compute functionality over this grid projection. All operations
on the returned GridCompute instance will only include nodes from
this projection.compute in interface GridProjectionpublic GridMessaging message()
messaging functionality over this grid projection. All operations
on the returned GridMessaging instance will only include nodes from
this projection.message in interface GridProjectionpublic GridEvents events()
events functionality over this grid projection. All operations
on the returned GridEvents instance will only include nodes from
this projection.events in interface GridProjectionpublic GridScheduler scheduler()
public GridProjection forNodes(Collection<? extends GridNode> nodes)
forNodes in interface GridProjectionnodes - Collection of nodes to create a projection from.public GridProjection forNodeIds(Collection<UUID> ids)
forNodeIds in interface GridProjectionids - Collection of node IDs.public GridProjection forNodeId(UUID nodeId, UUID... nodeIds)
forNodeId in interface GridProjectionnodeId - Node ID to get projection for.nodeIds - Optional additional node IDs to include into projection.public GridProjection forNode(GridNode node, GridNode... nodes)
forNode in interface GridProjectionnode - Node to get projection for.nodes - Optional additional nodes to include into projection.public GridProjection forOthers(GridNode node, GridNode... nodes)
forOthers in interface GridProjectionnode - Node to exclude from new grid projection.nodes - Optional additional nodes to exclude from projection.public GridProjection forOthers(GridProjection prj)
forOthers in interface GridProjectionprj - Projection to exclude from new grid projection.public GridProjection forPredicate(GridPredicate<GridNode> p)
forPredicate in interface GridProjectionp - Predicate filter for nodes to include into this projection.public GridProjection forAttribute(String name, @Nullable String val)
User attributes for every node are optional and can be specified in
grid node configuration. See GridConfiguration.getUserAttributes()
for more information.
forAttribute in interface GridProjectionname - Name of the attribute.val - Optional attribute value to match.public GridProjection forCache(String cacheName, @Nullable String... cacheNames)
forCache in interface GridProjectioncacheName - Cache name.cacheNames - Optional additional cache names to include into projection.public GridProjection forStreamer(String streamerName, @Nullable String... streamerNames)
forStreamer in interface GridProjectionstreamerName - Streamer name.streamerNames - Optional additional streamer names to include into projection.public GridProjection forRemotes()
forRemotes in interface GridProjectionpublic GridProjection forHost(GridNode node)
forHost in interface GridProjectionnode - Node residing on the host for which projection is created.public GridProjection forDaemons()
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 GridGain 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.
forDaemons in interface GridProjectionpublic GridProjection forRandom()
forRandom in interface GridProjectionpublic Collection<GridNode> nodes()
nodes in interface GridProjection@Nullable public GridNode node()
node in interface GridProjectionnull if projection is empty.public GridPredicate<GridNode> predicate()
predicate in interface GridProjectionpublic GridProjectionMetrics metrics() throws GridException
metrics in interface GridProjectionGridException - If projection is empty.public Collection<GridNode> topology(long topVer)
null if topology history storage doesn't contain
specified topology version (history currently keeps last 1000 snapshots).public 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.topologyVersion in interface Gridpublic 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.
pingNode in interface GridnodeId - ID of a node to ping.true if node for a given ID is alive, false otherwise.GridDiscoverySpipublic String name()
If default grid instance is used, then
null is returned. Refer to GridGain documentation
for information on how to start named grids.
public <K,V> GridCache<K,V> cache(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.cache in interface GridK - Key type.V - Value type.name - Cache name.GridGgfsConfiguration,
GridGgfsConfiguration.getDataCacheName(),
GridGgfsConfiguration.getMetaCacheName()public <K> Map<GridNode,Collection<K>> mapKeysToNodes(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.
mapKeysToNodes in interface GridcacheName - Cache name, if null, then default cache instance is used.keys - Cache keys to map to nodes.GridException - If failed to map cache keys.public <K> GridNode mapKeyToNode(String cacheName, K key) throws GridException
This method works as following:
GridCacheAffinityFunction
is returned.
mapKeyToNode in interface GridcacheName - 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.public GridFuture<Collection<org.gridgain.grid.util.lang.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.
startNodes in interface Gridfile - 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.public GridFuture<Collection<org.gridgain.grid.util.lang.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.
startNodes in interface Gridhosts - 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.public 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.
stopNodes in interface Gridids - IDs defining nodes to stop.GridException - In case of error.public void restartNodes(Collection<UUID> ids) throws GridException
NOTE: this command only works for grid nodes started with GridGain
ggstart.sh or ggstart.bat scripts.
restartNodes in interface Gridids - IDs defining nodes to restart.GridException - In case of error.public <K,V> GridDataLoader<K,V> dataLoader(@Nullable String cacheName)
GridDataLoader documentation.dataLoader in interface GridcacheName - Cache name (null for default cache).public 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.
public Collection<GridGgfs> ggfss()
@Nullable public GridStreamer streamer(@Nullable String name)
IllegalArgumentException will be thrown.public void resetMetrics()
resetMetrics in interface Gridpublic 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 AutoCloseableclose in interface GridGridException - If failed to stop grid.public void writeExternal(ObjectOutput out) throws IOException
writeExternal in interface ExternalizableIOExceptionpublic void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal in interface ExternalizableIOExceptionClassNotFoundException
Core Products
:
Data Grid ver. 6.0.2,
Streaming ver. 6.0.2
Accelerators
:
Hadoop Accelerator ver. 6.0.2
Release Date
:
March 24 2014