Skip Headers
Oracle® Coherence Developer's Guide
Release 3.7.1

Part Number E22837-01
Go to Documentation Home
Go to Book List
Book List
Go to Table of Contents
Go to Feedback page
Contact Us

Go to previous page
Go to next page
View PDF

25 Managing Map Operations with Triggers

Map triggers supplement the standard capabilities of Oracle Coherence to provide a highly customized cache management system. For example, map triggers can prevent invalid transactions, enforce complex security authorizations or complex business rules, provide transparent event logging and auditing, and gather statistics on data modifications. Other possible use for triggers include restricting operations against a cache to those issued during application re-deployment time.






Example 25-1 Example MapTriggerListener Configuration



The MapTriggerListener is a special purpose MapListener implementation that is used to register a MapTrigger with a corresponding NamedCache. In Example 25-2, MapTriggerListener is used to register the PersonMapTrigger with the People named cache.

Example 25-2 A MapTriggerListener Registering a MapTrigger with a Named Cache

NamedCache person = CacheFactory.getCache("People");
MapTrigger trigger = new PersonMapTrigger();
person.addMapListener(new MapTriggerListener(trigger));

These API reside in the com.tangosol.util package. For more information on these API, see the Javadoc pages for MapTrigger, MapTrigger.Entry, FilterTrigger, and MapTriggerListener.

25.1 A Map Trigger Example

The code in Example 25-3 illustrates a map trigger and how it can be called. In the PersonMapTrigger class in Example 25-3, the process method is implemented to modify an entry before it is placed in the map. In this case, the last name attribute of a Person object is converted to upper case characters. The object is then returned to the entry.

Example 25-3 A MapTrigger Class


public class PersonMapTrigger implements MapTrigger 
    public PersonMapTrigger()

    public void process(MapTrigger.Entry entry)
        Person person  = (Person) entry.getValue();
        String sName   = person.getLastName();
        String sNameUC = sName.toUpperCase();
        if (!sNameUC.equals(sName))


    public boolean equals(Object o)
    public int hashCode()

The MapTrigger in Example 25-4, calls the PersonMapTrigger. The new MapTriggerListener passes the PersonMapTrigger to the People NamedCache.

Example 25-4 Calling a MapTrigger and Passing it to a Named Cache


public class MyFactory
    * Instantiate a MapTriggerListener for a given NamedCache
    public static MapTriggerListener createTriggerListener(String sCacheName)
        MapTrigger trigger;
        if ("People".equals(sCacheName))
            trigger = new PersonMapTrigger();
            throw IllegalArgumentException("Unknown cache name " + sCacheName);

        System.out.println("Creating MapTrigger for cache " + sCacheName);

        return new MapTriggerListener(trigger);

    public static void main(String[] args) 
        NamedCache cache = CacheFactory.getCache("People");

        System.out.println("Installed MapTrigger into cache People");