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.
After you write a MapEventListener implementation, you can plug it in to the BackingMap configuration programmatically or with an XML configuration.
<?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);
ObjectGridManager objectGridManager = ObjectGridManagerFactory.getObjectGridManager(); ObjectGrid myGrid = objectGridManager.createObjectGrid("myGrid", false); BackingMap myMap = myGrid.defineMap("myMap"); MyMapEventListener myListener = new MyMapEventListener(); myMap.addMapEventListener(myListener);