Accessing a Cache From an Adapter

12-36 Oracle Complex Event Processing Developers Guide These user-defined functions are implemented as standard Java classes and are declared in the EPN assembly file using the standard Spring bean tags, as shown in the following example: bean id=orderFunction class=orderFunction-impl-class The processor in which the relevant EPL rule runs must then be injected with the user-defined function using the wlevs:function child element, referencing the Spring with the ref attribute: wlevs:processor id= tradeProcessor wlevs:function ref=orderFunction wlevs:processor The following EPL rule, assumed to be configured for the tradeProcessor processor, shows how to invoke the existsOrder method of the orderFunction user-defined function: INSERT INTO InstitutionalOrder SELECT er.orderKey AS key, er.symbol AS symbol, er.shares as cumulativeShares FROM ExecutionRequest er RETAIN 8 HOURS WITH UNIQUE KEY WHERE NOT orderFunction.existsOrderer.orderKey You can also configure the user-defined function to access a cache by injecting the function with a cache using the standard Spring mechanism for referencing another bean. A cache bean implements the java.util.Map interface which is what the user-defined function uses to access the injected cache. First, the configuration of the user-defined function in the EPN assembly file must be updated with a wlevs:property child element, as shown in the following example: wlevs:caching-system id=caching-system-id ... wlevs:cache id=cache-id name=alternative-cache-name wlevs:caching-system ref=caching-system-id wlevs:cache ... bean id=orderFunction class=orderFunction-impl-class wlevs:property name=cache ref=cache-id bean In the example, the ref attribute of the wlevs:property element references the id value of the wlevs:cache element. Oracle CEP automatically injects the cache, implemented as a java.util.Map, into the user-defined function. In the user-defined functions Java source, add a setMap Map method with the code that implements whatever you want the function to do with the cache: package com.bea.wlevs.example; … import java.util.Map; public class OrderFunction { ... public void setMap Map map {...} } For more information on user-defined functions, see User-Defined Functions in the Oracle Complex Event Processing EPL Language Reference.

12.11 Accessing a Cache Using JMX

At runtime, you can access a cache programatically using JMX and the MBeans that Oracle CEP deploys for the caching systems and caches you define. Configuring Caching 12-37 This section describes: ■ Section 12.11.1, How to Access a Cache With JMX Using Oracle CEP Visualizer ■ Section 12.11.2, How to Access a Cache With JMX Using Java For more information, Configuring JMX for Oracle CEP in the Oracle Complex Event Processing Administrators Guide

12.11.1 How to Access a Cache With JMX Using Oracle CEP Visualizer

The simplest and least error-prone way to access a caching system or cache with JMX is to use the Oracle CEP Visualizer. For more information, see Server and Domain Tasks in the Oracle Complex Event Processing Visualizer Users Guide.

12.11.2 How to Access a Cache With JMX Using Java

The simplest and least error-prone way to access a caching system or cache with JMX is to use the Oracle CEP Visualizer see Section 12.11.1, How to Access a Cache With JMX Using Oracle CEP Visualizer . Alternatively, you can access a caching system or cache with JMX using Java code that you write. Oracle CEP creates a StageMBean for each cache that your application uses as a stage. The Type of this MBean is Stage. To access a cache with JMX using Java: 1. Connect to the JMX service that Oracle CEP server provides. For more information, see Configuring JMX for Oracle CEP in the Oracle Complex Event Processing Administrators Guide 2. Get a list of cache StageMbean using either of: ■ CachingSystemMBean.getCacheMBeans ■ ApplicationMBean.getStageMBeans 3. Get the ObjectName for a given StageMBean that represents a cache in your caching system: ObjectName cacheName = ObjectName.getInstance com.bea.wlevs:Name = newCache,Type=Stage,CachingSystem=newCachingSystem,Application=provider ; 4. Get a proxy instance for the StageMBean with this ObjectName: StageMBean cache = StageMBean MBeanServerInvocationHandler.newProxyInstance server, cacheName, StageMBean.class, false ; 5. Use the methods of the StageMBean to access the cache. 12-38 Oracle Complex Event Processing Developers Guide