Ignite is JVM-based. Single JVM represents one or more logical Ignite nodes (most of the time, however, a single JVM runs just one Ignite node). Throughout the Ignite documentation, we use the terms Ignite runtime and Ignite node almost interchangeably. For example, when we say that you can “run 5 nodes on this host” – in most cases it technically means that you can start 5 JVMs on this host each running a single Ignite node. Ignite also supports multiple Ignite nodes in a single JVM. In fact, that is exactly how most of the internal tests run for Ignite.
Ignite runtime == JVM process == Ignite node (in most cases)
Ignition Class
The classIgnition
starts individual Ignite nodes in the network topology. Note that a physical server (like a computer on the network) can have multiple Ignite nodes running on it.
Here is how you can start a grid node locally with all the defaults:
Ignite ignite = Ignition.start();
You can also start an Ignite node by passing a configuration file:
Ignite ignite = Ignition.start("examples/config/example-cache.xml");
The path to the configuration file can be absolute or relative to either IGNITE_HOME
(Ignite installation folder) or folderMETA-INF
in your classpath.
Sometimes you need to perform certain actions before or after the Ignite node starts or stops. This can be done by implementing the LifecycleBean
interface, and specifying the implementation bean in lifecycleBeans
property of IgniteConfiguration
in the spring XML file:
<bean class="org.apache.ignite.IgniteConfiguration">
...
<property name="lifecycleBeans">
<list>
<bean class="com.mycompany.MyLifecycleBean"/>
</list>
</property>
...
</bean>
LifeCycleBean
can also be configured programmatically the following way:
// Create new configuration.
IgniteConfiguration cfg = new IgniteConfiguration();
// Provide lifecycle bean to configuration.
cfg.setLifecycleBeans(new MyLifecycleBean());
// Start Ignite node with given configuration.
Ignite ignite = Ignition.start(cfg)
An implementation of LifecycleBean
may look like the following:
public class MyLifecycleBean implements LifecycleBean {
public void onLifecycleEvent
(LifecycleEventType evt) {
if (evt == LifecycleEventType.BEFORE_NODE_START) {
// Do something.
...
}
}
}
You can inject an Ignite instance and other useful resources into an LifecycleBean
implementation. Please refer to Resource Injection section for more information.
The following lifecycle event types are supported:
BEFORE_NODE_START
Invoked before Ignite node startup routine is initiated.
AFTER_NODE_START
Invoked right after Ignite node has started.
BEFORE_NODE_STOP
Invoked right before Ignite stop routine is initiated.
AFTER_NODE_STOP
Invoked right after Ignite node has stopped.