Specifying the Key Used to Index an Oracle Coherence Cache

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; } } 12-24 Oracle Complex Event Processing Developers Guide

12.3.4.2 Configuring an Oracle Coherence Cache Store

In Example 12–9 , the localStore Spring bean loads events into the cache when the backing store is read-write. If the backing store is read-only, use a cache loader see Section 12.3.4.1, Configuring an Oracle Coherence Cache Loader . The class that implements this component, com.bea.wlevs.example.provider.coherence.LocalStore, must implement the appropriate Oracle Coherence-specific Java interfaces such as com.tangosol.net.cache.CacheStore. You must program this LocalStore class yourself as Example 12–10 shows. Example 12–9 Oracle Coherence Cache EPN Assembly File for a Cache Store wlevs:coherence-caching-system id=caching-system-id wlevs:cache id=myCache advertise=false wlevs:caching-system ref=caching-system-id wlevs:cache-store ref=localStore wlevs:cache bean id=localStore class=com.bea.wlevs.example.provider.coherence.LocalStore Example 12–10 Oracle Coherence Cache LocalStore Implementation package com.bea.wlevs.example.provider.coherence; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; import com.bea.wlevs.example.provider.event.ProviderData; import com.tangosol.net.cache.CacheStore; public class LocalStore implements CacheStore { public static int eraseCount = 0; public static int storeCount = 0; public static int loadCount = 0; public void eraseObject key { eraseCount++; } public void eraseAllCollection keys { for Object key : keys { erasekey; } } public void storeObject key, Object value { Do the store operation here. } public void storeAllMap entries { for Map.Entry entry : Set Map.Entryentries.entrySet { storeentry.getKey, entry.getValue; } } public Object loadObject key { loadCount++; return new ProviderDataString key; } public Map loadAllCollection keys { Map result = new HashMap; for Object key : keys { Configuring Caching 12-25 result.putkey, loadkey; } return result; } }

12.3.5 Configuring a Shared Oracle Coherence Cache

When declaring Oracle Coherence caches in the EPN assembly files of one or more applications deployed to the same Oracle CEP server, you should never configure multiple instances of the same cache with a loader or store. You might inadvertently do this by employing multiple applications that each configure the same Oracle Coherence cache with a loader or store in their respective EPN assembly file. If you do this, Oracle CEP throws an exception. If multiple application bundles need to share Oracle Coherence caches, then you should put the EPN assembly file that contains the appropriate wlevs:cache and wlevs:caching-system in a separate bundle and set their advertise attributes to true. To export both the caching system and the cache as an OSGi service, set the advertise attribute to true. wlevs:caching-system id=caching-system-id provider=coherence advertise=true ... wlevs:cache id=cache-id name=alternative-cache-name advertise=true wlevs:caching-system ref=caching-system-id wlevs:cache If the cache is advertised, then a component in the EPN of an application in a separate bundle can then reference it. The following example shows how a processor in one bundle can use as a cache source the cache with ID cache-id located in a separate bundle called cacheprovider: wlevs:processor id=myProcessor2 wlevs:cache-source ref=cacheprovider:cache-id wlevs:processor

12.4 Configuring a Third-Party Caching System and Cache

You can configure your application to use a third-party caching system and cache. To configure a third-party caching system and cache: 1. Create a plug-in to define the third-party caching system as an Oracle CEP caching system provider. This involves: ■ Implementing the com.bea.wlevs.cache.spi.CachingSystem interface ■ Creating a factory that creates caching systems of this type. ■ Registering the factory with an attribute that identifies its provider type. Note: It is assumed in this section that you have already created an Oracle CEP application along with its EPN assembly file and that you want to update the application to use caching. If you have not, refer to Chapter 1, Overview of Creating Oracle CEP Applications for details.