Package org.apache.ignite.lifecycle
Interface LifecycleBean
-
- All Known Implementing Classes:
PlatformDotNetLifecycleBean
,org.apache.ignite.internal.processors.platform.lifecycle.PlatformLifecycleBean
public interface LifecycleBean
A bean that reacts to node lifecycle events defined inLifecycleEventType
. Use this bean whenever you need to plug some custom logic before or after node startup and stopping routines.There are four events you can react to:
-
LifecycleEventType.BEFORE_NODE_START
invoked before node startup routine is initiated. Note that node is not available during this event, therefore if you injected a ignite instance viaIgniteInstanceResource
annotation, you cannot use it yet. -
LifecycleEventType.AFTER_NODE_START
invoked right after node has started. At this point, if you injected a node instance viaIgniteInstanceResource
annotation, you can start using it. Note that you should not be usingIgnition
to get node instance from lifecycle bean. -
LifecycleEventType.BEFORE_NODE_STOP
invoked right before node stop routine is initiated. Node is still available at this stage, so if you injected a ignite instance viaIgniteInstanceResource
annotation, you can use it. -
LifecycleEventType.AFTER_NODE_STOP
invoked right after node has stopped. Note that node is not available during this event.
Resource Injection
Lifecycle beans can be injected using IoC (dependency injection) with ignite resources. Both, field and method based injection are supported. The following ignite resources can be injected: Refer to corresponding resource documentation for more information.Usage
If you need to tie your application logic into Ignition lifecycle, you can configure lifecycle beans via standard node configuration, add your application library dependencies intoIGNITE_HOME/libs
folder, and simply startIGNITE_HOME/ignite.{sh|bat}
scripts.Configuration
Node lifecycle beans can be configured programmatically as follows:IgniteConfiguration cfg = new IgniteConfiguration(); cfg.setLifecycleBeans(new FooBarLifecycleBean1(), new FooBarLifecycleBean2()); // Start grid with given configuration. Ignition.start(cfg);
or from Spring XML configuration file as follows:<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> ... <property name="lifecycleBeans"> <list> <bean class="foo.bar.FooBarLifecycleBean1"/> <bean class="foo.bar.FooBarLifecycleBean2"/> </list> </property> ... </bean>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
onLifecycleEvent(LifecycleEventType evt)
This method is called when lifecycle event occurs.
-
-
-
Method Detail
-
onLifecycleEvent
void onLifecycleEvent(LifecycleEventType evt) throws IgniteException
This method is called when lifecycle event occurs.- Parameters:
evt
- Lifecycle event.- Throws:
IgniteException
- Thrown in case of any errors.
-
-