Program guide > Programming with system APIs and plug-ins > Event listener plug-ins



MapEventListener plug-in

A MapEventListener plug-in provides callback notifications and significant cache state changes that occur for a BackingMap object: when a map has finished pre-loading or when an entry is evicted from the map. A particular MapEventListener plug-in is a custom class you write implementing the MapEventListener interface.


MapEventListener plug-in conventions

When you develop a MapEventListener plug-in, follow common plug-in conventions. For more information about plug-in conventions, see Introduction to plug-ins. For other types of listener plug-ins, see Plug-ins for providing event listeners.

After you write a MapEventListener implementation, you can plug it in to the BackingMap configuration programmatically or with an XML configuration.


Write a MapEventListener implementation

Your application can include an implementation of the MapEventListener plug-in. The plug-in must implement the MapEventListener interface to receive significant events about a map. Events are sent to the MapEventListener plug-in when an entry is evicted from the map and when the preload of a map completes.


Programmatically plug in a MapEventListener implementation

The class name for the custom MapEventListener is the com.company.org.MyMapEventListener class. This class implements the MapEventListener interface. The following code snippet creates the custom MapEventListener object and adds it to a BackingMap object:

ObjectGridManager objectGridManager =
    ObjectGridManagerFactory.getObjectGridManager();
ObjectGrid myGrid = objectGridManager.createObjectGrid("myGrid", false);
BackingMap myMap = myGrid.defineMap("myMap");
MyMapEventListener myListener = new MyMapEventListener();
myMap.addMapEventListener(myListener);


Plug in a MapEventListener implementation using XML

A MapEventListner implementation can be configured using XML. The following XML 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">
           
<backingMap name="myMap" pluginCollectionRef="myPlugins" />
       
</objectGrid>
   
</objectGrids>
   
<backingMapPluginCollections>
       
<backingMapPluginCollection id="myPlugins">
           
<bean id="MapEventListener" className=
                            "com.company.org.MyMapEventListener" />
       
</backingMapPluginCollection>
   
</backingMapPluginCollections>
</objectGridConfig>

Providing this file to the ObjectGridManager instance facilitates the creation of this configuration. The following code snippet shows how to create an ObjectGrid instance using this XML file. The newly created ObjectGrid instance has a MapEventListener set on the myMap BackingMap.

ObjectGridManager objectGridManager = 
    ObjectGridManagerFactory.getObjectGridManager();
ObjectGrid myGrid = 
    objectGridManager.createObjectGrid("myGrid", new URL("file:etc/test/myGrid.xml"), 
        true, false);


Parent topic:

Plug-ins for providing event listeners

Related reference

ObjectGridEventListener plug-in