Dashboard > GridGain User Guide > Table Of Contents > Developers Guide > Grid Lifecycle Beans
Grid Lifecycle Beans
Added by dozer, last edited by dozer on Dec 17, 2008
Labels: 
(None)


Overview

GridLifecycleBean Javadoc reacts to grid lifecycle events defined in GridLifecycleEventType Javadoc . Use this bean whenever you need to plug some custom logic before or after grid startup and stopping routines.

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:

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.

Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.10 Build:#528 Nov 29, 2006) - Bug/feature request - Contact Administrators