How To Access a Cache From an EPL Statement

Configuring Caching 12-35 wlevs:function ref=orderFunction wlevs:processor Alternatively, you can specify the bean class in the wlevs:function element: wlevs:processor id=testProcessor wlevs:listener ref=providerCache wlevs:listener ref=outputCache wlevs:cache-source ref=testCache wlevs:function function-name=mymod exec-method=”execute” bean class=com.bea.wlevs.example.function.MyMod wlevs:function wlevs:processor The following Oracle CQL 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 [Range 8 hours] 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 Functions: User-Defined in the Oracle Complex Event Processing CQL Language Reference.

12.10 Accessing a Cache From an EPL User-Defined Function

In addition to standard event streams, EPL rules can also invoke the member methods of a user-defined function. 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.