The coherence-cache-config.xml File

12-20 Oracle Complex Event Processing Developers Guide Refer to your Oracle Coherence documentation see http:www.oracle.comtechnologyproductscoherenceindex.html for detailed information about the tangosol-coherence-override.xml file. For more information on Oracle CEP clusters, see Administrating Multi-Server Domains With Oracle CEP Native Clustering in the Oracle Complex Event Processing Administrators Guide.

12.3.2 Configuring an Oracle Coherence Cache as an Event Listener

An Oracle Coherence cache can be configured as an explicit listener in the event processing network in order to receive events. For example, to specify that a cache listens to a channel, specify the wlevs:listener element with a reference to the cache as a child of the wlevs:channel element as shown below: wlevs:coherence-caching-system id=caching-system-id ... wlevs:cache id=cache-id name=alternative-cache-name wlevs:caching-system ref=caching-system-id wlevs:cache ... wlevs:channel id=tradeStream wlevs:listener ref=cache-id wlevs:channel As the channel sends new events to the cache, they are inserted into the cache. If a remove event an old event that exits the output window is sent by the channel, then the event is removed from the cache.

12.3.2.1 Specifying the Key Used to Index an Oracle Coherence Cache

When you configure an Oracle Coherence cache to be a listener, events are inserted into the cache. This section describes the variety of options available to you to specify the key used to index a cache in this instance. If you do not explicitly specify a key, the event object itself serves as both the key and value when the event is inserted into the cache. In this case, the event class must include a valid implementation of the equals and hashcode methods that take into account the values of the key properties. See the following for ways to explicitly specify a key: ■ Section 12.3.2.1.1, Specifying a Key Property in EPN Assembly File ■ Section 12.3.2.1.2, Using a Metadata Annotation to Specify a Key ■ Section 12.3.2.1.3, Specifying a Composite Key

12.3.2.1.1 Specifying a Key Property in EPN Assembly File The first option is to specify a

property name for the key property when a cache is declared in the EPN assembly file using the key-properties attribute, as shown in the following example: wlevs:cache id=myCache key-properties=key-property-name wlevs:caching-system ref=caching-system-id wlevs:cache In this case, all events that are inserted into the cache are required to have a property of this name at runtime, otherwise Oracle CEP throws an exception. For example, assume the event type being inserted into the cache looks something like the following; note the key property only relevant Java source shown: Configuring Caching 12-21 public class MyEvent { private String key; public MyEvent { } public MyEventString key { this.key = key; } public String getKey { return key; } public void setKeyString key { this.key = key; } ... } The corresponding declaration in the EPN assembly file would look like the following: wlevs:cache id=myCache key-properties=key wlevs:caching-system ref=caching-system-id wlevs:cache

12.3.2.1.2 Using a Metadata Annotation to Specify a Key The second option is to use the

metadata annotation com.bea.wlevs.ede.api.Key to annotate the event property in the Java class that implements the event type. This annotation does not have any attributes. To use a metadata annotation to specify a key: 1. Import the com.bea.wlevs.ede.api.Key package. For more information, see Section 4.7.5, How to Import a Package . 2. Apply the Key annotation to a method. The following example shows how to specify that the key property of the MyEvent event type is the key; only relevant code is shown: import com.bea.wlevs.ede.api.Key; public class MyEvent { private String key; public MyEvent { } public MyEventString key { this.key = key; } public String getKey { return key; } Key public void setKeyString key { this.key = key; } ... } 12.3.2.1.3 Specifying a Composite Key The final option is to use the key-class attribute of the wlevs:cache element to specify a composite key in which multiple properties form the key. The value of the key-class attribute must be a JavaBean whose public fields match the fields of the event class. The matching is done according to the field name. For example: wlevs:cache id=myCache key-class=key-class-name wlevs:caching-system ref=caching-system-id 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.