Ignite.NET Life Cycle
Manage life cycle of your Ignite nodes.
Ignite.NET is process-based. Single process represents one or more logical Ignite.NET nodes (most of the time, however, a single process runs just one Ignite.NET node). Throughout Ignite documentation we use term 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 Ignite.NET processes on this host each running a single Ignite node. Ignite.NET also supports multiple nodes in a single process. In fact, that is exactly how most of the internal tests run for Ignite.NET itself.
Ignite runtime == Ignite .NET process == Ignite .NET node (in most cases)
Ignition Class
The Ignition class starts individual Ignite.NET nodes in the network topology. Note that a physical server (like a computer on the network) can have multiple Ignite.NET nodes running on it.
Here is how you can start grid node locally with all defaults
IIgnite ignite = Ignition.Start();
or by passing a configuration file:
IIgnite ignite = Ignition.Start("examples/config/example-cache.xml");
Path to configuration file can be absolute, or relative to either IGNITE_HOME (Ignite installation folder) or current directory.
ILifecycleHandler
Sometimes you need to perform certain actions before or after the Ignite node starts or stops. This can be done by implementing ILifecycleHandler interface, and specifying the implementation in LifecycleHandlers property of IgniteConfiguration:
var cfg = new IgniteConfiguration
{
LifecycleHandlers = new [] { new LifecycleExampleHandler() }
};
using (var ignite = Ignition.Start(cfg))
{
...
}
An implementation of ILifecycleHandler may look like the following:
class LifecycleExampleHandler : ILifecycleHandler
{
public void OnLifecycleEvent(LifecycleEventType evt)
{
if (evt == LifecycleEventType.AfterNodeStart)
Started = true;
else if (evt == LifecycleEventType.AfterNodeStop)
Started = false;
}
public bool Started { get; private set; }
}
You can inject Ignite instance and other useful resources into a ILifecycleHandler implementation.
Lifecycle Event Types
The following lifecycle event types are supported:
| Event Type | Description |
|---|---|
| BeforeNodeStart | Invoked before Ignite node startup routine is initiated. |
| AfterNodeStart | Invoked right after Ignite node has started. |
| BeforeNodeStop | Invoked right before Ignite stop routine is initiated. |
| AfterNodeStop | Invoked right after Ignite node has stopped. |
Updated about 6 years ago
