Class Ignition
- java.lang.Object
-
- org.apache.ignite.Ignition
-
public class Ignition extends Object
This class defines a factory for the main Ignite API. It controls Grid life cycle and allows listening for grid events.Grid Loaders
Although user can apply grid factory directly to start and stop grid, grid is often started and stopped by grid loaders. Grid loaders can be found inorg.apache.ignite.startup
package, for example:Examples
Usestart()
method to start grid with default configuration. You can also useIgniteConfiguration
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 (seeClusterNode.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 usingIGNITE_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 usingIgnition
. For more information refer toIgniteSpringBean
documentation.
-
-
Field Summary
Fields Modifier and Type Field 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.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Ignition()
Enforces singleton.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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(@Nullable 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 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 localIgnite
instance, principally from closure.static boolean
removeListener(IgnitionListener lsnr)
Removes lsnr added byaddListener(IgnitionListener)
method.static void
restart(boolean cancel)
Restarts all started grids.static void
setClientMode(boolean clientMode)
Sets client mode thread-local flag.static Ignite
start()
Starts grid with default 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 Ignite
start(IgniteConfiguration cfg)
Starts grid with given configuration.static IgniteClient
startClient(ClientConfiguration cfg)
Initializes new instance ofIgniteClient
.static IgniteState
state()
Gets state of grid default grid.static IgniteState
state(@Nullable 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.
-
-
-
Field Detail
-
RESTART_EXIT_CODE
public static final 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. Note that there is no standard way for a JVM to restart itself from Java application and therefore we rely on external tools to provide that capability.Note that standard ignite.{sh|bat} scripts support restarting when JVM process exits with this code.
- See Also:
- Constant Field Values
-
KILL_EXIT_CODE
public static final 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.- See Also:
- Constant Field Values
-
-
Method Detail
-
setClientMode
public static void setClientMode(boolean clientMode)
Sets client mode thread-local flag.This flag used when node is started if
IgniteConfiguration.isClientMode()
isnull
. WhenIgniteConfiguration.isClientMode()
is set this flag is ignored.- Parameters:
clientMode
- Client mode flag.- See Also:
IgniteConfiguration.isClientMode()
-
isClientMode
public static boolean isClientMode()
Gets client mode thread-local flag.This flag used when node is started if
IgniteConfiguration.isClientMode()
isnull
. WhenIgniteConfiguration.isClientMode()
is set this flag is ignored.- Returns:
- Client mode flag.
- See Also:
IgniteConfiguration.isClientMode()
-
state
public static IgniteState state()
Gets state of grid default grid.- Returns:
- Default grid state.
-
state
public static IgniteState state(@Nullable @Nullable String name)
Gets states of named Ignite instance. If name isnull
, then state of default no-name Ignite instance is returned.- Parameters:
name
- Ignite instance name. If name isnull
, then state of default no-name Ignite instance is returned.- Returns:
- Ignite instance state.
-
stop
public static boolean stop(boolean cancel)
Stops default grid. This method is identical toG.stop(null, cancel)
apply. Note that method does not wait for all tasks to be completed.- Parameters:
cancel
- Iftrue
then all jobs currently executing on default grid will be cancelled by callingComputeJob.cancel()
method. Note that just like withThread.interrupt()
, it is up to the actual job to exit from execution- Returns:
true
if default grid instance was indeed stopped,false
otherwise (if it was not started).
-
stop
public static boolean stop(String name, boolean cancel)
Stops named Ignite instance. Ifcancel
flag is set totrue
then all jobs currently executing on local node will be interrupted. If Ignite instance name isnull
, then default no-name Ignite instance will be stopped. If wait parameter is set totrue
then Ignite instance will wait for all tasks to be finished.- Parameters:
name
- Ignite instance name. Ifnull
, then default no-name Ignite instance will be stopped.cancel
- Iftrue
then all jobs currently will be cancelled by callingComputeJob.cancel()
method. Note that just like withThread.interrupt()
, it is up to the actual job to exit from execution. Iffalse
, 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.- Returns:
true
if named Ignite instance was indeed found and stopped,false
otherwise (the instance with givenname
was not found).
-
stopAll
public static void stopAll(boolean cancel)
Stops all started grids in current JVM. Ifcancel
flag is set totrue
then all jobs currently executing on local node will be interrupted. If wait parameter is set totrue
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.
- Parameters:
cancel
- Iftrue
then all jobs currently executing on all grids will be cancelled by callingComputeJob.cancel()
method. Note that just like withThread.interrupt()
, it is up to the actual job to exit from execution
-
restart
public static void restart(boolean cancel)
Restarts all started grids. Ifcancel
flag is set totrue
then all jobs currently executing on the local node will be interrupted. Ifwait
parameter is set totrue
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.
- Parameters:
cancel
- Iftrue
then all jobs currently executing on all grids will be cancelled by callingComputeJob.cancel()
method. Note that just like withThread.interrupt()
, it is up to the actual job to exit from execution.- See Also:
RESTART_EXIT_CODE
-
kill
public static void kill(boolean cancel)
Stops all started grids. Ifcancel
flag is set totrue
then all jobs currently executing on the local node will be interrupted. Ifwait
parameter is set totrue
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
.- Parameters:
cancel
- Iftrue
then all jobs currently executing on all grids will be cancelled by callingComputeJob.cancel()
method. Note that just like withThread.interrupt()
, it is up to the actual job to exit from execution.- See Also:
KILL_EXIT_CODE
-
start
public static Ignite start() throws IgniteException
Starts grid with default configuration. By default this method will use grid configuration defined inIGNITE_HOME/config/default-config.xml
configuration file. If such file is not found, then all system defaults will be used.- Returns:
- Started grid.
- Throws:
IgniteException
- If default grid could not be started. This exception will be thrown also if default grid has already been started.
-
start
public static Ignite start(IgniteConfiguration cfg) throws IgniteException
Starts grid with given configuration. Note that this method will throw an exception if grid with the name provided in given configuration is already started.- Parameters:
cfg
- Grid configuration. This cannot benull
.- Returns:
- Started grid.
- Throws:
IgniteException
- If grid could not be started. This exception will be thrown also if named grid has already been started.
-
start
public static Ignite start(String springCfgPath) throws IgniteException
Starts all grids specified within given Spring XML configuration file. If grid with given name is already started, then exception is thrown. In this case all instances that may have been started so far will be stopped too.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.
- Parameters:
springCfgPath
- Spring XML configuration file path or URL.- Returns:
- Started grid. If Spring configuration contains multiple grid instances, then the 1st found instance is returned.
- Throws:
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.
-
start
public static Ignite start(URL springCfgUrl) throws IgniteException
Starts all grids specified within given Spring XML configuration file URL. If grid with given name is already started, then exception is thrown. In this case all instances that may have been started so far will be stopped too.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.
- Parameters:
springCfgUrl
- Spring XML configuration file URL. This cannot benull
.- Returns:
- Started grid. If Spring configuration contains multiple grid instances, then the 1st found instance is returned.
- Throws:
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.
-
start
public static Ignite start(InputStream springCfgStream) throws IgniteException
Starts all grids specified within given Spring XML configuration input stream. If grid with given name is already started, then exception is thrown. In this case all instances that may have been started so far will be stopped too.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.
- Parameters:
springCfgStream
- Input stream containing Spring XML configuration. This cannot benull
.- Returns:
- Started grid. If Spring configuration contains multiple grid instances, then the 1st found instance is returned.
- Throws:
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.
-
getOrStart
public static Ignite getOrStart(IgniteConfiguration cfg) throws IgniteException
Gets or starts new grid instance if it hasn't been started yet.- Parameters:
cfg
- Grid configuration. This cannot benull
.- Returns:
- Grid instance.
- Throws:
IgniteException
- If grid could not be started.
-
loadSpringBean
public static <T> T loadSpringBean(String springXmlPath, String beanName) throws IgniteException
Loads Spring bean by its name from given Spring XML configuration file. If bean with such name doesn't exist, exception is thrown.- Type Parameters:
T
- Type of the loaded bean.- Parameters:
springXmlPath
- Spring XML configuration file path (cannot benull
).beanName
- Bean name (cannot benull
).- Returns:
- Loaded bean instance.
- Throws:
IgniteException
- If bean with provided name was not found or in case any other error.
-
loadSpringBean
public static <T> T loadSpringBean(URL springXmlUrl, String beanName) throws IgniteException
Loads Spring bean by its name from given Spring XML configuration file. If bean with such name doesn't exist, exception is thrown.- Type Parameters:
T
- Type of the loaded bean.- Parameters:
springXmlUrl
- Spring XML configuration file URL (cannot benull
).beanName
- Bean name (cannot benull
).- Returns:
- Loaded bean instance.
- Throws:
IgniteException
- If bean with provided name was not found or in case any other error.
-
loadSpringBean
public static <T> T loadSpringBean(InputStream springXmlStream, String beanName) throws IgniteException
Loads Spring bean by its name from given Spring XML configuration file. If bean with such name doesn't exist, exception is thrown.- Type Parameters:
T
- Type of the loaded bean.- Parameters:
springXmlStream
- Input stream containing Spring XML configuration (cannot benull
).beanName
- Bean name (cannot benull
).- Returns:
- Loaded bean instance.
- Throws:
IgniteException
- If bean with provided name was not found or in case any other error.
-
ignite
public static Ignite ignite() throws IgniteIllegalStateException
Gets an instance of default no-name grid. Note that caller of this method should not assume that it will return the same instance every time.- Returns:
- An instance of default no-name grid. This method never returns
null
. - Throws:
IgniteIllegalStateException
- Thrown if default grid was not properly initialized or grid instance was stopped or was not started.
-
allGrids
public static List<Ignite> allGrids()
Gets a list of all grids started so far.- Returns:
- List of all grids started so far.
-
ignite
public static Ignite ignite(UUID locNodeId) throws IgniteIllegalStateException
Gets a grid instance for given local node ID. Note that grid instance and local node have one-to-one relationship where node has ID and instance has name of the grid to which both grid instance and its node belong. Note also that caller of this method should not assume that it will return the same instance every time.- Parameters:
locNodeId
- ID of local node the requested grid instance is managing.- Returns:
- An instance of named grid. This method never returns
null
. - Throws:
IgniteIllegalStateException
- Thrown if grid was not properly initialized or grid instance was stopped or was not started.
-
ignite
public static Ignite ignite(@Nullable @Nullable String name) throws IgniteIllegalStateException
Gets a named Ignite instance. If Ignite instance name isnull
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.
- Parameters:
name
- Ignite instance name. Ifnull
, then a default no-name Ignite instance will be returned.- Returns:
- A named Ignite instance. This method never returns
null
. - Throws:
IgniteIllegalStateException
- Thrown if default Ignite instance was not properly initialized or Ignite instance was stopped or was not started.
-
localIgnite
public static Ignite localIgnite() throws IgniteIllegalStateException, IllegalArgumentException
This method is used to address a localIgnite
instance, principally from closure.According to contract this method has to be called only under
IgniteThread
. AnIllegalArgumentException
will be thrown otherwise.- Returns:
- A current
Ignite
instance to address from closure. - Throws:
IgniteIllegalStateException
- Thrown if grid was not properly initialized or grid instance was stopped or was not startedIllegalArgumentException
- Thrown if current thread is not anIgniteThread
.
-
addListener
public static void addListener(IgnitionListener lsnr)
Adds a lsnr for grid life cycle events.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.
- Parameters:
lsnr
- Listener for grid life cycle events. If this listener was already added this method is no-op.
-
removeListener
public static boolean removeListener(IgnitionListener lsnr)
Removes lsnr added byaddListener(IgnitionListener)
method.- Parameters:
lsnr
- Listener to remove.- Returns:
true
if lsnr was added before,false
otherwise.
-
startClient
public static IgniteClient startClient(ClientConfiguration cfg) throws ClientException
Initializes new instance ofIgniteClient
.- Parameters:
cfg
- Thin client configuration.- Returns:
- Client with successfully opened thin client connection.
- Throws:
ClientException
-
-