[Java programming language only]

Writing an ObjectGridPlugin plug-in

An ObjectGridPlugin is an optional mix-in interface that you can use to provide extended life cycle management events to all other ObjectGrid plug-ins.

About this task

Any ObjectGrid plug-in that implements the ObjectGridPlugin receives the extended set of life cycle events, and can provide more control, which you can use to set up or remove resources. In a container for a partitioned data grid, there will be one ObjectGrid instance (the plugin owner) for each partition managed by the container.When individual partitions are removed, the resources that are used by that ObjectGrid instance must also be removed. Therefore, you might need to close or end a resource, such as an open configuration file or a running thread that is managed by a plug-in, when the owning partition for that resource is removed.

The ObjectGridPlugin interface provides methods to set or modify the state of the plug-in, as well as methods to introspect the current state of the plug-in. All methods must be implemented correctly, and the WebSphere® eXtreme Scale runtime environment verifies the method behavior under certain circumstances. For example, after calling the initialize() method, the eXtreme Scale runtime environment calls the isInitialized() method to ensure that the method successfully completed the appropriate initialization.

Procedure

  1. Implement the ObjectGridPlugin interface so that the ObjectGridPlugin plug-in receives notifications about significant eXtreme Scale events.
    Three main categories of methods exist:
    Properties methods Purpose
    setObjectGrid() Called to set the ObjectGrid instance the plug-in is used for.
    getObjectGrid() Called to get or confirm the ObjectGrid instance the plug-in is used for.
    Initialization methods Purpose
    initialize() Called to initialize the ObjectGridPlugin.
    isInitialized() Called to get or confirm the initialization status of the plug-in.
    Destruction methods Purpose
    destroy() Called to destroy the ObjectGridPlugin.
    isDestroyed() Called to get or confirm the destroyed status of the plug-in.

    See the API documentation for more information about these interfaces.

  2. Configure an ObjectGridPlugin plug-in with XML.
    Use the com.company.org.MyObjectGridPluginTxCallback class, which implements the TransactionCallback interface and the ObjectGridPlugin interface.
    In the following code example, the custom transaction callback, which will ultimately receive extended life cycle events, is generated and added to an ObjectGrid.
    Important: The TransactionCallback interface already has an initialize method, a new initialize method is added as well as the destroy method and other ObjectGridPlugin methods. Each method is used, and the initialize methods only perform initialization one time. The following XML creates a configuration that uses the enhanced TransactionCallback interface.

    The following text must be in the myGrid.xml file:

    ?xml version="1.0" encoding="UTF-8"?>
    <objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://ibm.com/ws/objectgrid/config ../objectGrid.xsd"
     xmlns="http://ibm.com/ws/objectgrid/config">
        <objectGrids>
            <objectGrid name="myGrid">
                <bean id="TransactionCallback"
                      className="com.company.org.MyObjectGridPluginTxCallback" />
                <backingMap name="Book"/>
            </objectGrid>
        </objectGrids>
    </objectGridConfig>

    Notice the bean declarations come before the backingMap declarations.

  3. Provide the myGrid.xml file to the ObjectGridManager plug-in to facilitate the creation of this configuration.