public class Ignition extends Object
org.apache.ignite.startup
package, for example:
start()
method to start grid with default configuration. You can also use
IgniteConfiguration
to override some default configuration. Below is an
example on how to start grid with custom configuration for URI deployment.
IgniteConfiguration cfg = new IgniteConfiguration(); GridUriDeployment deploySpi = new GridUriDeployment(); deploySpi.setUriList(Collections.singletonList("classes://tmp/output/classes")); cfg.setDeploymentSpi(deploySpi); Ignition.start(cfg);Here is how a grid instance can be configured from Spring XML configuration file. The example below configures a grid instance with additional user attributes (see
ClusterNode.attributes()
) and specifies a Ignite instance name:
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> ... <property name="igniteInstanceName" value="grid"/> <property name="userAttributes"> <map> <entry key="group" value="worker"/> </map> </property> ... </bean>A grid instance with Spring configuration above can be started as following. Note that you do not need to pass path to Spring XML file if you are using
IGNITE_HOME/config/default-config.xml
. Also note, that the path can be
absolute or relative to IGNITE_HOME.
... Ignition.start("/path/to/spring/xml/file.xml"); ...You can also instantiate grid directly from Spring without using
Ignition
.
For more information refer to IgniteSpringBean
documentation.Modifier and Type | Field and Description |
---|---|
static int |
KILL_EXIT_CODE
This is kill code that can be used by external tools, like Shell scripts,
to auto-stop the Ignite JVM process without restarting.
|
static int |
RESTART_EXIT_CODE
This is restart code that can be used by external tools, like Shell scripts,
to auto-restart the Ignite JVM process.
|
Modifier | Constructor and Description |
---|---|
protected |
Ignition()
Enforces singleton.
|
Modifier and Type | Method and Description |
---|---|
static void |
addListener(IgnitionListener lsnr)
Adds a lsnr for grid life cycle events.
|
static List<Ignite> |
allGrids()
Gets a list of all grids started so far.
|
static Ignite |
getOrStart(IgniteConfiguration cfg)
Gets or starts new grid instance if it hasn't been started yet.
|
static Ignite |
ignite()
Gets an instance of default no-name grid.
|
static Ignite |
ignite(String name)
Gets a named Ignite instance.
|
static Ignite |
ignite(UUID locNodeId)
Gets a grid instance for given local node ID.
|
static boolean |
isClientMode()
Gets client mode thread-local flag.
|
static boolean |
isDaemon()
Gets daemon flag.
|
static void |
kill(boolean cancel)
Stops all started grids.
|
static <T> T |
loadSpringBean(InputStream springXmlStream,
String beanName)
Loads Spring bean by its name from given Spring XML configuration file.
|
static <T> T |
loadSpringBean(String springXmlPath,
String beanName)
Loads Spring bean by its name from given Spring XML configuration file.
|
static <T> T |
loadSpringBean(URL springXmlUrl,
String beanName)
Loads Spring bean by its name from given Spring XML configuration file.
|
static Ignite |
localIgnite()
This method is used to address a local
Ignite instance, principally from closure. |
static boolean |
removeListener(IgnitionListener lsnr)
Removes lsnr added by
addListener(IgnitionListener) method. |
static void |
restart(boolean cancel)
Restarts all started grids.
|
static void |
setClientMode(boolean clientMode)
Sets client mode thread-local flag.
|
static void |
setDaemon(boolean daemon)
Sets daemon flag.
|
static Ignite |
start()
Starts grid with default configuration.
|
static Ignite |
start(IgniteConfiguration cfg)
Starts grid with given configuration.
|
static Ignite |
start(InputStream springCfgStream)
Starts all grids specified within given Spring XML configuration input stream.
|
static Ignite |
start(String springCfgPath)
Starts all grids specified within given Spring XML configuration file.
|
static Ignite |
start(URL springCfgUrl)
Starts all grids specified within given Spring XML configuration file URL.
|
static IgniteClient |
startClient(ClientConfiguration cfg)
Initializes new instance of
IgniteClient . |
static IgniteState |
state()
Gets state of grid default grid.
|
static IgniteState |
state(String name)
Gets states of named Ignite instance.
|
static boolean |
stop(boolean cancel)
Stops default grid.
|
static boolean |
stop(String name,
boolean cancel)
Stops named Ignite instance.
|
static void |
stopAll(boolean cancel)
Stops all started grids in current JVM.
|
public static final int RESTART_EXIT_CODE
Note that standard ignite.{sh|bat} scripts support restarting when JVM process exits with this code.
public static final int KILL_EXIT_CODE
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 IgniteConfiguration.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 IgniteConfiguration.isDaemon()
.
Note that you can set on and off daemon flag at will.
public static void setClientMode(boolean clientMode)
This flag used when node is started if IgniteConfiguration.isClientMode()
is null
. When IgniteConfiguration.isClientMode()
is set this flag is ignored.
clientMode
- Client mode flag.IgniteConfiguration.isClientMode()
public static boolean isClientMode()
This flag used when node is started if IgniteConfiguration.isClientMode()
is null
. When IgniteConfiguration.isClientMode()
is set this flag is ignored.
IgniteConfiguration.isClientMode()
public static IgniteState state()
public static IgniteState state(String name)
null
, then state of
default no-name Ignite instance is returned.name
- Ignite instance name. If name is null
, then state of
default no-name Ignite instance 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 ComputeJob.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(String name, boolean cancel)
cancel
flag is set to true
then
all jobs currently executing on local node will be interrupted. If
Ignite instance name is null
, then default no-name Ignite instance will be stopped.
If wait parameter is set to true
then Ignite instance will wait for all
tasks to be finished.name
- Ignite instance name. If null
, then default no-name Ignite instance will
be stopped.cancel
- If true
then all jobs currently will be cancelled
by calling ComputeJob.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 Ignite 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 ComputeJob.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 Ignite's protocol for restarting. Currently only standard ignite.{sh|bat} scripts support restarting of JVM Ignite's process.
cancel
- If true
then all jobs currently executing on
all grids will be cancelled by calling ComputeJob.cancel()
method. Note that just like with Thread.interrupt()
, it is
up to the actual job to exit from execution.RESTART_EXIT_CODE
public 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 KILL_EXIT_CODE
.
cancel
- If true
then all jobs currently executing on
all grids will be cancelled by calling ComputeJob.cancel()
method. Note that just like with Thread.interrupt()
, it is
up to the actual job to exit from execution.KILL_EXIT_CODE
public static Ignite start() throws IgniteException
IGNITE_HOME/config/default-config.xml
configuration file. If such file is not found, then all system defaults will be used.IgniteException
- If default grid could not be started. This exception will be thrown
also if default grid has already been started.public static Ignite start(IgniteConfiguration cfg) throws IgniteException
cfg
- Grid configuration. This cannot be null
.IgniteException
- If grid could not be started. This exception will be thrown
also if named grid has already been started.public static Ignite start(String springCfgPath) throws IgniteException
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.IgniteException
- 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 Ignite start(URL springCfgUrl) throws IgniteException
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
.IgniteException
- 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 Ignite start(InputStream springCfgStream) throws IgniteException
Usually Spring XML configuration input stream will contain only one Grid definition. Note that Grid configuration bean(s) is retrieved form configuration input stream by type, so the name of the Grid configuration bean is ignored.
springCfgStream
- Input stream containing Spring XML configuration. This cannot be null
.IgniteException
- 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 Ignite getOrStart(IgniteConfiguration cfg) throws IgniteException
cfg
- Grid configuration. This cannot be null
.IgniteException
- If grid could not be started.public static <T> T loadSpringBean(String springXmlPath, String beanName) throws IgniteException
springXmlPath
- Spring XML configuration file path (cannot be null
).beanName
- Bean name (cannot be null
).IgniteException
- If bean with provided name was not found or in case any other error.public static <T> T loadSpringBean(URL springXmlUrl, String beanName) throws IgniteException
springXmlUrl
- Spring XML configuration file URL (cannot be null
).beanName
- Bean name (cannot be null
).IgniteException
- If bean with provided name was not found or in case any other error.public static <T> T loadSpringBean(InputStream springXmlStream, String beanName) throws IgniteException
springXmlStream
- Input stream containing Spring XML configuration (cannot be null
).beanName
- Bean name (cannot be null
).IgniteException
- If bean with provided name was not found or in case any other error.public static Ignite ignite() throws IgniteIllegalStateException
This method is identical to G.grid(null)
apply.
null
.IgniteIllegalStateException
- Thrown if default grid was not properly
initialized or grid instance was stopped or was not started.public static List<Ignite> allGrids()
public static Ignite ignite(UUID locNodeId) throws IgniteIllegalStateException
locNodeId
- ID of local node the requested grid instance is managing.null
.IgniteIllegalStateException
- Thrown if grid was not properly
initialized or grid instance was stopped or was not started.public static Ignite ignite(String name) throws IgniteIllegalStateException
null
or empty string,
then default no-name Ignite instance will be returned. Note that caller of this method
should not assume that it will return the same instance every time.
The name allows having multiple Ignite instances with different names within the same Java VM.
name
- Ignite instance name. If null
, then a default no-name
Ignite instance will be returned.null
.IgniteIllegalStateException
- Thrown if default Ignite instance was not properly
initialized or Ignite instance was stopped or was not started.public static Ignite localIgnite() throws IgniteIllegalStateException, IllegalArgumentException
Ignite
instance, principally from closure.
According to contract this method has to be called only under IgniteThread
.
An IllegalArgumentException
will be thrown otherwise.
Ignite
instance to address from closure.IgniteIllegalStateException
- Thrown if grid was not properly
initialized or grid instance was stopped or was not startedIllegalArgumentException
- Thrown if current thread is not an IgniteThread
.public static void addListener(IgnitionListener lsnr)
Note that unlike other listeners in Ignite 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(IgnitionListener lsnr)
addListener(IgnitionListener)
method.lsnr
- Listener to remove.true
if lsnr was added before, false
otherwise.public static IgniteClient startClient(ClientConfiguration cfg) throws ClientException
IgniteClient
.cfg
- Thin client configuration.ClientException
GridGain In-Memory Computing Platform : ver. 8.9.14 Release Date : November 5 2024