The tangosol-coherence-override.xml File

12-22 Oracle Complex Event Processing Developers Guide wlevs:cache

12.3.3 Configuring an Oracle Coherence Cache as an Event Source

You can configure an Oracle Coherence cache as a source of events to which another component in the event processing network listens. The listening component can be an adapter or a standard Spring bean. Any component that listens to a cache must implement the com.tangosol.util.MapListener interface. The following example shows how to configure an Oracle Coherence cache to be an event source for a Spring bean: wlevs:coherence-caching-system id=caching-system-id ... wlevs:cache id=myCache advertise=false wlevs:caching-system ref=caching-system-id wlevs:cache-loader ref=localLoader wlevs:cache-listener ref=localListener wlevs:cache bean id=localListener class=com.bea.wlevs.example.provider.coherence.LocalListener In the example, the cache-listener-id Spring bean listens to events coming from the cache; the class that implements this component, com.bea.wlevs.example.provider.coherence.LocalListener, must implement the appropriate Oracle Coherence-specific Java interfaces such as com.tangosol.util.MapListener. You must program this LocalListener class yourself as Example 12–6 shows. Example 12–6 Oracle Coherence Cache LocalListener Implementation package com.bea.wlevs.example.provider.coherence; import com.tangosol.util.MapEvent; import com.tangosol.util.MapListener; public class LocalListener implements MapListener { public static int deleted = 0; public static int inserted = 0; public static int updated = 0; public void entryDeletedMapEvent event { deleted++; } public void entryInsertedMapEvent event { inserted++; } public void entryUpdatedMapEvent event { updated++; } }

12.3.4 Configuring an Oracle Coherence Cache Loader or Store

Using an Oracle Coherence cache, you may configure either a wlevs:cache-loader or a wlevs:cache-store child element of the wlevs:cache element in the EPN assembly file, but not both. This is because Oracle Coherence combines the loader and store into a single component: ■ Specify a cache loader when the backing store is read-only. See Section 12.3.4.1, Configuring an Oracle Coherence Cache Loader. ■ Specify a cache store when the backing store is read-write. Configuring Caching 12-23 See Section 12.3.4.2, Configuring an Oracle Coherence Cache Store.

12.3.4.1 Configuring an Oracle Coherence Cache Loader

In Example 12–7 , the localLoader Spring bean loads events into the oracle Coherence cache when the backing store is read-only. If the backing store is read-write, use a cache store see Section 12.3.4.2, Configuring an Oracle Coherence Cache Store . The class that implements this component, com.bea.wlevs.example.provider.coherence.LocalLoader, must implement the appropriate Oracle Coherence-specific Java interfaces such as com.tangosol.net.cache.CacheLoader. You must program this LocalLoader class yourself as Example 12–8 shows. Example 12–7 Oracle Coherence Cache EPN Assembly File for a Cache Loader wlevs:coherence-caching-system id=caching-system-id wlevs:cache id=myCache advertise=false wlevs:caching-system ref=caching-system-id wlevs:cache-loader ref=localLoader wlevs:cache bean id=localLoader class=com.bea.wlevs.example.provider.coherence.LocalLoader Example 12–8 Oracle Coherence Cache LocalLoader Implementation package com.bea.wlevs.example.provider.coherence; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import com.bea.wlevs.example.provider.event.ProviderData; import com.tangosol.net.cache.CacheLoader; public class LocalLoader implements CacheLoader { public static int loadCount = 0; public static Set keys = new HashSet; public LocalLoader { } public Object loadObject key { loadCount++; keys.addkey; return new ProviderDataString key; } public Map loadAllCollection keys { Map result = new HashMap; for Object key : keys { result.putkey, loadkey; } return result; } }