public class GridGainEx extends Object
org.gridgain.grid.startup package, for example:
GridCommandLineStartupGridServletStartupstart() method to start grid with default configuration. You can also use
GridConfiguration to override some default configuration. Below is an
example on how to start grid with URI deployment.
GridConfiguration cfg = new GridConfiguration();
| Modifier and Type | Method and Description |
|---|---|
static void |
addListener(GridGainListener lsnr)
Adds a lsnr for grid life cycle events.
|
static List<Grid> |
allGrids()
Gets a list of all grids started so far.
|
static Grid |
grid()
Gets an instance of default no-name grid.
|
static Grid |
grid(String name)
Gets an named grid instance.
|
static Grid |
grid(UUID locNodeId)
Gets a grid instance for given local node ID.
|
static GridKernal |
gridx(String name)
Gets grid instance without waiting its initialization.
|
static boolean |
isDaemon()
Gets daemon flag.
|
static void |
kill(boolean cancel)
Stops all started grids.
|
static GridBiTuple<GridConfiguration,GridSpringResourceContext> |
loadConfiguration(String springCfgPath)
Loads first found grid configuration specified within given Spring XML configuration file.
|
static GridBiTuple<GridConfiguration,GridSpringResourceContext> |
loadConfiguration(URL springCfgUrl)
Loads first found grid configuration specified within given Spring XML configuration file.
|
static GridBiTuple<Collection<GridConfiguration>,? extends GridSpringResourceContext> |
loadConfigurations(String springCfgPath)
Loads all grid configurations specified within given Spring XML configuration file.
|
static GridBiTuple<Collection<GridConfiguration>,? extends GridSpringResourceContext> |
loadConfigurations(URL springCfgUrl)
Loads all grid configurations specified within given Spring XML configuration file.
|
static boolean |
removeListener(GridGainListener lsnr)
Removes lsnr added by
addListener(GridGainListener) method. |
static void |
restart(boolean cancel)
Restarts all started grids.
|
static void |
setDaemon(boolean daemon)
Sets daemon flag.
|
static Grid |
start()
Starts grid with default configuration.
|
static Grid |
start(GridConfiguration cfg)
Starts grid with given configuration.
|
static Grid |
start(GridConfiguration cfg,
GridSpringResourceContext springCtx)
Starts grid with given configuration.
|
static Grid |
start(GridSpringResourceContext springCtx)
Starts grid with default configuration.
|
static Grid |
start(String springCfgPath)
Starts all grids specified within given Spring XML configuration file.
|
static Grid |
start(String springCfgPath,
GridSpringResourceContext springCtx)
Starts all grids specified within given Spring XML configuration file.
|
static Grid |
start(URL springCfgUrl)
Starts all grids specified within given Spring XML configuration file URL.
|
static Grid |
start(URL springCfgUrl,
GridSpringResourceContext springCtx)
Starts all grids specified within given Spring XML configuration file URL.
|
static GridGainState |
state()
Gets state of grid default grid.
|
static GridGainState |
state(String name)
Gets states of named grid.
|
static boolean |
stop(boolean cancel)
Stops default grid.
|
static boolean |
stop(String name,
boolean cancel)
Stops named grid.
|
static void |
stopAll(boolean cancel)
Stops all started grids.
|
public static void setDaemon(boolean daemon)
If daemon flag is set then all grid instances created by the factory will be
daemon, i.e. the local node for these instances will be a daemon node. Note that
if daemon flag is set - it will override the same settings in GridConfiguration.isDaemon().
Note that you can set on and off daemon flag at will.
daemon - Daemon flag to set.public static boolean isDaemon()
If daemon flag it set then all grid instances created by the factory will be
daemon, i.e. the local node for these instances will be a daemon node. Note that
if daemon flag is set - it will override the same settings in GridConfiguration.isDaemon().
Note that you can set on and off daemon flag at will.
public static GridGainState state()
public static GridGainState state(@Nullable String name)
null, then state of
default no-name grid is returned.name - Grid name. If name is null, then state of
default no-name grid is returned.public static boolean stop(boolean cancel)
G.stop(null, cancel) apply.
Note that method does not wait for all tasks to be completed.cancel - If true then all jobs currently executing on
default grid will be cancelled by calling GridComputeJob.cancel()
method. Note that just like with Thread.interrupt(), it is
up to the actual job to exit from executiontrue if default grid instance was indeed stopped,
false otherwise (if it was not started).public static boolean stop(@Nullable String name, boolean cancel)
cancel flag is set to true then
all jobs currently executing on local node will be interrupted. If
grid name is null, then default no-name grid will be stopped.
If wait parameter is set to true then grid will wait for all
tasks to be finished.name - Grid name. If null, then default no-name grid will
be stopped.cancel - If true then all jobs currently will be cancelled
by calling GridComputeJob.cancel() method. Note that just like with
Thread.interrupt(), it is up to the actual job to exit from
execution. If false, then jobs currently running will not be
canceled. In either case, grid node will wait for completion of all
jobs running on it before stopping.true if named grid instance was indeed found and stopped,
false otherwise (the instance with given name was
not found).public static void stopAll(boolean cancel)
cancel flag is set to true then
all jobs currently executing on local node will be interrupted.
If wait parameter is set to true then grid will wait for all
tasks to be finished.
Note: it is usually safer and more appropriate to stop grid instances individually instead of blanket operation. In most cases, the party that started the grid instance should be responsible for stopping it.
cancel - If true then all jobs currently executing on
all grids will be cancelled by calling GridComputeJob.cancel()
method. Note that just like with Thread.interrupt(), it is
up to the actual job to exit from executionpublic static void restart(boolean cancel)
cancel flag is set to true then
all jobs currently executing on the local node will be interrupted.
If wait parameter is set to true then grid will wait for all
tasks to be finished.
Note: it is usually safer and more appropriate to stop grid instances individually instead of blanket operation. In most cases, the party that started the grid instance should be responsible for stopping it.
Note also that restarting functionality only works with the tools that specifically support GridGain's protocol for restarting. Currently only standard ggstart.{sh|bat} scripts support restarting of JVM GridGain's process.
cancel - If true then all jobs currently executing on
all grids will be cancelled by calling GridComputeJob.cancel()
method. Note that just like with Thread.interrupt(), it is
up to the actual job to exit from execution.GridGain.RESTART_EXIT_CODEpublic static void kill(boolean cancel)
cancel flag is set to true then
all jobs currently executing on the local node will be interrupted.
If wait parameter is set to true then grid will wait for all
tasks to be finished.
Note: it is usually safer and more appropriate to stop grid instances individually instead of blanket operation. In most cases, the party that started the grid instance should be responsible for stopping it.
Note that upon completion of this method, the JVM with forcefully exist with
exit code GridGain.KILL_EXIT_CODE.
cancel - If true then all jobs currently executing on
all grids will be cancelled by calling GridComputeJob.cancel()
method. Note that just like with Thread.interrupt(), it is
up to the actual job to exit from execution.GridGain.KILL_EXIT_CODEpublic static Grid start() throws GridException
GRIDGAIN_HOME/config/default-config.xml
configuration file. If such file is not found, then all system defaults will be used.GridException - If default grid could not be started. This exception will be thrown
also if default grid has already been started.public static Grid start(@Nullable GridSpringResourceContext springCtx) throws GridException
GRIDGAIN_HOME/config/default-config.xml
configuration file. If such file is not found, then all system defaults will be used.springCtx - Optional Spring application context, possibly null.
Spring bean definitions for bean injection are taken from this context.
If provided, this context can be injected into grid tasks and grid jobs using
@GridSpringApplicationContextResource annotation.GridException - If default grid could not be started. This exception will be thrown
also if default grid has already been started.public static Grid start(GridConfiguration cfg) throws GridException
cfg - Grid configuration. This cannot be null.GridException - If grid could not be started. This exception will be thrown
also if named grid has already been started.public static Grid start(GridConfiguration cfg, @Nullable GridSpringResourceContext springCtx) throws GridException
cfg - Grid configuration. This cannot be null.springCtx - Optional Spring application context, possibly null.
Spring bean definitions for bean injection are taken from this context.
If provided, this context can be injected into grid tasks and grid jobs using
@GridSpringApplicationContextResource annotation.GridException - If grid could not be started. This exception will be thrown
also if named grid has already been started.public static Grid start(@Nullable String springCfgPath) throws GridException
Usually Spring XML configuration file will contain only one Grid definition. Note that Grid configuration bean(s) is retrieved form configuration file by type, so the name of the Grid configuration bean is ignored.
springCfgPath - Spring XML configuration file path or URL.GridException - If grid could not be started or configuration
read. This exception will be thrown also if grid with given name has already
been started or Spring XML configuration file is invalid.public static GridBiTuple<Collection<GridConfiguration>,? extends GridSpringResourceContext> loadConfigurations(URL springCfgUrl) throws GridException
Usually Spring XML configuration file will contain only one Grid definition. Note that Grid configuration bean(s) is retrieved form configuration file by type, so the name of the Grid configuration bean is ignored.
springCfgUrl - Spring XML configuration file path or URL. This cannot be null.GridException - If grid could not be started or configuration
read. This exception will be thrown also if grid with given name has already
been started or Spring XML configuration file is invalid.public static GridBiTuple<Collection<GridConfiguration>,? extends GridSpringResourceContext> loadConfigurations(String springCfgPath) throws GridException
Usually Spring XML configuration file will contain only one Grid definition. Note that Grid configuration bean(s) is retrieved form configuration file by type, so the name of the Grid configuration bean is ignored.
springCfgPath - Spring XML configuration file path. This cannot be null.GridException - If grid could not be started or configuration
read. This exception will be thrown also if grid with given name has already
been started or Spring XML configuration file is invalid.public static GridBiTuple<GridConfiguration,GridSpringResourceContext> loadConfiguration(URL springCfgUrl) throws GridException
Usually Spring XML configuration file will contain only one Grid definition. Note that Grid configuration bean(s) is retrieved form configuration file by type, so the name of the Grid configuration bean is ignored.
springCfgUrl - Spring XML configuration file path or URL. This cannot be null.GridException - If grid could not be started or configuration
read. This exception will be thrown also if grid with given name has already
been started or Spring XML configuration file is invalid.public static GridBiTuple<GridConfiguration,GridSpringResourceContext> loadConfiguration(String springCfgPath) throws GridException
Usually Spring XML configuration file will contain only one Grid definition. Note that Grid configuration bean(s) is retrieved form configuration file by type, so the name of the Grid configuration bean is ignored.
springCfgPath - Spring XML configuration file path. This cannot be null.GridException - If grid could not be started or configuration
read. This exception will be thrown also if grid with given name has already
been started or Spring XML configuration file is invalid.public static Grid start(String springCfgPath, @Nullable GridSpringResourceContext springCtx) throws GridException
Usually Spring XML configuration file will contain only one Grid definition. Note that Grid configuration bean(s) is retrieved form configuration file by type, so the name of the Grid configuration bean is ignored.
springCfgPath - Spring XML configuration file path or URL. This cannot be null.springCtx - Optional Spring application context, possibly null.
Spring bean definitions for bean injection are taken from this context.
If provided, this context can be injected into grid tasks and grid jobs using
@GridSpringApplicationContextResource annotation.GridException - If grid could not be started or configuration
read. This exception will be thrown also if grid with given name has already
been started or Spring XML configuration file is invalid.public static Grid start(URL springCfgUrl) throws GridException
Usually Spring XML configuration file will contain only one Grid definition. Note that Grid configuration bean(s) is retrieved form configuration file by type, so the name of the Grid configuration bean is ignored.
springCfgUrl - Spring XML configuration file URL. This cannot be null.GridException - If grid could not be started or configuration
read. This exception will be thrown also if grid with given name has already
been started or Spring XML configuration file is invalid.public static Grid start(URL springCfgUrl, @Nullable GridSpringResourceContext springCtx) throws GridException
Usually Spring XML configuration file will contain only one Grid definition. Note that Grid configuration bean(s) is retrieved form configuration file by type, so the name of the Grid configuration bean is ignored.
springCfgUrl - Spring XML configuration file URL. This cannot be null.springCtx - Optional Spring application context, possibly null.
Spring bean definitions for bean injection are taken from this context.
If provided, this context can be injected into grid tasks and grid jobs using
@GridSpringApplicationContextResource annotation.GridException - If grid could not be started or configuration
read. This exception will be thrown also if grid with given name has already
been started or Spring XML configuration file is invalid.public static Grid grid() throws GridIllegalStateException
This method is identical to G.grid(null) apply.
null.GridIllegalStateException - Thrown if default grid was not properly
initialized or grid instance was stopped or was not started.public static List<Grid> allGrids()
public static Grid grid(UUID locNodeId) throws GridIllegalStateException
locNodeId - ID of local node the requested grid instance is managing.null.GridIllegalStateException - Thrown if grid was not properly
initialized or grid instance was stopped or was not started.public static Grid grid(@Nullable String name) throws GridIllegalStateException
null or empty string,
then default no-name grid will be returned. Note that caller of this method
should not assume that it will return the same instance every time.
Note that Java VM can run multiple grid instances and every grid instance (and its node) can belong to a different grid. Grid name defines what grid a particular grid instance (and correspondingly its node) belongs to.
name - Grid name to which requested grid instance belongs to. If null,
then grid instance belonging to a default no-name grid will be returned.null.GridIllegalStateException - Thrown if default grid was not properly
initialized or grid instance was stopped or was not started.public static GridKernal gridx(@Nullable String name)
name - Grid name.public static void addListener(GridGainListener lsnr)
Note that unlike other listeners in GridGain this listener will be notified from the same thread that triggers the state change. Because of that it is the responsibility of the user to make sure that listener logic is light-weight and properly handles (catches) any runtime exceptions, if any are expected.
lsnr - Listener for grid life cycle events. If this listener was already added
this method is no-op.public static boolean removeListener(GridGainListener lsnr)
addListener(GridGainListener) method.lsnr - Listener to remove.true if lsnr was added before, false otherwise.Copyright © 2014. All rights reserved.