Overview
GridLifecycleBean ![]()
![]()
There are four events you can react to:
- GridLifecycleEventType.BEFORE_GRID_START invoked before grid startup routine is initiated. Note that grid is not available during this event, therefore if you injected a grid instance via GridInstanceResource
Javadoc annotation, you cannot use it yet.
- GridLifecycleEventType.AFTER_GRID_START invoked right after grid has started. At this point, if you injected a grid instance via GridInstanceResource
Javadoc annotation, you can start using it.
- GridLifecycleEventType.BEFORE_GRID_STOP invoked right before grid stop routine is initiated. Grid is still available at this stage, so if you injected a grid instance via GridInstanceResource
Javadoc annotation, you can use it.
- GridLifecycleEventType.AFTER_GRID_STOP invoked right after grid has stopped. Note that grid is not available during this event.
Resource Injection
Lifecycle beans can be injected using IoC (dependency injection) with grid resources. Both, field and method based injection are supported. The following grid resources can be injected:
- GridLoggerResource
Javadoc 
- GridLocalNodeIdResource
Javadoc 
- GridHomeResource
Javadoc 
- GridMBeanServerResource
Javadoc 
- GridExecutorServiceResource
Javadoc 
- GridMarshallerResource
Javadoc 
- GridSpringApplicationContextResource
Javadoc 
- GridSpringResource
Javadoc 
- GridInstanceResource
Javadoc 
Refer to Resources Injection documentation for more information.
Usage
If you need to tie your application logic into GridGain lifecycle, you can configure lifecycle beans via standard grid configuration, add your application library dependencies into GRIDGAIN_HOME/libs/ext folder, and simply start GRIDGAIN_HOMNE/gridgain.(sh|bat) scripts.
Configuration
Grid lifecycle beans can be configured programmatically as follows:
Collection<GridLifecycleBean> lifecycleBeans = new ArrayList<GridLifecycleBean>(); Collections.addAll(lifecycleBeans, new FooBarLifecycleBean1(), new FooBarLifecycleBean2()); GridConfigurationAdapter cfg = new GridConfigurationAdapter(); cfg.setLifecycleBeans(lifecycleBeans); // Start grid with given configuration. GridFactory.start(cfg);
or from Spring XML configuration file as follows:
<bean id="grid.cfg" class="org.gridgain.grid.GridConfigurationAdapter" scope="singleton"> ... <property name="lifecycleBeans"> <list> <bean class="foo.bar.FooBarLifecycleBean1"/> <bean class="foo.bar.FooBarLifecycleBean2"/> </list> </property> ... </bean>

For more information about using Spring framework for configuration click here.
