3 Oracle CEP Samples

This section contains information on the following subjects:

3.1 Overview of the Samples Provided in the Distribution Kit

Oracle CEP includes the following samples:

  • HelloWorld: a basic skeleton of a typical Oracle CEP application.

  • Oracle Continuous Query Language (CQL): an example that shows how to use the Oracle CEP Visualizer Query Wizard to construct various Oracle CQL queries to process event streams.

  • Oracle Spatial: an example that shows how to use the Oracle Spatial data cartridge with Oracle CQL queries to process a stream of Global Positioning System (GPS) events to track the GPS location of buses and generate alerts when a bus arrives at its pre-determined bus stop positions.

  • Foreign Exchange (FX): a complete example that includes multiple components.

  • Signal Generation: an example that simulates market trading and trend detection.

  • Event record and playback: an example that shows how to configure event record and playback using a persistent event store.

These samples are provided in two forms, as follows:

The samples use Ant as their development tool; for details about Ant and installing it on your computer, see http://ant.apache.org/.

Note:

"Additional Oracle CEP sample code can be found at http://www.oracle.com/technology/sample_code/products/event-driven-architecture".

3.1.1 Ready-to-Run Samples

Out-of-the-box sample domains pre-configured to deploy an assembled application; each sample has its own domain for simplicity. Each domain is a standalone server domain; the server files are located in the defaultserver subdirectory of the domain directory. To deploy the application you simply start the default server in the domain.

3.1.2 Sample Source

The Java and configuration XML source for each sample is provided in a separate source directory that describes a sample development environment.

3.2 Installing the Samples

When initially installing Oracle CEP, you must chose the Custom option to also install the samples. The Typical option does not include the samples.

If you previously installed Oracle CEP using the Typical option, and you now want to also install the samples, re-run the Oracle CEP installation process and specify the same Oracle CEP home directory; a later step in the installation process allows you to then install just the samples.

3.3 Using Oracle CEP Visualizer With the Samples

The Oracle CEP Visualizer is a Web 2.0 application that consumes data from Oracle CEP, displays it in a useful and intuitive way to system administrators and operators, and, for specified tasks, accepts data that is then passed back to Oracle CEP so as to change it configuration.

Visualizer is itself an Oracle CEP application and is automatically deployed in each server instance. To use it with the samples, be sure you have started the server (instructions provided for each sample below) and then invoke the following URL in your browser:

   http://host:9002/wlevs

where host refers to the name of the computer hosting Oracle CEP; if it is the same as the computer on which the browser is running you can use localhost.

Security is disabled for the HelloWorld application, so you can click Logon at the login screen without entering a username and password. For the FX and signal generation samples, however, security is enabled, so use the following to logon:

   User Id: wlevs
   Password: wlevs

For more information about Visualizer, see Section 1.8, "Oracle CEP Visualizer".

3.4 Increasing the Performance of the Samples

To increase the throughput and latency when running the samples, and Oracle CEP applications in general, Oracle recommends the following:

  • Use the JRockit JDK included in Oracle JRockit Real Time 3.1.2 and enable the deterministic garbage collector by passing the -dgc parameter to the command that starts the Oracle CEP instance for the appropriate domain:

    prompt> startwlevs.cmd -dgc
    

    By default the deterministic garbage collector is disabled for the samples.

    For more information on Oracle JRockit Real Time 3.1.2, see http://www.oracle.com/technology/products/jrockit/jrrt/index.html.

  • When running Oracle CEP on a computer with a larger amount of memory, you should set the load generator and server heap sizes appropriately for the size of the computer. On computers with sufficient memory, Oracle recommend a heap size of 1 GB for the server and between 512MB - 1GB for the load generator.

3.5 Setting Your Development Environment

You must set your development environment before you can start Oracle CEP instances and run the samples. In particular, you must set the PATH and JAVA_HOME environment variables so that you are using the correct version of the JRockit JDK.

There are two ways in which JRockit might have been installed on your computer:

  • As part of the Oracle JRockit Real Time 3.0 installation. This version of the JRockit JDK includes the deterministic garbage collector.

  • As part of the Oracle CEP 11g Release 1 (11.1.1) installation. This version of the JRockit JDK does not include the deterministic garbage collector, and is provided for testing purposes only.

Although not required, Oracle recommends that you run Oracle CEP using the JRockit JDK version included in Oracle JRockit Real Time 3.0 for best results; however, the following procedures describe how to set your environment for either case.

For more information about JRockit, see Section 3.4, "Increasing the Performance of the Samples".

This section describes:

3.5.1 How to Set Your Development Environment on Windows

This procedure describes how to set your development environment on Windows.

To make it easier to reset your development environment after logging out of a session, you can create a command file, such as setEnv.cmd, that contains the set commands this section describes.

You can also set the required environment variables permanently on your Windows computer by invoking the Control Panel > System window, clicking the Advanced tab, and then clicking the Environment Variables button. You can set the environment variables for the current user or for the entire system.

To set your development environment on Windows:

  1. Update your PATH environment variable to include the bin directory of the JRockit JDK. Also, be sure that your PATH environment variable includes the bin directory of your Ant installation:

    1. If using the JRockit JDK installed with Oracle JRockit Real Time 3.0:

      If you installed Oracle JRockit Real Time 3.0 in the d:\jrockit directory and Ant is installed in the d:\ant directory, set your PATH environment variable as shown:

      prompt> set PATH=d:\jrockit\jrrt-3.0.0-1.6.0\bin;d:\ant\bin;%PATH%
      
    2. If using the JRockit JDK installed with Oracle CEP 11g Release 1 (11.1.1):

      If you installed Oracle CEP in the d:\oracle_cep directory and Ant is installed in the d:\ant directory, set your PATH environment variable as shown:

      prompt> set PATH=d:\oracle_cep\jrockit-R27.6.0-50-1.6.0_05\bin;d:\ant\bin;%PATH%
      
  2. Ensure that the JAVA_HOME variable in the setDomainEnv.cmd script points to the correct JRockit JDK. If it does not, edit the script.

    The setDomainEnv.cmd script is located in the defaultserver subdirectory of the main domain directory; the defaultserver subdirectory contains the files for the standalone server of each domain. For example, the HelloWorld domain is located in ORACLE_CEP_HOME\ocep_11.1\samples\domains\helloworld_domain, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

    1. If using the JRockit JDK installed with Oracle JRockit Real Time 3.0

      The set command should be as follows:

      set JAVA_HOME=d:\jrockit\jrrt-3.0.0-1.6.0
      
    2. If using the JRockit JDK installed with Oracle CEP 11g Release 1 (11.1.1):

      The set command should be as follows:

      set JAVA_HOME=d:\oracle_cep\jrockit-R27.6.0-50-1.6.0_05
      
  3. Set the JAVA_HOME variable in your own development environment to point to the JRockit JDK.

    1. If using the JRockit JDK installed with Oracle JRockit Real Time 3.0:

      The set command should be as follows:

      prompt> set JAVA_HOME=d:\jrockit\jrrt-3.0.0-1.6.0
      
    2. If using the JRockit JDK installed with Oracle CEP 11g Release 1 (11.1.1):

      The set command should be as follows:

      prompt> set JAVA_HOME=d:\oracle_cep\jrockit-R27.6.0-50-1.6.0_05
      

3.5.2 How to Set Your Development Environment on UNIX

This procedure describes how to set your development environment on UNIX.

To make it easier to reset your development environment after logging out of a session, you can create a command file, such as setEnv.sh, that contains the set commands this section describes.

To set your development environment on UNIX:

  1. Update your PATH environment variable to include the bin directory of the JRockit JDK. Also, be sure that your PATH environment variable includes the bin directory of your Ant installation.

    1. If using the JRockit JDK installed with Oracle JRockit Real Time 3.0:

      If you installed Oracle JRockit Real Time in the /jrockit directory and Ant is installed in the /ant directory, set your PATH environment variable as follows:

      prompt> PATH=/jrockit/jrrt-3.0.0-1.6.0/bin:/ant/bin:$PATH
      
    2. If using the JRockit JDK installed with Oracle CEP 10.3

      If you installed Oracle CEP in the /oracle_cep directory and Ant is installed in the /ant directory, set your PATH environment variable as shown:

      prompt> PATH=/oracle_cep/jrockit-R27.6.0-50-1.6.0_05/bin:/ant/bin:$PATH
      
  2. Ensure that the JAVA_HOME variable in the setDomainEnv.sh script points to the correct JRockit JDK. If it does not, edit the script.

    The setDomainEnv.sh script is located in the defaultserver subdirectory of the main domain directory; the defaultserver subdirectory contains the files for the standalone server of each domain. For example, the HelloWorld domain is located in ORACLE_CEP_HOME/ocep_11.1/samples/domains/helloworld_domain, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as /oracle_cep.

    1. If using the JRockit JDK installed with Oracle JRockit Real Time 3.0:

      The JAVA_HOME variable should be set as follows:

      JAVA_HOME=/jrockit/jrrt-3.0.0-1.6.0
      
    2. If using the JRockit JDK installed with Oracle CEP 11g Release 1 (11.1.1):

      The JAVA_HOME variable should be set as follows:

      JAVA_HOME=/oracle_cep/jrockit-R27.6.0-50-1.6.0_05
      
  3. Set the JAVA_HOME variable in your development environment to point to the JRockit JDK.

    1. If using the JRockit JDK installed with Oracle JRockit Real Time 3.0:

      The JAVA_HOME variable should be set as follows:

      prompt> JAVA_HOME=/jrockit/jrrt-3.0.0-1.6.0
      
    2. If using the JRockit JDK installed with Oracle CEP 11g Release 1 (11.1.1):

      The JAVA_HOME variable should be set as follows:

      prompt> JAVA_HOME=/oracle_cep/jrockit-R27.6.0-50-1.6.0_05
      

3.6 HelloWorld Example

The first example that shows how to create an Oracle CEP application is the ubiquitous HelloWorld.

Figure 3-1 shows the HelloWorld example Event Processing Network (EPN). The EPN contains the components that make up the application and how they fit together.

Figure 3-1 The HelloWorld Example Event Processing Network

Description of Figure 3-1 follows
Description of "Figure 3-1 The HelloWorld Example Event Processing Network"

The example includes the following components:

  • helloworldAdapter—Component that generates Hello World messages every second. In a real-world scenario, this component would typically read a stream of data from a source, such as a data feed from a financial institution, and convert it into a stream of events that the complex event processor can understand. The HelloWorld application also includes a HelloWorldAdapterFactory that creates instances of HelloWorldAdapter.

  • helloworldInputChannel—Component that streams the events generated by the adapter (in this case Hello World messages) to the complex event processor.

  • helloworldProcessor—Component that simply forwards the messages from the helloworldAdapter component to the POJO that contains the business logic. In a real-world scenario, this component would typically execute additional and possibly much more complex processing of the events from the stream, such as selecting a subset of events based on a property value, grouping events, and so on using Oracle CQL.

  • helloworldOutputChannel—Component that streams the events processed by the complex event processor to the POJO that contains the user-defined business logic.

  • helloworldBean—POJO component that simply prints out a message every time it receives a batch of messages from the processor via the output channel. In a real-world scenario, this component would contain the business logic of the application, such as running reports on the set of events from the processor, sending appropriate emails or alerts, and so on.

3.6.1 Running the HelloWorld Example from the helloworld Domain

The HelloWorld application is pre-deployed to the helloworld domain. To run the application, you simply start an instance of Oracle CEP server.

To run the HelloWorld example from the helloworld domain:

  1. Open a command window and change to the default server directory of the helloworld domain directory, located in ORACLE_CEP_HOME\ocep_11.1\samples\domains\helloworld_domain\defaultserver, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

    prompt> cd d:\oracle_cep\ocep_11.1\samples\domains\helloworld_domain\defaultserver
    
  2. Ensure the environment is set correctly in the server startup script.

    For more information, see Section 3.5, "Setting Your Development Environment."

  3. Start Oracle CEP by executing the appropriate script with the correct command line arguments:

    1. On Windows:

      • If you are using the JRockit JDK included in Oracle JRockit Real Time 3.0, enable the deterministic garbage collector by passing the -dgc parameter to the command:

        prompt> startwlevs.cmd -dgc
        
      • If you are not using the JRockit JDK included in Oracle JRockit Real Time 3.0:

        prompt> startwlevs.cmd
        
    2. On UNIX:

      • If you are using the JRockit JDK included in Oracle JRockit Real Time 3.0, enable the deterministic garbage collector by passing the -dgc parameter to the command:

        prompt> startwlevs.sh -dgc
        
      • If you are not using the JRockit JDK included in Oracle JRockit Real Time 3.0:

        prompt> startwlevs.sh
        

    After server status messages scroll by, you should see the following message printed to the output about every second:

    Message: HelloWorld - the current time is: 3:56:57 PM
    

    This message indicates that the HelloWorld example is running correctly.

3.6.2 Building and Deploying the HelloWorld Example from the Source Directory

The HelloWorld sample source directory contains the Java source, along with other required resources such as configuration XML files, that make up the HelloWorld application. The build.xml Ant file contains targets to build and deploy the application to the helloworld domain.

For more information, see Section 3.6.3, "Description of the Ant Targets to Build Hello World".

To build and deploy the HelloWorld example from the source directory:

  1. If the helloworld Oracle CEP instance is not already running, follow the procedure in Section 3.6.1, "Running the HelloWorld Example from the helloworld Domain" to start the server.

    You must have a running server to successfully deploy the rebuilt application.

  2. Open a new command window and change to the HelloWorld source directory, located in ORACLE_CEP_HOME\ocep_11.1\samples\source\applications\helloworld where ORACLE_CEP_HOME is the directory in which you installed Oracle CEP.

    For example:

    prompt> cd d:\oracle_cep\ocep_11.1\samples\source\applications\helloworld
    
  3. Set your development environment.

    For more information, see Section 3.5, "Setting Your Development Environment."

  4. Execute the all Ant target to compile and create the application JAR file:

    prompt> ant all
    
  5. Execute the deploy Ant target to deploy the application JAR file to Oracle CEP:

    prompt> ant -Daction=update deploy
    

    Caution:

    This target overwrites the existing helloworld application JAR file in the domain directory.

You should see the following message printed to the output about every second:

    Message: HelloWorld - the current time is: 3:56:57 PM

This message indicates that the HelloWorld example has been redeployed and is running correctly.

3.6.3 Description of the Ant Targets to Build Hello World

The build.xml file, located in the top level of the HelloWorld source directory, contains the following targets to build and deploy the application:

  • clean—This target removes the dist and output working directories under the current directory.

  • all—This target cleans, compiles, and JARs up the application into a file called com.bea.wlevs.example.helloworld_3.0.0.0.jar, and places the generated JAR file into a dist directory below the current directory.

  • deploy—This target deploys the JAR file to Oracle CEP using the Deployer utility.

    For more information, see "Deployer Command-Line Reference" in the Oracle CEP Administrator's Guide.

3.6.4 Implementation of the HelloWorld Example

The implementation of the HelloWorld example generally follows "Creating Oracle CEP Applications: Typical Steps" in the Oracle CEP Developer's Guide for Eclipse.

Refer to that section for a task-oriented procedure that describes the typical development process.

The HelloWorld example, because it is relatively simple, does not use all the components and configuration files described in the general procedure for creating an Oracle CEP application.

All the example files are located relative to the ORACLE_CEP_HOME\ocep_11.1\samples\source\applications\helloworld directory, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory such as c:\oracle_cep. Oracle recommends that you use this example directory setup in your own environment, although it is obviously not required.

The files used by the HelloWorld example include:

  • An EPN assembly file that describes each component in the application and how all the components are connected together. The EPN assembly file extends the standard Spring context file. The file also registers the event types used in the application. You are required to include this XML file in your Oracle CEP application.

    In the example, the file is called com.bea.wlevs.example.helloworld-context.xml and is located in the META-INF/spring directory.

    For details, see Section 3.6.5, "The HelloWorld EPN Assembly File."

  • Java source file for the helloworldAdapter component.

    In the example, the file is called HelloWorldAdapter.java and is located in the src/com/bea/wlevs/adapter/example/helloworld directory.

    For a detailed description of this file and how to program the adapter Java files in general, see "Programming Adapters and Event Bean Classes as Event Sources: Guidelines" in the Oracle CEP Developer's Guide for Eclipse.

  • Java source file that describes the HelloWorldEvent event type.

    In the example, the file is called HelloWorldEvent.java and is located in the src/com/bea/wlevs/event/example/helloworld directory.

    For a detailed description of this file, as well as general information about programming event types, see "Creating the Event Types" in the Oracle CEP Developer's Guide for Eclipse.

  • An XML file that configures the helloworldProcessor and helloworldOutputChannel components. An important part of this file is the set of EPL rules that select the set of events that the HelloWorld application processes. You are required to include a processor configuration file in your Oracle CEP application, although the adapter and channel configuration is optional.

    In the example, the file is called config.xml and is located in the META-INF/wlevs directory.

    For details, see Section 3.6.6, "The HelloWorld Component Configuration File."

  • A Java file that implements the helloworldBean component of the application, a POJO that contains the business logic.

    In the example, the file is called HelloWorldBean.java and is located in the src/com/bea/wlevs/example/helloworld directory.

    For a detailed description of this file, as well as general information about programming event sinks, see "Programming Event Sinks: Guidelines" in the Oracle CEP Developer's Guide for Eclipse.

  • A MANIFEST.MF file that describes the contents of the OSGi bundle that will be deployed to Oracle CEP.

    In the example, the MANIFEST.MF file is located in the META-INF directory.

    For more information about creating this file, as well as a description of creating the OSGi bundle that you deploy to Oracle CEP, see "Overview of Application Assembly and Deployment" in the Oracle CEP Developer's Guide for Eclipse.

The HelloWorld example uses a build.xml Ant file to compile, assemble, and deploy the OSGi bundle; see Section 3.6.2, "Building and Deploying the HelloWorld Example from the Source Directory" for a description of this build.xml file if you also use Ant in your development environment.

3.6.5 The HelloWorld EPN Assembly File

One of the main purposes of the EPN assembly file is to define the event processing network by declaring the components of the application and how they are all connected, or in other word, which components listen to which other components. Oracle CEP provides a set of custom Spring tags used to declare the network. You also use the EPN assembly file to register the event types used by your application and its EPL rules.

You use the EPN assembly file in the typical way to define the application component beans in the Spring application context; the application components beans are those implemented with Java classes, such as adapters and the POJO that contains the business logic.

For more information, see:

Example 3-1 shows the EPN assembly file used in the HelloWorld sample application; see the explanation after the example for details about the entries in bold.

Example 3-1 HelloWorld EPN Assembly File

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xmlns:wlevs="http://www.bea.com/ns/wlevs/spring"
       xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/osgi
  http://www.springframework.org/schema/osgi/spring-osgi.xsd
  http://www.bea.com/ns/wlevs/spring
  http://www.bea.com/ns/wlevs/spring/spring-wlevs-v11_1_1_3.xsd">
    <wlevs:event-type-repository>
        <wlevs:event-type type-name="HelloWorldEvent">
            <wlevs:class>com.bea.wlevs.event.example.helloworld.HelloWorldEvent</wlevs:class>
        </wlevs:event-type>
    </wlevs:event-type-repository>
    <wlevs:adapter id="helloworldAdapter" class="com.bea.wlevs.adapter.example.helloworld.HelloWorldAdapter" >
        <wlevs:instance-property name="message" value="HelloWorld - the currenttime is:"/>
    </wlevs:adapter>
    <wlevs:processor id="helloworldProcessor" />
    <wlevs:channel id="helloworldInstream" >
        <wlevs:listener ref="helloworldProcessor"/>
        <wlevs:source ref="helloworldAdapter"/>
    </wlevs:channel>
    <wlevs:channel id="helloworldOutstream" manageable="true">
        <wlevs:listener>
            <bean class="com.bea.wlevs.example.helloworld.HelloWorldBean"/>
        </wlevs:listener>
        <wlevs:source ref="helloworldProcessor"/>
    </wlevs:channel>
</beans>

In the preceding example:

  • The wlevs:event-type-repository element registers the event types that are used throughout the application; in the HelloWorld application, there is just a single event type: HelloWorldEvent, implemented with the com.bea.wlevs.event.example.helloworld.HelloWorldEvent class. Oracle CEP automatically creates instances of this data type when needed. You can also reference this data type in the EPL rules of the application.

  • The wlevs:adapter, wlevs:processor, and wlevs:channel elements together define the event processor network by declaring each component in the network:

    • The wlevs:adapter element defines the adapter component of the HelloWorld application:

      <wlevs:adapter id="helloworldAdapter" 
            class="com.bea.wlevs.adapter.example.helloworld.HelloWorldAdapter" >
          <wlevs:instance-property name="message" value="HelloWorld - the currenttime is:"/>
      </wlevs:adapter>
      

      The id attribute specifies a unique identifier for this component; the id will be referenced later by other components. The class attribute specifies the class that implements the adapter; in this case it is com.bea.wlevs.adapter.example.helloworld.HelloWorldAdapter.

      The wlevs:instance-property child element passes an instance variable to the adapter instance; the name of the variable is message and the value is HelloWorld - the current time is: .

    • The wlevs:processor element defines the processor component of the application:

      <wlevs:processor id="helloworldProcessor" />
      

      The id attribute functions the same as that of wlevs:adapter element.

    • The wlevs:channel elements define the two channel components of the application:

      <wlevs:channel id="helloworldInstream" >
          <wlevs:listener ref="helloworldProcessor"/>
          <wlevs:source ref="helloworldAdapter"/>
      </wlevs:channel>
      <wlevs:channel id="helloworldOutstream" manageable="true">
          <wlevs:listener>
              <bean class="com.bea.wlevs.example.helloworld.HelloWorldBean"/>
          </wlevs:listener>
          <wlevs:source ref="helloworldProcessor"/>
      </wlevs:channel>
      

      The id attribute for streams functions the same as that of wlevs:adapter. The manageable attribute enables monitoring of the channel; by default the manageability of components is disabled.

      The wlevs:channel element with id="helloworldInstream" uses the wlevs:listener child element to specify that the helloworldProcessor listens to the channel, and the wlevs:source child element to specify that the channel gets its events from the helloworldAdapter component.

      The wlevs:channel element with id="helloworldOutstream" also uses these listener and source tags. One difference, however, is that it directly nests the definition of the business logic POJO in the wlevs:listener element rather than reference a unique identifier. In this case, the nested tag is a standard Spring bean element that specifies that the POJO is implemented with the com.bea.wlevs.example.helloworld.HelloWorldBean class.

3.6.6 The HelloWorld Component Configuration File

The HelloWorld application configures the processor in the component configuration file that Example 3-2 shows.

Example 3-2 HelloWorld Component Configuration File

<?xml version="1.0" encoding="UTF-8"?><n1:config xmlns:n1="http://www.bea.com/ns/wlevs/config/application"           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  <processor>    <name>helloworldProcessor</name>    <rules>      <query id="helloworldRule">        <![CDATA[ select * from helloworldInputChannel ]]>      </query>    </rules>  </processor></n1:config>

If your application contains multiple processors, adapters or streams, you can either declare them all in a single configuration file, or create separate configuration files for each component; the method you chose depends on which you find easier to manage.

For each component you configure, you must add the name child element to explicitly declare the specific component to which you are referring. The value of the name element must correspond to the component's unique identifier of its declaration in the EPN assembly file.

For example, assume a processor is declared in the EPN assembly file as follows:

<wlevs:processor id="helloworldProcessor" ...>

Then its corresponding XML configuration would be as follows:

<processor>
    <name>helloworldProcessor</name>
    ...
</processor>

The HelloWorld example uses a single configuration file for one processor with the name helloworldProcessor. This name corresponds with the declaration of the components in the EPN assembly file.

The processor element configures the processor component. The most important part of the processor configuration is the declaration of the set of Oracle Continuous Query Language (Oracle CQL) rules that this processor executes; these rules select the set of events that are eventually passed to the application business object. Each rule is declared with a query or relation element using an XML <![CDATA[...]]> section; all query and relation elements are grouped together within a single rules element. You can define as many rules as you want for a particular processor.

The HelloWorld application has a single, very simple rule:

select * from helloworldInputChannel

The purpose of this query is to show how to pass input data through as is (without manipulation) and output this data as a stream (not a relation). That is why this query does not use a window operator (such as [now] or [range 1]). With a window operator, the output is a relation and not a stream. Consider the downstream HelloWorldBean POJO: it only implements StreamSink (and not RelationSink) because the output of this query is a stream (not a relation generated by a window operator). Consequently, the HelloWorldBean POJO prints only the insert events. It will not print the delete events since it does not implement RelationSink.Typically, you create queries (and views) that output relations (using a window operator) for consumption by subsequent queries or views that produce streams.

For additional information and samples about using Oracle CEP query languages, see:

Note:

Oracle EPL is superseded by Oracle CQL.

3.7 Oracle Continuous Query Language (CQL) Example

The CQL example shows how to use the Oracle CEP Visualizer Query Wizard to construct various types of Oracle CQL queries.

Figure 3-2 shows the CQL example Event Processing Network (EPN). The EPN contains the components that make up the application and how they fit together.

Figure 3-2 The CQL Example Event Processing Network

Description of Figure 3-2 follows
Description of "Figure 3-2 The CQL Example Event Processing Network"

The application contains three separate event paths in its EPN:

  • Missing events: this event path consists of an adapter orderCVSAdapter connected to a channel orderChannel. The orderChannel is connected to processor orderProcessor which is connected to channel alertChannel which is connected to adapter alertOutput.

    This event path is used to detect missing events in a customer order workflow.

    For more information on how to construct the query that the cqlProc processor executes, see Section 3.7.4.1, "Creating the Missing Event Query".

  • Moving average: this event path consists of channel stockChannel connected to processor stockProcessor which is connected to channel movingAvgChannel which is connected to adapter movingOutput.

    This event path is used to compute a moving average on stock whose volume is greater than 1000.

    For more information on how to construct the query that the cqlProc processor executes, see Section 3.7.4.2, "Creating the Moving Average Query".

  • Cache: this event path consists of adapter adapter connected to channel S1 connected to Oracle CQL processor cacheProcessor connected to channel S2 connected to bean Bean. There is a cache stockCache also connected to the Oracle CQL processor cacheProcessor. There is also a bean Loader.

    This event path is used to access information from a cache in an Oracle CQL query.

Note:

For more information about the various components in the EPN, see the other samples in this book.

3.7.1 Running the CQL Example

For optimal demonstration purposes, Oracle recommends that you run this example on a powerful computer, such as one with multiple CPUs or a 3 GHz dual-core Intel, with a minimum of 2 GB of RAM.

The CQL application is pre-deployed to the cql_domain domain. To run the application, you simply start an instance of Oracle CEP server.

To run the CQL example:

  1. Open a command window and change to the default server directory of the CQL domain directory, located in ORACLE_CEP_HOME\ocep_11.1\samples\domains\cql_domain\defaultserver, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

    prompt> cd d:\oracle_cep\ocep_11.1\samples\domains\cql_domain\defaultserver
    
  2. Set your development environment, as described in Section 3.5, "Setting Your Development Environment."

  3. Start Oracle CEP by executing the appropriate script with the correct command line arguments:

    1. On Windows:

      • If you are using the JRockit JDK included in Oracle JRockit Real Time 3.0, enable the deterministic garbage collector by passing the -dgc parameter to the command:

        prompt> startwlevs.cmd -dgc
        
      • If you are not using the JRockit JDK included in Oracle JRockit Real Time 3.0:

        prompt> startwlevs.cmd
        
    2. On UNIX:

      • If you are using the JRockit JDK included in Oracle JRockit Real Time 3.0, enable the deterministic garbage collector by passing the -dgc parameter to the command:

        prompt> startwlevs.sh -dgc
        
      • If you are not using the JRockit JDK included in Oracle JRockit Real Time 3.0:

        prompt> startwlevs.sh
        

    The CQL application is now ready to receive data from the data feeds.

  4. To simulate the data feed for the missing event query, open a new command window and set your environment as described in Section 3.5, "Setting Your Development Environment."

  5. Change to the ORACLE_CEP_HOME\ocep_11.1\utils\load-generator directory, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

  6. Run the load generator using the orderData.prop properties file:

    1. On Windows:

      prompt> runloadgen.cmd orderData.prop
      
    2. On UNIX:

      prompt> runloadgen.sh orderData.prop
      
  7. To simulate the data feed for the moving average query, open a new command window and set your environment as described in Section 3.5, "Setting Your Development Environment."

  8. Change to the ORACLE_CEP_HOME\ocep_11.1\utils\load-generator directory, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

  9. Run the load generator using the stockData.prop properties file:

    1. On Windows:

      prompt> runloadgen.cmd stockData.prop
      
    2. On UNIX:

      prompt> runloadgen.sh stockData.prop
      
  10. To simulate the data feed for the cache query, you only need to run the example.

    The load data is generated by Adaptor.java and the cache data is generated by Loader.java. You can verify that data is flowing through by turning on statistics in the Oracle CEP Visualizer Query Plan.

3.7.2 Building and Deploying the CQL Example

The CQL sample source directory contains the Java source, along with other required resources such as configuration XML files, that make up the CQL application. The build.xml Ant file contains targets to build and deploy the application to the cql_domain domain, as described in Section 3.7.3, "Description of the Ant Targets to Build the CQL Example."

To build and deploy the CQL example from the source directory:

  1. If the CQL Oracle CEP instance is not already running, follow the procedure in Section 3.7.1, "Running the CQL Example" to start the server.

    You must have a running server to successfully deploy the rebuilt application.

  2. Open a new command window and change to the CQL source directory, located in ORACLE_CEP_HOME\ocep_11.1\samples\source\applications\cql, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

    prompt> cd d:\oracle_cep\ocep_11.1\samples\source\applications\cql
    
  3. Set your development environment, as described in Section 3.5, "Setting Your Development Environment."

  4. Execute the all Ant target to compile and create the application JAR file:

    prompt> ant all
    
  5. Execute the deploy Ant target to deploy the application JAR file to Oracle CEP:

    prompt> ant -Dusername=wlevs -Dpassword=wlevs -Daction=update deploy
    

    Caution:

    This target overwrites the existing CQL application JAR file in the domain directory.
  6. If the load generators required by the CQL application are not running, start them as described in Section 3.7.1, "Running the CQL Example."

3.7.3 Description of the Ant Targets to Build the CQL Example

The build.xml file, located in the top-level directory of the CQL source, contains the following targets to build and deploy the application:

  • clean—This target removes the dist and output working directories under the current directory.

  • all—This target cleans, compiles, and jars up the application into a file called com.bea.wlevs.example.cql_3.0.0.0.jar, and places the generated JAR file into a dist directory below the current directory.

  • deploy—This target deploys the JAR file to Oracle CEP using the Deployer utility.

    For more information, see "Deployer Command-Line Reference" in the Oracle CEP Administrator's Guide.

3.7.4 Implementation of the CQL Example

This section describes how to create the queries that the CQL example uses, including:

3.7.4.1 Creating the Missing Event Query

This section describes how to use the Oracle CEP Visualizer Query Wizard to create the Oracle CQL pattern matching query that the cqlProc processor executes to detect missing events.

Consider a customer order workflow in which you have customer order workflow events flowing into the Oracle CEP system.

In a valid scenario, you see events in the order that Table 3-1 lists:

Table 3-1 Valid Order Workflow

Event Type Description

C

Customer order

A

Approval

S

Shipment


However, it is an error if an order is shipped without an approval event as Table 3-2 lists:

Table 3-2 Invalid Order Workflow

Event Type Description

C

Customer order

S

Shipment


We will create and test a query that detects the missing approval event and generates an alert event:

To create the missing event query:

  1. If the CQL Oracle CEP instance is not already running, follow the procedure in Section 3.7.1, "Running the CQL Example" to start the server.

    You must have a running server to use the Oracle CEP Visualizer.

  2. Invoke the following URL in your browser:

    http://host:port/wlevs
    

    where host refers to the name of the computer on which Oracle CEP is running and port refers to the Jetty NetIO port configured for the server (default value 9002).

    The Logon screen appears as Figure 3-3 shows.

    Figure 3-3 Oracle CEP Visualizer Logon Screen

    Description of Figure 3-3 follows
    Description of "Figure 3-3 Oracle CEP Visualizer Logon Screen"

  3. In the Logon screen, enter the User Id wlevs and Password wlevs, and click Log In.

    The Oracle CEP Visualizer dashboard appears as Figure 3-29 shows.

    Figure 3-4 Oracle CEP Visualizer Dashboard

    Description of Figure 3-4 follows
    Description of "Figure 3-4 Oracle CEP Visualizer Dashboard"

    For more information about the Oracle CEP Visualizer user interface, see "Understanding the Oracle CEP Visualizer User Interface" in the Oracle CEP Visualizer User's Guide.

  4. In the right-hand pane, expand WLEventServerDomain > NonClusteredServer > Applications.

  5. Select the cql node.

    The CQL application screen appears as Figure 3-30 shows.

    Figure 3-5 CQL Application Screen: General Tab

    Description of Figure 3-5 follows
    Description of "Figure 3-5 CQL Application Screen: General Tab"

  6. Select the Event Processing Network tab.

    The Event Processing Network screen appears as Figure 3-31 shows.

    Figure 3-6 CQL Application: Event Processing Network Tab

    Description of Figure 3-6 follows
    Description of "Figure 3-6 CQL Application: Event Processing Network Tab"

  7. Double-click the orderProcessor Oracle CQL processor icon.

    The Oracle CQL processor screen appears as Figure 3-32 shows.

    Figure 3-7 Oracle CQL Processor: General Tab

    Description of Figure 3-7 follows
    Description of "Figure 3-7 Oracle CQL Processor: General Tab"

  8. Select the Query Wizard tab.

    The Query Wizard screen appears as Figure 3-33 shows.

    Figure 3-8 Oracle CQL Processor: Query Wizard Tab

    Description of Figure 3-8 follows
    Description of "Figure 3-8 Oracle CQL Processor: Query Wizard Tab"

    You can use the Oracle CQL Query Wizard to construct an Oracle CQL query from a template or from individual Oracle CQL constructs.

    In this procedure, you are going to create an Oracle CQL query from a template.

    For more information, see "Creating a Rule in an Oracle CQL Processor Using the Query Wizard" in the Oracle CEP Visualizer User's Guide.

  9. Click the Templates tab.

    The Templates tab appears as Figure 3-9 shows.

  10. Click and drag the Pattern Match Template from the Templates palette and drop it anywhere in the Query Wizard canvas as Figure 3-9.

  11. Double-click the SSource icon.

    The SSource configuration screen appears as Figure 3-35 shows.

    Figure 3-10 SSource Configuration Dialog

    Description of Figure 3-10 follows
    Description of "Figure 3-10 SSource Configuration Dialog"

    The source of our query will be the orderChannel stream.

  12. Configure the SSource as follows:

    • Select Stream as the Type.

    • Select orderChannel from the Select a source pull-down menu.

  13. Click Save.

  14. Click Save Query.

  15. Double-click the Pattern icon.

    The Pattern configuration screen appears as Figure 3-11 shows.

    Figure 3-11 Pattern Configuration Dialog: Pattern Tab

    Description of Figure 3-11 follows
    Description of "Figure 3-11 Pattern Configuration Dialog: Pattern Tab"

    Using the Pattern tab, we will define the pattern expression that matches when missed events occur. The expression is made in terms of named conditions that we will specify on the Define tab in a later step.

  16. Enter the following expression in the Pattern Expression field:

    CustOrder NoApproval*? Shipment 
    

    This pattern uses the Oracle CQL pattern quantifiers that Table 3-3 lists. Use the pattern quantifiers to specify the allowed range of pattern matches. The one-character pattern quantifiers are maximal or "greedy"; they will attempt to match the biggest quantity first. The two-character pattern quantifiers are minimal or "reluctant"; they will attempt to match the smallest quantity first.

    Table 3-3 MATCH_RECOGNIZE Pattern Quantifiers

    Maximal Minimal Description

    *

    *?

    0 or more times

    +

    +?

    1 or more times.

    ?

    ??

    0 or 1 time.


    For more information, see:

  17. Select orderid from the Partition By pull-down menu and click the Plus Sign button to add this property to the PARTITION BY clause.

    This ensures that Oracle CEP evaluates the missing event query on each order.

  18. Enter Orders in the Alias field.

    This assigns an alias (Orders) for the pattern to simplify its use later in the query.

  19. Click the Define tab.

    The Define tab appears as Figure 3-12 shows.

    Figure 3-12 Pattern Configuration Dialog: Define Tab

    Description of Figure 3-12 follows
    Description of "Figure 3-12 Pattern Configuration Dialog: Define Tab"

    We will now define each of the conditions named in the pattern clause as Table 3-4 lists:

    Table 3-4 Condition Definitions

    Condition Name Definition

    CustOrder

    orderChannel.eventType = 'C'

    NoApproval

    NOT(orderChannel.eventType = 'A')

    Shipment

    orderChannel.eventType = 'C'


  20. Enter CustOrder in the Object Name field.

  21. Click the Expression Builder button and configure the Expression Builder as follows (see Figure 3-13):

    • In the Variables list, double-click eventType.

    • In the Operands list, double-click =.

    • After the = operand, enter the value 'C'.

    Figure 3-13 Expression Builder: CustOrder

    Description of Figure 3-13 follows
    Description of "Figure 3-13 Expression Builder: CustOrder"

  22. Click Save.

  23. Click the Plus Sign button.

    The condition definition is added to the Object List as Figure 3-14 shows.

    Figure 3-14 Pattern Configuration Dialog: Define Tab With CustOrder Condition

    Description of Figure 3-14 follows
    Description of "Figure 3-14 Pattern Configuration Dialog: Define Tab With CustOrder Condition"

  24. Enter NoApproval in the Object Name field.

  25. Click the Expression Builder button and configure the Expression Builder as follows (see Figure 3-13):

    • In the Variables list, double-click eventType.

    • In the Operands list, double-click =.

    • After the = operand, enter the value 'A'.

    • Place parenthesis around the expression.

    • Place the insertion bar at the beginning of the expression, outside the open parenthesis.

    • In the Operands list, double-click NOT.

    Figure 3-15 Expression Builder: NoApproval

    Description of Figure 3-15 follows
    Description of "Figure 3-15 Expression Builder: NoApproval"

  26. Click Save.

  27. Click the Plus Sign button.

    The condition definition is added to the Object List.

  28. Enter Shipment in the Object Name field.

  29. Click the Expression Builder button and configure the Expression Builder as follows (see Figure 3-13):

    • In the Variables list, double-click eventType.

    • In the Operands list, double-click =.

    • After the = operand, enter the value 'S'.

    Figure 3-16 Expression Builder: Shipment

    Description of Figure 3-16 follows
    Description of "Figure 3-16 Expression Builder: Shipment"

  30. Click Save.

  31. Click the Plus Sign button.

    The Define tab appears as Figure 3-17 shows.

    Figure 3-17 Pattern Configuration Dialog: Define Tab Complete

    Description of Figure 3-17 follows
    Description of "Figure 3-17 Pattern Configuration Dialog: Define Tab Complete"

  32. Click the Measure tab.

    The Measure tab appears as Figure 3-18 shows.

    Use the Measure tab to define expressions in a MATCH_RECOGNIZE condition and to bind stream elements that match conditions in the DEFINE clause to arguments that you can include in the select statement of a query.

    Use the Meaure tab to specify the following:

    • CustOrder.orderid AS orderid

    • CustOrder.amount AS amount

    For more information, see:

  33. Enter orderid in the Object Name field.

  34. Click the Expression Builder button and configure the Expression Builder as follows (see Figure 3-13):

    • In the Variables list, double-click CustOrder.orderid.

    Figure 3-19 Expression Builder: orderid

    Description of Figure 3-19 follows
    Description of "Figure 3-19 Expression Builder: orderid"

  35. Click Save.

  36. Click the Plus Sign button.

  37. Enter amount in the Object Name field.

  38. Click the Expression Builder button and configure the Expression Builder as follows (see Figure 3-13):

    • In the Variables list, double-click CustOrder.amount.

    Figure 3-20 Expression Builder: amount

    Description of Figure 3-20 follows
    Description of "Figure 3-20 Expression Builder: amount"

  39. Click Save.

  40. Click the Plus Sign button.

    The Measure tab appears as Figure 3-21 shows.

    Figure 3-21 Measure Tab: Complete

    Description of Figure 3-21 follows
    Description of "Figure 3-21 Measure Tab: Complete"

  41. Click Save.

  42. Double-click the Select icon.

    The Select configuration screen appears as Figure 3-22 shows.

    Figure 3-22 Select Configuration Dialog: Project Tab

    Description of Figure 3-22 follows
    Description of "Figure 3-22 Select Configuration Dialog: Project Tab"

  43. Configure the Project tab as follows:

    • Select AlertEvent from the Select or Input Event Type pull-down menu.

    • Select Orders from the Select a source pull-down menu.

  44. Double-click orderid in the Properties list and select orderid from the Select or Input Alias pull-down menu.

  45. Click the Plus Sign button to add the property to the Generated CQL Statement.

  46. Double-click amount in the Properties list and select amount from the Select or Input Alias pull-down menu.

  47. Click the Plus Sign button to add the property to the Generated CQL Statement.

  48. Click in the Project Expression field and enter the value "Error - Missing Approval" and select alertType from the Select or Input Alias pull-down menu.

  49. Click the Plus Sign button to add the property to the Generated CQL Statement.

    The Project tab appears as Figure 3-23 shows.

    Figure 3-23 Select Configuration Dialog: Project Tab Complete

    Description of Figure 3-23 follows
    Description of "Figure 3-23 Select Configuration Dialog: Project Tab Complete"

  50. Click Save.

  51. Click Save Query.

  52. Double-click the Output icon.

    The Output configuration screen appears as Figure 3-72 shows.

    Figure 3-24 Output Configuration Dialog

    Description of Figure 3-24 follows
    Description of "Figure 3-24 Output Configuration Dialog"

  53. Configure the Output as follows:

    • Select Query.

    • Enter Tracking as the Query Name.

  54. Click Inject Rule.

    The Inject Rule Confirmation dialog appears as Figure 3-46 shows.

    Figure 3-25 Inject Rule Confirmation Dialog

    Description of Figure 3-25 follows
    Description of "Figure 3-25 Inject Rule Confirmation Dialog"

  55. Click OK.

    The Query Wizard adds the rule to the cqlProc processor.

  56. Click Save.

  57. Click on the CQL Rules tab.

    The CQL Rules tab appears as Figure 3-47 shows.

  58. Click on the Query radio button.

    Confirm that your Tracking query is present.

    Figure 3-26 CQL Rules Tab With Tracking Query

    Description of Figure 3-26 follows
    Description of "Figure 3-26 CQL Rules Tab With Tracking Query"

To test the missing event query:

  1. To simulate the data feed for the missing event query, open a new command window and set your environment as described in Section 3.5, "Setting Your Development Environment."

  2. Change to the ORACLE_CEP_HOME\ocep_11.1\utils\load-generator directory, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

  3. Run the load generator using the data-aggre.prop properties file:

    1. On Windows:

      prompt> runloadgen.cmd data-aggre.prop
      
    2. On UNIX:

      prompt> runloadgen.sh data-aggre.prop
      
  4. In the Oracle CEP Visualizer, click the ViewStream button in the top pane.

    The Stream Visualizer screen appears as Figure 3-27 shows.

    Figure 3-27 Stream Visualizer: Showing Missing Events

    Description of Figure 3-27 follows
    Description of "Figure 3-27 Stream Visualizer: Showing Missing Events"

  5. Click Initialize Client.

  6. Enter /orderalert in the Inititalize client field.

  7. Click Subscribe.

    As missing events are detected, the Oracle CEP updates the Received Messages area showing the AlertEvents generated.

3.7.4.2 Creating the Moving Average Query

This section describes how to use the Oracle CEP Visualizer Query Wizard to create the Oracle CQL moving average query that the stockProc processor executes.

You do this in two steps:

To create a view source for the moving average query:

  1. If the CQL Oracle CEP instance is not already running, follow the procedure in Section 3.7.1, "Running the CQL Example" to start the server.

    You must have a running server to use the Oracle CEP Visualizer.

  2. Invoke the following URL in your browser:

    http://host:port/wlevs
    

    where host refers to the name of the computer on which Oracle CEP is running and port refers to the Jetty NetIO port configured for the server (default value 9002).

    The Logon screen appears as Figure 3-28 shows.

    Figure 3-28 Oracle CEP Visualizer Logon Screen

    Description of Figure 3-28 follows
    Description of "Figure 3-28 Oracle CEP Visualizer Logon Screen"

  3. In the Logon screen, enter the User Id wlevs and Password wlevs, and click Log In.

    The Oracle CEP Visualizer dashboard appears as Figure 3-29 shows.

    Figure 3-29 Oracle CEP Visualizer Dashboard

    Description of Figure 3-29 follows
    Description of "Figure 3-29 Oracle CEP Visualizer Dashboard"

    For more information about the Oracle CEP Visualizer user interface, see "Understanding the Oracle CEP Visualizer User Interface" in the Oracle CEP Visualizer User's Guide.

  4. In the right-hand pane, expand WLEventServerDomain > NonClusteredServer > Applications.

  5. Select the cql node.

    The CQL application screen appears as Figure 3-30 shows.

    Figure 3-30 CQL Application Screen: General Tab

    Description of Figure 3-30 follows
    Description of "Figure 3-30 CQL Application Screen: General Tab"

  6. Select the Event Processing Network tab.

    The Event Processing Network screen appears as Figure 3-31 shows.

    Figure 3-31 CQL Application: Event Processing Network Tab

    Description of Figure 3-31 follows
    Description of "Figure 3-31 CQL Application: Event Processing Network Tab"

  7. Double-click the stockProcessor Oracle CQL processor icon.

    The Oracle CQL processor screen appears as Figure 3-32 shows.

    Figure 3-32 Oracle CQL Processor: General Tab

    Description of Figure 3-32 follows
    Description of "Figure 3-32 Oracle CQL Processor: General Tab"

  8. Select the Query Wizard tab.

    The Query Wizard screen appears as Figure 3-33 shows.

    Figure 3-33 Oracle CQL Processor: Query Wizard Tab

    Description of Figure 3-33 follows
    Description of "Figure 3-33 Oracle CQL Processor: Query Wizard Tab"

    You can use the Oracle CQL Query Wizard to construct an Oracle CQL query from a template or from individual Oracle CQL constructs.

    In this procedure, you are going to create an Oracle CQL view and query from individual Oracle CQL constructs.

    For more information, see "Creating a Rule in an Oracle CQL Processor Using the Query Wizard" in the Oracle CEP Visualizer User's Guide.

  9. Click and drag an SSource icon (Stream Source) from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as Figure 3-54 shows.

    Figure 3-34 Query Wizard: SSource

    Description of Figure 3-34 follows
    Description of "Figure 3-34 Query Wizard: SSource"

  10. Double-click the SSource icon.

    The SSource configuration screen appears as Figure 3-35 shows.

    Figure 3-35 SSource Configuration Dialog

    Description of Figure 3-35 follows
    Description of "Figure 3-35 SSource Configuration Dialog"

    The source of our view will be the stockChannel stream. We want to select stock events from this stream where the volume is greater than 1000. This will be the source for our moving average query.

  11. Configure the SSource as follows:

    • Select Stream as the Type.

      The source of our view is the stockChannel stream.

    • Select stockChannel from the Select a source pull-down menu.

    • Enter the alias StockVolGt1000 in the AS field.

  12. Click Save.

  13. Click Save Query.

    Next, we will add an Oracle CQL filter.

  14. Click and drag a Filter icon from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as Figure 3-36 shows.

    Figure 3-36 Query Wizard: Filter

    Description of Figure 3-36 follows
    Description of "Figure 3-36 Query Wizard: Filter"

  15. Click on the SSource icon and drag to the Window icon to connect the Oracle CQL constructs as Figure 3-37 shows.

    Figure 3-37 Connecting the SSource and Filter Icons

    Description of Figure 3-37 follows
    Description of "Figure 3-37 Connecting the SSource and Filter Icons"

  16. Double-click the Filter icon.

    The Filter configuration screen appears as Figure 3-38 shows.

    Figure 3-38 Filter Configuration Dialog

    Description of Figure 3-38 follows
    Description of "Figure 3-38 Filter Configuration Dialog"

  17. Click the Expression Builder button.

    The Expression Builder dialog appears as Figure 3-39 shows.

    Figure 3-39 Filter Expression Builder

    Description of Figure 3-39 follows
    Description of "Figure 3-39 Filter Expression Builder"

  18. Configure the Expression Builder as follows:

    • Select StockVolGt100 from the Select an Event Type pull-down menu to define the variables we can use in this expression.

    • Double-click the symbol variable to add it to the Expression Builder field.

    • Double-click > in the Operands list to add it to the Expression Builder field.

    • Enter the value 1000 after the > operand.

  19. Click Save.

  20. Click Add Filter.

    The Query Wizard adds the expression to the Generated CQL Statement as Figure 3-40 shows.

    Figure 3-40 Filter Configuration Dialog: After Adding the Filter

    Description of Figure 3-40 follows
    Description of "Figure 3-40 Filter Configuration Dialog: After Adding the Filter"

  21. Click Save.

  22. Click Save Query.

    Next we want to add a select statement.

  23. Click and drag a Select icon from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as Figure 3-41 shows.

    Figure 3-41 Query Wizard: Select

    Description of Figure 3-41 follows
    Description of "Figure 3-41 Query Wizard: Select"

  24. Click on the Filter icon and drag to the Select icon to connect the Oracle CQL constructs.

  25. Double-click the Select icon.

    The Select configuration screen appears as Figure 3-42 shows.

    Figure 3-42 Select Configuration Dialog

    Description of Figure 3-42 follows
    Description of "Figure 3-42 Select Configuration Dialog"

    We want to select price, symbol, and volume from our StockVolGt1000 stream.

  26. Configure the Select as follows:

    • Select StockVolGt1000 from the Select a source pull-down menu.

    • Select the price property and click the Plus Sign button.

      The Query Wizard adds the property to Generated CQL Statement

    • Repeat for the symbol and volume properties.

    The Select configuration dialog appears as Figure 3-43 shows.

    Figure 3-43 Select Configuration Dialog: Properties Selected

    Description of Figure 3-43 follows
    Description of "Figure 3-43 Select Configuration Dialog: Properties Selected"

  27. Click Save.

  28. Click Save Query.

    Finally, we will add an Output.

  29. Click and drag an Output icon from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as Figure 3-44 shows.

    Figure 3-44 Query Wizard: Output

    Description of Figure 3-44 follows
    Description of "Figure 3-44 Query Wizard: Output"

  30. Click on the Select icon and drag to the Output icon to connect the Oracle CQL constructs.

  31. Double-click the Output icon.

    The Output configuration screen appears as Figure 3-45 shows.

    Figure 3-45 Output Configuration Dialog

    Description of Figure 3-45 follows
    Description of "Figure 3-45 Output Configuration Dialog"

  32. Configure the Output as follows:

    • Select View.

    • Configure View Name as StockVolGt1000.

    • Delete the contents of the View Schema field.

      We will let the Oracle CEP server define the view schema for us.

  33. Click Inject Rule.

    The Inject Rule Confirmation dialog appears as Figure 3-46 shows.

    Figure 3-46 Inject Rule Confirmation Dialog

    Description of Figure 3-46 follows
    Description of "Figure 3-46 Inject Rule Confirmation Dialog"

  34. Click OK.

    The Query Wizard adds the rule to the cqlProc processor.

  35. Click Save.

  36. Click on the CQL Rules tab.

    The CQL Rules tab appears as Figure 3-47 shows.

  37. Click on the View radio button.

    Confirm that your StockVolGt1000 view is present.

    Figure 3-47 CQL Rules Tab With View StockVolGt1000

    Description of Figure 3-47 follows
    Description of "Figure 3-47 CQL Rules Tab With View StockVolGt1000"

To create the moving average query using the view source:

  1. If the CQL Oracle CEP instance is not already running, follow the procedure in Section 3.7.1, "Running the CQL Example" to start the server.

    You must have a running server to use the Oracle CEP Visualizer.

  2. Invoke the following URL in your browser:

    http://host:port/wlevs
    

    where host refers to the name of the computer on which Oracle CEP is running and port refers to the Jetty NetIO port configured for the server (default value 9002).

    The Logon screen appears as Figure 3-48 shows.

    Figure 3-48 Oracle CEP Visualizer Logon Screen

    Description of Figure 3-48 follows
    Description of "Figure 3-48 Oracle CEP Visualizer Logon Screen"

  3. In the Logon screen, enter the User Id wlevs and Password wlevs, and click Log In.

    The Oracle CEP Visualizer dashboard appears as Figure 3-29 shows.

    Figure 3-49 Oracle CEP Visualizer Dashboard

    Description of Figure 3-49 follows
    Description of "Figure 3-49 Oracle CEP Visualizer Dashboard"

    For more information about the Oracle CEP Visualizer user interface, see "Understanding the Oracle CEP Visualizer User Interface" in the Oracle CEP Visualizer User's Guide.

  4. In the right-hand pane, expand WLEventServerDomain > NonClusteredServer > Applications.

  5. Select the cql node.

    The CQL application screen appears as Figure 3-30 shows.

    Figure 3-50 CQL Application Screen: General Tab

    Description of Figure 3-50 follows
    Description of "Figure 3-50 CQL Application Screen: General Tab"

  6. Select the Event Processing Network tab.

    The Event Processing Network screen appears as Figure 3-31 shows.

    Figure 3-51 CQL Application: Event Processing Network Tab

    Description of Figure 3-51 follows
    Description of "Figure 3-51 CQL Application: Event Processing Network Tab"

  7. Double-click the stockProcessor Oracle CQL processor icon.

    The Oracle CQL processor screen appears as Figure 3-32 shows.

    Figure 3-52 Oracle CQL Processor: General Tab

    Description of Figure 3-52 follows
    Description of "Figure 3-52 Oracle CQL Processor: General Tab"

  8. Select the Query Wizard tab.

    The Query Wizard screen appears as Figure 3-33 shows.

    Figure 3-53 Oracle CQL Processor: Query Wizard Tab

    Description of Figure 3-53 follows
    Description of "Figure 3-53 Oracle CQL Processor: Query Wizard Tab"

    You can use the Oracle CQL Query Wizard to construct an Oracle CQL query from a template or from individual Oracle CQL constructs.

    In this procedure, you are going to create an Oracle CQL view and query from individual Oracle CQL constructs.

    For more information, see "Creating a Rule in an Oracle CQL Processor Using the Query Wizard" in the Oracle CEP Visualizer User's Guide.

  9. Click and drag an SSource icon (Stream Source) from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as Figure 3-54 shows.

    Figure 3-54 Query Wizard: SSource for Moving Average Query

    Description of Figure 3-54 follows
    Description of "Figure 3-54 Query Wizard: SSource for Moving Average Query"

  10. Double-click the SSource icon.

    The SSource configuration screen appears as Figure 3-55 shows.

    Figure 3-55 SSource Configuration Dialog: Moving Average Query

    Description of Figure 3-55 follows
    Description of "Figure 3-55 SSource Configuration Dialog: Moving Average Query"

  11. Configure the SSource dialog as follows:

    • Select View as the Type.

    • Select the StockVolGt1000 view from the Select a source pull-down menu.

  12. Click Save.

  13. Click Save Query.

  14. Click and drag a Window icon from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as Figure 3-56 shows.

    Figure 3-56 Query Wizard: Window for Moving Average Query

    Description of Figure 3-56 follows
    Description of "Figure 3-56 Query Wizard: Window for Moving Average Query"

  15. Click on the SSource icon and drag to the Window icon to connect the Oracle CQL constructs.

  16. Double-click the Window icon.

    The SSource configuration screen appears as Figure 3-55 shows.

    Figure 3-57 Window Configuration Dialog: Moving Average Query

    Description of Figure 3-57 follows
    Description of "Figure 3-57 Window Configuration Dialog: Moving Average Query"

    We want to create a sliding window over the last 2 events, partitioned by symbol.

  17. Configure the Window dialog as follows:

    • Select symbol in the Source Property List to add it to the Partition List.

    • Select Partition as the Type.

    • Select Row Based and enter 2 in the Row Based field.

  18. Click Add Window.

    The Query Wizard adds the sliding window to the Generated CQL Statement as Figure 3-58 shows.

    Figure 3-58 Window Configuration Dialog: After Adding Window

    Description of Figure 3-58 follows
    Description of "Figure 3-58 Window Configuration Dialog: After Adding Window"

  19. Click Save.

  20. Click Save Query.

  21. Click and drag a Select icon from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as Figure 3-56 shows.

    Figure 3-59 Query Wizard: Select for Moving Average Query

    Description of Figure 3-59 follows
    Description of "Figure 3-59 Query Wizard: Select for Moving Average Query"

  22. Click on the Window icon and drag to the Select icon to connect the Oracle CQL constructs.

  23. Double-click the Select icon.

    The Select configuration screen appears as Figure 3-55 shows.

    Figure 3-60 Select Configuration Dialog: Source Property symbol Selected

    Description of Figure 3-60 follows
    Description of "Figure 3-60 Select Configuration Dialog: Source Property symbol Selected"

  24. Select StockVolGt1000 from the Select a source pull-down menu.

    This is the source of moving average query: the view we created earlier (see "To create a view source for the moving average query:").

  25. Select MovingAvgEvent from the Select or Input Event Type pull-down menu.

    This is the output event our moving average query will produced. We will map properties from the source events to this output event.

  26. In the Source Properties list, select symbol.

    The selected source property is added to the Project Expression as Figure 3-61 shows.

    Figure 3-61 Select Configuration Dialog: Source Property symbol Selected

    Description of Figure 3-61 follows
    Description of "Figure 3-61 Select Configuration Dialog: Source Property symbol Selected"

    In this case, we just want to map the source property symbol to output event property symbol as is.

  27. Click on the pull-down menu next to the AS field and select symbol.

  28. Click the Plus Sign button.

    The source property is added to the project expression of the Generated CQL Statement as Figure 3-62 shows.

    Figure 3-62 Select Configuration Dialog: Source Property symbol Mapped to Output Event Property

    Description of Figure 3-62 follows
    Description of "Figure 3-62 Select Configuration Dialog: Source Property symbol Mapped to Output Event Property"

  29. In the Source Properties list, select price.

    The selected source property is added to the Project Expression as Figure 3-63 shows.

    Figure 3-63 Select Configuration Dialog: Source Property price Selected

    Description of Figure 3-63 follows
    Description of "Figure 3-63 Select Configuration Dialog: Source Property price Selected"

    In this case, we want to process the source property price before we map it to the output event.

  30. Click the Expression Builder button.

    The Expression Builder dialog appears as Figure 3-64 shows.

    Figure 3-64 Expression Builder Dialog

    Description of Figure 3-64 follows
    Description of "Figure 3-64 Expression Builder Dialog"

  31. Select Aggregate Functions from the Select a function type pull-down menu.

    A list of the aggregate functions that Oracle CQL provides is displayed. We are going to use the AVG function.

  32. Select the StockVolGt1000.price in the Expression Builder field.

  33. Double-click the AVG function.

    The AVG() function is wrapped around our selection in the Expression Builder field as Figure 3-65 shows.

    Figure 3-65 Expression Builder: Applying the AVG Function

    Description of Figure 3-65 follows
    Description of "Figure 3-65 Expression Builder: Applying the AVG Function"

  34. Click Save.

    The expression is added to the Project Expression field as Figure 3-66 shows.

    Figure 3-66 Select Configuration Dialog: With Expression

    Description of Figure 3-66 follows
    Description of "Figure 3-66 Select Configuration Dialog: With Expression"

  35. Click on the pull-down menu next to the AS field and select movingAvgPrice.

  36. Click the plus Sign button.

    The source property is added to the project expression of the Generated CQL Statement as Figure 3-67 shows.

    Figure 3-67 Select Configuration Dialog: Source Property price Mapped to Output Event Property

    Description of Figure 3-67 follows
    Description of "Figure 3-67 Select Configuration Dialog: Source Property price Mapped to Output Event Property"

  37. Click Validate.

    A validation error dialog is shown as Figure 3-68 shows.

    Figure 3-68 Validation Error: GROUP BY

    Description of Figure 3-68 follows
    Description of "Figure 3-68 Validation Error: GROUP BY"

    Because we are partitioning, we must specify a GROUP BY clause.

  38. Select the Group tab.

    The Group tab appears as Figure 3-69 shows.

  39. Configure the Group tab as follows:

    • Select StockVolGt1000 from the Select a source pull-down menu.

    • Select symbol from the Properties list.

    • Click the Plus Sign button.

    The symbol property is added to GROUP BY clause as Figure 3-70 shows.

    Figure 3-70 Group Tab: With symbol Grouping Property

    Description of Figure 3-70 follows
    Description of "Figure 3-70 Group Tab: With symbol Grouping Property"

  40. Click Save.

  41. Click Save Query.

    Next, we want to connect the query to an output.

  42. Click and drag an Output icon from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as Figure 3-71 shows.

    Figure 3-71 Query Wizard: Output

    Description of Figure 3-71 follows
    Description of "Figure 3-71 Query Wizard: Output"

  43. Click on the Select icon and drag to the Output icon to connect the Oracle CQL constructs.

  44. Double-click the Output icon.

    The Output configuration screen appears as Figure 3-72 shows.

    Figure 3-72 Output Configuration Dialog

    Description of Figure 3-72 follows
    Description of "Figure 3-72 Output Configuration Dialog"

  45. Configure the Output as follows:

    • Select Query.

    • Enter MovingAverage as the Query Name.

  46. Click Inject Rule.

    The Inject Rule Confirmation dialog appears as Figure 3-46 shows.

    Figure 3-73 Inject Rule Confirmation Dialog

    Description of Figure 3-73 follows
    Description of "Figure 3-73 Inject Rule Confirmation Dialog"

  47. Click OK.

    The Query Wizard adds the rule to the cqlProc processor.

  48. Click Save.

  49. Click on the CQL Rules tab.

    The CQL Rules tab appears as Figure 3-47 shows.

  50. Click on the Query radio button.

    Confirm that your MovingAverage query is present.

    Figure 3-74 CQL Rules Tab With View MovingAverage

    Description of Figure 3-74 follows
    Description of "Figure 3-74 CQL Rules Tab With View MovingAverage"

To test the moving average query:

  1. To simulate the data feed for the moving average query, open a new command window and set your environment as described in Section 3.5, "Setting Your Development Environment."

  2. Change to the ORACLE_CEP_HOME\ocep_11.1\utils\load-generator directory, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

  3. Run the load generator using the stockData.prop properties file:

    1. On Windows:

      prompt> runloadgen.cmd stockData.prop
      
    2. On UNIX:

      prompt> runloadgen.sh stockData.prop
      
  4. In the Oracle CEP Visualizer, click the ViewStream button in the top pane.

    The Stream Visualizer screen appears as Figure 3-27 shows.

    Figure 3-75 Stream Visualizer: Showing Moving Average Query Output

    Description of Figure 3-75 follows
    Description of "Figure 3-75 Stream Visualizer: Showing Moving Average Query Output"

  5. Click Initialize Client.

  6. Enter /alertOutput in the Inititalize client field.

  7. Click Subscribe.

    As the moving average query outputs events, the Oracle CEP updates the Received Messages area showing the events generated.

3.8 Oracle Spatial Data Cartridge Example

This example shows how to use the Oracle Spatial data cartridge with Oracle CQL queries to process a stream of Global Positioning System (GPS) events to track the GPS location of buses and generate alerts when a bus arrives at its pre-determined bus stop positions.

Figure 3-76 shows the Oracle Spatial data cartridge example Event Processing Network (EPN). The EPN contains the components that make up the application and how they fit together.

Figure 3-76 The Oracle Spatial Data Cartridge Example Event Processing Network

Surrounding text describes Figure 3-76 .

The example includes the following components:

  • BusPositionGen—Component that simulates an input stream of bus position GPS events. It uses the Oracle CEP loadgen utility and csvgen adapter provider to read in comma separated values (CSV) and deliver them to the EPN as BusPos events.

  • BusStopAdapter—Custom adapter component that generates bus stop positions based on ORACLE_CEP_HOME\ocep_11.1\samples\domains\spatial_domain\defaultserver\applications\spatial_sample\bus_stops.csv, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

  • BusPosStream—Component that transmits BusPos events to the Processor as a stream.

  • BusStopRelation—Component that transmits BusPos evetns to the Processor as a relation.

  • Processor—Component that executes Oracle CQL queries on the incoming BusPos events.

  • BusStopChannel, BusPosChannel, and BusStopArrivalChannel—Components that each specify a different selector to transmit the results of a different query from the Processor component to the appropriate outbound adapter or output bean.

  • BusStopPub, BusPosPub, and BusStopArrivalPub—Components that publish the results of the Processor component's queries.

  • BusStopArrivalOutputBean—POJO event bean component that logs a message for each insert, delete, and update event to help visualize the relation offered by the BusStopArrivalChannel.

Note:

For more information about data cartridges, see:

3.8.1 Running the Oracle Spatial Data Cartridge Example

The Oracle Spatial data cartridge application is pre-deployed to the spatial_domain domain. To run the application, you simply start an instance of Oracle CEP server.

To run the Oracle Spatial data cartridge example from the spatial_domain domain:

  1. Open a command window and change to the default server directory of the Oracle Spatial data cartridge example domain directory, located in ORACLE_CEP_HOME\ocep_11.1\samples\domains\spatial_domain\defaultserver, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

    prompt> cd d:\oracle_cep\ocep_11.1\samples\domains\spatial_domain\defaultserver
    
  2. Ensure the environment is set correctly in the server startup script.

    For more information, see Section 3.5, "Setting Your Development Environment."

  3. Start Oracle CEP by executing the appropriate script with the correct command line arguments:

    1. On Windows:

      • If you are using the JRockit JDK included in Oracle JRockit Real Time 3.0, enable the deterministic garbage collector by passing the -dgc parameter to the command:

        prompt> startwlevs.cmd -dgc
        
      • If you are not using the JRockit JDK included in Oracle JRockit Real Time 3.0:

        prompt> startwlevs.cmd
        
    2. On UNIX:

      • If you are using the JRockit JDK included in Oracle JRockit Real Time 3.0, enable the deterministic garbage collector by passing the -dgc parameter to the command:

        prompt> startwlevs.sh -dgc
        
      • If you are not using the JRockit JDK included in Oracle JRockit Real Time 3.0:

        prompt> startwlevs.sh
        

    Wait for the console log to show:

    <Mar 4, 2010 2:13:15 PM EST> <Notice> <Spring> <BEA-2047000> <The application context for "spatial_sample" was started successfully>
    <Mar 4, 2010 2:13:15 PM EST> <Notice> <Server> <BEA-2046000> <Server STARTED>
    

    This message indicates that the Oracle Spatial data cartridge example is running correctly.

  4. On the same host as the Oracle Spatial data cartridge example is running, launch a browser and navigate to http://localhost:9002/bus/main.html.

    Note:

    You cannot run this example on one host and browse to it from another host. This is a limitation of the Google API Key that the example uses and is not a limitation of Oracle CEP.

    The Oracle Spatial data cartridge example Web page appears as Figure 3-77 shows.

    Figure 3-77 Oracle Spatial Data Cartridge Web Page

    Description of Figure 3-77 follows
    Description of "Figure 3-77 Oracle Spatial Data Cartridge Web Page"

    Click the Bus Top Arrivals tab to view bus stop arrivals as Figure 3-78 shows.

    Figure 3-78 Oracle Spatial Data Cartridge Web Page: Bus Stop Arrivals Tab

    Description of Figure 3-78 follows
    Description of "Figure 3-78 Oracle Spatial Data Cartridge Web Page: Bus Stop Arrivals Tab"

  5. Execute the Oracle CEP load generator to generate sample data:

    1. On Windows:

      • Open a command prompt and navigate to ORACLE_CEP_HOME/ocep_11.1/utils/load-generator

      • runloadgen.cmd bus_positions.prop

    2. On UNIX:

      • Open a terminal window and navigate to ORACLE_CEP_HOME/ocep_11.1/utils/load-generator

      • runloadgen.sh bus_positions.prop

  6. Observe the bus movements and alerts in the browser as Figure 3-79 shows.

    Figure 3-79 Oracle Spatial Data Cartridge Web Page: Bus Tracking

    Description of Figure 3-79 follows
    Description of "Figure 3-79 Oracle Spatial Data Cartridge Web Page: Bus Tracking"

3.8.2 Building and Deploying the Oracle Spatial Data Cartridge Example

The Oracle Spatial data cartridge sample source directory contains the Java source, along with other required resources such as configuration XML files, that make up the Oracle Spatial data cartridge application. The build.xml Ant file contains targets to build and deploy the application to the spatial_domain domain.

For more information, see Section 3.8.3, "Description of the Ant Targets to Build the Oracle Spatial Data Cartridge Example".

To build and deploy the Oracle Spatial data cartridge example from the source directory:

  1. If the spatial_domain Oracle CEP instance is not already running, follow the procedure in Section 3.8.1, "Running the Oracle Spatial Data Cartridge Example" to start the server.

    You must have a running server to successfully deploy the rebuilt application.

  2. Open a new command window and change to the Oracle Spatial data cartridge source directory, located in ORACLE_CEP_HOME\ocep_11.1\samples\source\applications\spatial where ORACLE_CEP_HOME is the directory in which you installed Oracle CEP.

    For example:

    prompt> cd d:\oracle_cep\ocep_11.1\samples\source\applications\spatial
    
  3. Set your development environment.

    For more information, see Section 3.5, "Setting Your Development Environment."

  4. Execute the all Ant target to compile and create the application JAR file:

    prompt> ant all
    
  5. Execute the deploy Ant target to deploy the application JAR file to Oracle CEP:

    prompt> ant -Daction=update deploy
    

    Caution:

    This target overwrites the existing Oracle Spatial data cartridge application JAR file in the domain directory.

3.8.3 Description of the Ant Targets to Build the Oracle Spatial Data Cartridge Example

The build.xml file, located in the top level of the Oracle Spatial data cartridge source directory, contains the following targets to build and deploy the application:

  • clean—This target removes the dist and output working directories under the current directory.

  • all—This target cleans, compiles, and JARs up the application into a file called com.bea.wlevs.example.helloworld_3.0.0.0.jar, and places the generated JAR file into a dist directory below the current directory.

  • deploy—This target deploys the JAR file to Oracle CEP using the Deployer utility.

    For more information, see "Deployer Command-Line Reference" in the Oracle CEP Administrator's Guide.

3.8.4 Implementation of the Oracle Spatial Data Cartridge Example

The implementation of the Oracle Spatial data cartridge example generally follows "Creating Oracle CEP Applications: Typical Steps" in the Oracle CEP Developer's Guide for Eclipse.

Refer to that section for a task-oriented procedure that describes the typical development process.

All the files of the Oracle Spatial data cartridge example are located relative to the ORACLE_CEP_HOME\ocep_11.1\samples\source\applications\spatial directory, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory such as c:\oracle_cep. Oracle recommends that you use this example directory setup in your own environment, although it is obviously not required.

The files used by the Oracle Spatial data cartridge example include:

  • An EPN assembly file that describes each component in the application and how all the components are connected together. You are required to include this XML file in your Oracle CEP application.

    In the example, the file is called context.xml and is located in the META-INF/spring directory.

    For details, see Section 3.8.5, "Oracle Spatial Data Cartridge Example EPN Assembly File."

  • A component configuration file that configures the various components on the EPN including the processor component of the application:

    In the example, this file is called config.xml and is located in the META-INF/wlevs directory.

    For details, see Section 3.8.6, "Oracle Spatial Data Cartridge Example Component Configuration File."

  • Java files that implement:

    • BusStopAdapter: Custom adapter component that generates bus stop positions based on ORACLE_CEP_HOME\ocep_11.1\samples\domains\spatial_domain\defaultserver\applications\spatial_sample\bus_stops.csv, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

    • OutputBean: POJO event bean component that logs a message for each insert, delete, and update event to help visualize the relation offered by the BusStopArrivalChannel

    • OrdsHelper: Helper class that provides method getOrds to return the ordinates from a JGeometry as a List of Double values.

    These Java files arelocated in the source\applications\spatial\src\com\oracle\cep\sample\spatial directory.

    For additional information about the Oracle CEP APIs referenced in this POJO, see Oracle CEP Java API Reference.

  • A MANIFEST.MF file that describes the contents of the OSGi bundle that will be deployed to Oracle CEP.

    In the example, the MANIFEST.MF file is located in the META-INF directory.

    For more information about creating this file, as well as a description of creating the OSGi bundle that you deploy to Oracle CEP, see "Overview of Application Assembly and Deployment" in the Oracle CEP Developer's Guide for Eclipse.

    The Oracle Spatial data cartridge example uses a build.xml Ant file to compile, assemble, and deploy the OSGi bundle; see Section 3.8.2, "Building and Deploying the Oracle Spatial Data Cartridge Example" for a description of this build.xml file if you also use Ant in your development environment.

3.8.5 Oracle Spatial Data Cartridge Example EPN Assembly File

One of the main purposes of the EPN assembly file is to define the event processing network by declaring the components of the application and how they are all connected, or in other word, which components listen to which other components. Oracle CEP provides a set of custom Spring tags used to declare the network. You also use the EPN assembly file to register the event types used by your application and its Oracle CQL or EPL rules.

You use the EPN assembly file in the typical way to define the application component beans in the Spring application context; the application components beans are those implemented with Java classes, such as adapters and the POJO that contains the business logic.

For more information, see:

Example 3-3 shows the EPN assembly file used in the Oracle Spatial data cartridge sample application.

Example 3-3 Oracle Spatial Data Cartridge Example EPN Assembly File

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xmlns:wlevs="http://www.bea.com/ns/wlevs/spring"
       xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/osgi
  http://www.springframework.org/schema/osgi/spring-osgi.xsd
  http://www.bea.com/ns/wlevs/spring
  http://www.bea.com/ns/wlevs/spring/spring-wlevs-v11_1_1_3.xsd">

    <wlevs:event-type-repository>
        <wlevs:event-type type-name="BusPos">
            <wlevs:properties type="tuple">
                <wlevs:property name="busId" type="int"/>
                <wlevs:property name="seq" type="int"/>
                <wlevs:property name="longitude" type="double"/>
                <wlevs:property name="latitude" type="double"/>
            </wlevs:properties>
        </wlevs:event-type>

    <wlevs:event-type type-name="BusStop">
            <wlevs:properties type="tuple">
                <wlevs:property name="busId" type="int"/>
                <wlevs:property name="seq" type="int"/>
                <wlevs:property name="geom" type="com.oracle.cep.cartridge.spatial.Geometry"/>
            </wlevs:properties>
    </wlevs:event-type>

   <wlevs:event-type type-name="BusPosEvent">
            <wlevs:properties type="tuple">
                <wlevs:property name="busId" type="int"/>
                <wlevs:property name="seq" type="int"/>
                <wlevs:property name="geom" type="com.oracle.cep.cartridge.spatial.Geometry"/>
            </wlevs:properties>
    </wlevs:event-type>

    <wlevs:event-type type-name="BusStopArrivalEvent">
            <wlevs:properties type="tuple">
                <wlevs:property name="incidentTime" type="int"/>
                <wlevs:property name="busId" type="int"/>
                <wlevs:property name="stopSeq" type="int"/>
            </wlevs:properties>
    </wlevs:event-type>

    <wlevs:event-type type-name="BusPosPubEvent">
            <wlevs:properties type="tuple">
                <wlevs:property name="lastTime" type="int"/>
                <wlevs:property name="busId" type="int"/>
                <wlevs:property name="longitude" type="double"/>
                <wlevs:property name="latitude" type="double"/>
            </wlevs:properties>
    </wlevs:event-type>

    <wlevs:event-type type-name="BusStopPubEvent">
            <wlevs:properties type="tuple">
                <wlevs:property name="busId" type="int"/>
                <wlevs:property name="id" type="int"/>
                <wlevs:property name="coords" type="java.util.List"/>
            </wlevs:properties>
    </wlevs:event-type>        

   </wlevs:event-type-repository>

    <!-- Assemble EPN (event processing network) -->

    <wlevs:adapter id="BusPositionGen" provider="csvgen">
        <wlevs:instance-property name="port" value="9020"/>
        <wlevs:instance-property name="eventTypeName" value="BusPos"/>
        <wlevs:instance-property
                name="eventPropertyNames"
                value="busId,seq,longitude,latitude"/>
        <wlevs:listener ref="BusPosStream"/>
        <wlevs:listener ref="BusStopAdapter"/>
    </wlevs:adapter>

    <wlevs:adapter id="BusStopAdapter" class="com.oracle.cep.sample.spatial.BusStopAdapter" >
        <wlevs:instance-property name="path" value="bus_stops.csv"/>
        <wlevs:instance-property name="eventType" value="BusStop"/>

        <wlevs:instance-property name="buffer" value="30.0"/>
    </wlevs:adapter>

    <wlevs:channel id="BusPosStream" event-type="BusPos"
        max-size="0" max-threads="0">
        <wlevs:listener ref="Processor"/>
    </wlevs:channel>

    <wlevs:channel id="BusStopRelation" event-type="BusStop" is-relation="true" >
        <wlevs:listener ref="Processor"/>
        <wlevs:source ref="BusStopAdapter"/>
    </wlevs:channel>

    <wlevs:processor id="Processor" >
    </wlevs:processor>

<!-- bus stops -->
    <wlevs:channel id="BusStopChannel" event-type="BusStopPubEvent">
        <wlevs:listener ref="BusStopPub" />
        <wlevs:source ref="Processor"/>
    </wlevs:channel>

    <wlevs:adapter id="BusStopPub" provider="httppub" />

<!-- bus position -->
    <wlevs:channel id="BusPosChannel" event-type="BusPosPubEvent">
        <wlevs:listener ref="BusPosPub" />
        <wlevs:source ref="Processor"/>
    </wlevs:channel>

    <wlevs:adapter id="BusPosPub" provider="httppub" />

<!-- bus stop arrival -->    
    <wlevs:channel id="BusStopArrivalChannel" event-type="BusStopArrivalEvent">
        <wlevs:listener ref="BusStopArrivalPub" />
        <wlevs:listener ref="BusStopArrivalOutputBean" />
        <wlevs:source ref="Processor"/>
    </wlevs:channel>
 
    <wlevs:event-bean id="BusStopArrivalOutputBean" class="com.oracle.cep.sample.spatial.OutputBean">
    </wlevs:event-bean>
    
    <wlevs:adapter id="BusStopArrivalPub" provider="httppub" />

</beans>

3.8.6 Oracle Spatial Data Cartridge Example Component Configuration File

The Oracle Spatial data cartridge application uses five processors: three to handle the three data feeds, one that joins the resulting events, and one that generates summarized results.

These XML files contain the Oracle CEP queries executed against input events. This sample uses the Oracle CQL language. For additional information and samples about using Oracle CEP query languages, see:

Note:

Oracle EPL is superseded by Oracle CQL.

Example 3-4 shows the component configuration file used in the Oracle Spatial data cartridge sample application.

The processor element contains the Oracle CQL views and queries that use the Oracle Spatial data cartridge to process geometric data using Oracle CEP.

Note:

For more information about data cartridges, see:

Example 3-4 Oracle Spatial Data Cartridge Example Component Configuration File

<?xml version="1.0" encoding="UTF-8"?>
<n1:config xsi:schemaLocation="http://www.bea.com/ns/wlevs/config/application wlevs_application_config.xsd" xmlns:n1="http://www.bea.com/ns/wlevs/config/application" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <http-pub-sub-adapter>
        <name>BusPosPub</name>
        <server-url>http://localhost:9002/pubsub</server-url>
        <channel>/bus/buspos</channel>
        <event-type>BusPosPubEvent</event-type>
    </http-pub-sub-adapter>

    <http-pub-sub-adapter>
        <name>BusStopPub</name>
        <server-url>http://localhost:9002/pubsub</server-url>
        <channel>/bus/busstop</channel>
        <event-type>BusStopPubEvent</event-type>
    </http-pub-sub-adapter>

    <http-pub-sub-adapter>
        <name>BusStopArrivalPub</name>
        <server-url>http://localhost:9002/pubsub</server-url>
        <channel>/bus/busstoparrival</channel>
        <event-type>BusStopArrivalEvent</event-type>
    </http-pub-sub-adapter>

  <processor>
    <name>Processor</name>
    <rules>

    <view id="BusPosGeomStream" >
        select bus.busId as busId, bus.seq as seq, 
        com.oracle.cep.cartridge.spatial.Geometry.createPoint(8307, bus.longitude, bus.latitude) as geom
        from BusPosStream as bus
    </view>

    <query id="BusArrival">
        ISTREAM(
            select systimestamp() as incidentTime, bus.busId as busId, busstop.seq as stopSeq
            from BusPosGeomStream[NOW] as bus, BusStopRelation as busstop
            where CONTAIN@spatial(busstop.geom, bus.geom, 0.0d) = true and
                   bus.busId = busstop.busId
        )
    </query>

    <query id="BusStopOut">
        select busId, seq as id, com.oracle.cep.sample.spatial.OrdsHelper.getOrds(geom) as coords from BusStopRelation
    </query>

    <query id="BusPosOut">
        select systimestamp() as lastTime, busId, longitude, latitude from BusPosStream
    </query>
   </rules>
  </processor>

  <channel>
      <name>BusStopArrivalChannel</name>
      <selector>BusArrival</selector>
  </channel>

  <channel>
      <name>BusPosChannel</name>
      <selector>BusPosOut</selector>
  </channel>

  <channel>
      <name>BusStopChannel</name>
      <selector>BusStopOut</selector>
  </channel>

</n1:config>

3.9 Foreign Exchange (FX) Example

The foreign exchange example, called FX for simplicity, is a more complex example than the HelloWorld example because it includes multiple processors that handle information from multiple data feeds. In the example, the data feeds are simulated using the Oracle CEP load generator utility.

Figure 3-80 shows the FX example Event Processing Network (EPN). The EPN contains the components that make up the application and how they fit together.

Figure 3-80 FX Example Event Processing Network

Description of Figure 3-80 follows
Description of "Figure 3-80 FX Example Event Processing Network"

In this scenario, three data feeds, simulated using the load generator, send a constant pair of values from different parts of the world; the value pairs consist of a currency pair, such as USDEUR for US dollar - European euro, and an exchange rate between the two currencies. The fxMarketAmer, fxMarketAsia, and fxMarketEuro adapters receive the data from the feeds, convert them into events, and pass them to the corresponding FilterAmer, FilterAsia, and FilterEuro processors. Each processor performs an initial stale check to ensure that no event is more than 1 second old and then a boundary check to ensure that the exchange rate between the two currencies is within a current boundary. The processor also only selects a specific currency pair from a particular channel; for example, the server selects USDEUR from the simulated American data feed, but rejects all other pairs, such as USDAUD (Australian dollar).

After the data from each data feed provider passes this initial preparation phase, a different processor, called FindCrossRate, joins all events across all providers, calculates the mid-point between the maximum and minimum rate, and then applies a trader-specified spread. Finally, the processor forwards the rate to the POJO that contains the business code; in this example, the POJO simply publishes the rate to clients.

The Oracle CEP monitor is configured to watch if the event latency in the last step exceeds some threshold, such as no updated rates in a 30 second time-span, and if there is too much variance between two consecutive rates for the same currency pair. Finally, the last rate of each currency pair is forwarded to the Oracle CEP http pub-sub server.

3.9.1 Running the Foreign Exchange Example

For optimal demonstration purposes, Oracle recommends that you run this example on a powerful computer, such as one with multiple CPUs or a 3 GHz dual-core Intel, with a minimum of 2 GB of RAM.

The Foreign Exchange (FX) application is pre-deployed to the fx_domain domain. To run the application, you simply start an instance of Oracle CEP server.

To run the foreign exchange example:

  1. Open a command window and change to the default server directory of the FX domain directory, located in ORACLE_CEP_HOME\ocep_11.1\samples\domains\fx_domain\defaultserver, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

    prompt> cd d:\oracle_cep\ocep_11.1\samples\domains\fx_domain\defaultserver
    
  2. Set your development environment, as described in Section 3.5, "Setting Your Development Environment."

  3. Start Oracle CEP by executing the appropriate script with the correct command line arguments:

    1. On Windows:

      • If you are using the JRockit JDK included in Oracle JRockit Real Time 3.0, enable the deterministic garbage collector by passing the -dgc parameter to the command:

        prompt> startwlevs.cmd -dgc
        
      • If you are not using the JRockit JDK included in Oracle JRockit Real Time 3.0:

        prompt> startwlevs.cmd
        
    2. On UNIX:

      • If you are using the JRockit JDK included in Oracle JRockit Real Time 3.0, enable the deterministic garbage collector by passing the -dgc parameter to the command:

        prompt> startwlevs.sh -dgc
        
      • If you are not using the JRockit JDK included in Oracle JRockit Real Time 3.0:

        prompt> startwlevs.sh
        

    The FX application is now ready to receive data from the data feeds.

  4. To simulate an American data feed, open a new command window and set your environment as described in Section 3.5, "Setting Your Development Environment."

  5. Change to the ORACLE_CEP_HOME\ocep_11.1\utils\load-generator directory, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

  6. Run the load generator using the fxAmer.prop properties file:

    1. On Windows:

      prompt> runloadgen.cmd fxAmer.prop
      
    2. On UNIX:

      prompt> runloadgen.sh fxAmer.prop
      
  7. Repeat steps 4 - 6 to simulate an Asian data feed, using the fxAsia.prop properties file:

    1. On Windows:

      prompt> runloadgen.cmd fxAsia.prop
      
    2. On UNIX:

      prompt> runloadgen.sh fxAsia.prop
      
  8. Repeat steps 4 - 6 to simulate an European data feed, using the fxEuro.prop properties file:

    1. On Windows:

      prompt> runloadgen.cmd fxEuro.prop
      
    2. On UNIX:

      prompt> runloadgen.sh fxEuro.prop
      

    After the server status messages scroll by in the command window from which you started the server, and the three load generators start, you should see messages similar to the following being printed to the server command window:

    OutputBean:onEvent() + <TupleValue><EventType>SpreaderOuputEvent</EventType><ObjectName>FindCrossRatesRule</ObjectName><Timestamp>1843704855846</Timestamp><TupleKind>null</TupleKind><DoubleAttribute><Value>90.08350000074516</Value></DoubleAttribute><CharAttribute><Value>USD</Value><Length>3</Length></CharAttribute><CharAttribute><Value>JPY</Value><Length>3</Length></CharAttribute><IsTotalOrderGuarantee>false</IsTotalOrderGuarantee></TupleValue>
    

    These messages indicate that the Foreign Exchange example is running correctly. The output shows the cross rates of US dollars to Japanese yen and US dollars to UK pounds sterling.

3.9.2 Building and Deploying the Foreign Exchange Example from the Source Directory

The Foreign Exchange (FX) sample source directory contains the Java source, along with other required resources such as configuration XML files, that make up the FX application. The build.xml Ant file contains targets to build and deploy the application to the fx_domain domain, as described in Section 3.9.3, "Description of the Ant Targets to Build FX."

To build and deploy the foreign exchange example from the source directory:

  1. If the FX Oracle CEP instance is not already running, follow the procedure in Section 3.9.1, "Running the Foreign Exchange Example" to start the server.

    You must have a running server to successfully deploy the rebuilt application.

  2. Open a new command window and change to the FX source directory, located in ORACLE_CEP_HOME\ocep_11.1\samples\source\applications\fx, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

    prompt> cd d:\oracle_cep\ocep_11.1\samples\source\applications\fx
    
  3. Set your development environment, as described in Section 3.5, "Setting Your Development Environment."

  4. Execute the all Ant target to compile and create the application JAR file:

    prompt> ant all
    
  5. Execute the deploy Ant target to deploy the application JAR file to Oracle CEP:

    prompt> ant -Dusername=wlevs -Dpassword=wlevs -Daction=update deploy
    

    Caution:

    This target overwrites the existing FX application JAR file in the domain directory.
  6. If the load generators required by the FX application are not running, start them as described in Section 3.9.1, "Running the Foreign Exchange Example."

    After server status messages scroll by, you should see the following message printed to the output:

    {crossRate=USDJPY, internalPrice=119.09934499999781}, {crossRate=USDGBP, internalPrice=0.5031949999999915}, {crossRate=USDJPY, internalPrice=117.73945624999783}
    

    This message indicates that the FX example has been redeployed and is running correctly.

3.9.3 Description of the Ant Targets to Build FX

The build.xml file, located in the top-level directory of the FX source, contains the following targets to build and deploy the application:

  • clean—This target removes the dist and output working directories under the current directory.

  • all—This target cleans, compiles, and jars up the application into a file called com.bea.wlevs.example.fx_3.0.0.0.jar, and places the generated JAR file into a dist directory below the current directory.

  • deploy—This target deploys the JAR file to Oracle CEP using the Deployer utility.

    For more information, see "Deployer Command-Line Reference" in the Oracle CEP Administrator's Guide.

3.9.4 Implementation of the FX Example

The implementation of the foreign exchange (FX) example generally follows "Creating Oracle CEP Applications: Typical Steps" in the Oracle CEP Developer's Guide for Eclipse.

Refer to that section for a task-oriented procedure that describes the typical development process.

All the files of the FX example are located relative to the ORACLE_CEP_HOME\ocep_11.1\samples\source\applications\fx directory, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory such as c:\oracle_cep. Oracle recommends that you use this example directory setup in your own environment, although it is obviously not required.

The files used by the FX example include:

  • An EPN assembly file that describes each component in the application and how all the components are connected together. You are required to include this XML file in your Oracle CEP application.

    In the example, the file is called com.oracle.cep.sample.fx.context.xml and is located in the META-INF/spring directory.

    For details, see Section 3.9.5, "The FX EPN Assembly File."

  • Two XML files that configure the processor components of the application:

    The first XML file configures the filterAmer, filterAsia, filterEuro, and FindCrossRates processors, all in a single file. This XML file includes the Oracle CQL rules that select particular currency pairs from particular simulated market feeds and joins together all the events that were selected by the pre-processors, calculates an internal price for the particular currency pair, and then calculates the cross rate. In the example, this file is called spreader.xml and is located in the META-INF/wlevs directory.

    The second XML file configures the summarizeResults processor and includes the Oracle CQL rule that summarizes the results of the FindCrossRates processor. In the example, this file is called SummarizeResults.xml and is located in the META-INF/wlevs directory.

    For details, see Section 3.9.6, "The FX Processor Component Configuration Files."

  • An XML file that configures the PublishSummaryResults http pub-sub adapter. In the example, this file is called PubSubAdapterConfiguration.xml and is located in the META-INF/wlevs directory.

  • A Java file that implements the OutputBean component of the application, a POJO that contains the business logic. This POJO prints out to the screen the events that it receives, programmed in the onEvent method. The POJO also registers into the event type repository the ForeignExchangeEvent event type.

    In the example, the file is called OutputBean.java and is located in the src/com/oracle/cep/sample/fx directory.

    For additional information about the Oracle CEP APIs referenced in this POJO, see Oracle CEP Java API Reference.

  • A MANIFEST.MF file that describes the contents of the OSGi bundle that will be deployed to Oracle CEP.

    In the example, the MANIFEST.MF file is located in the META-INF directory.

    For more information about creating this file, as well as a description of creating the OSGi bundle that you deploy to Oracle CEP, see "Overview of Application Assembly and Deployment" in the Oracle CEP Developer's Guide for Eclipse.

    The FX example uses a build.xml Ant file to compile, assemble, and deploy the OSGi bundle; see Section 3.9.2, "Building and Deploying the Foreign Exchange Example from the Source Directory" for a description of this build.xml file if you also use Ant in your development environment.

3.9.5 The FX EPN Assembly File

One of the main purposes of the EPN assembly file is to define the event processing network by declaring the components of the application and how they are all connected, or in other word, which components listen to which other components. Oracle CEP provides a set of custom Spring tags used to declare the network. You also use the EPN assembly file to register the event types used by your application and its Oracle CQL or EPL rules.

You use the EPN assembly file in the typical way to define the application component beans in the Spring application context; the application components beans are those implemented with Java classes, such as adapters and the POJO that contains the business logic.

For more information, see:

Example 3-5 shows the EPN assembly file used in the FX sample application; see the explanation after the example for details about the entries in bold.

Example 3-5 FX EPN Assembly File

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xmlns:wlevs="http://www.bea.com/ns/wlevs/spring"
       xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/osgi
  http://www.springframework.org/schema/osgi/spring-osgi.xsd
  http://www.bea.com/ns/wlevs/spring
  http://www.bea.com/ns/wlevs/spring/spring-wlevs-v11_1_1_3.xsd">
 
    <wlevs:event-type-repository>
        <wlevs:event-type type-name="StockTick">
            <wlevs:properties>
                <wlevs:property name="lastPrice" type="double"/>
                <wlevs:property name="symbol" type="char"/>
            </wlevs:properties>
        </wlevs:event-type>
        <wlevs:event-type type-name="CrossRateEvent">
            <wlevs:properties>
                <wlevs:property name="price" type="double"/>
                <wlevs:property name="fromRate" type="char"/>
                <wlevs:property name="toRate" type="char"/>
            </wlevs:properties>
        </wlevs:event-type>
        <wlevs:event-type type-name="SpreaderOuputEvent">
            <wlevs:properties type="tuple">
                <wlevs:property name="internalPrice" type="double"/>
                <wlevs:property name="crossRate1" type="char"/>
                <wlevs:property name="crossRate2" type="char"/>
            </wlevs:properties>
        </wlevs:event-type>
        <wlevs:event-type type-name="CrossrateSummaryEvent">
            <wlevs:properties>
                <wlevs:property name="averageInternalPrice" type="double"/>
                <wlevs:property name="crossRatePair" type="char"/>
                <wlevs:property name="totalCount" type="int"/>
            </wlevs:properties>
        </wlevs:event-type>
    </wlevs:event-type-repository>
 
    <!-- Assemble EPN (event processing network) -->
    <wlevs:adapter id="fxMarketAmer" provider="loadgen">
        <wlevs:instance-property name="port" value="9011"/>
        <wlevs:listener ref="FilterAmerStream"/>
    </wlevs:adapter>
 
    <!-- This processor is simply here to filter the inbound event data
    to make it appear more realistic. It would not normally be required
    in a real application -->
    <wlevs:channel id="FilterAmerStream" event-type="StockTick">
        <wlevs:listener ref="FilterAmer"/>
    </wlevs:channel>
    <wlevs:processor id="FilterAmer" provider="cql">
        <wlevs:listener ref="FxQuoteStream"/>
    </wlevs:processor>
 
    <wlevs:adapter id="fxMarketAsia" provider="loadgen">
        <wlevs:instance-property name="port" value="9012"/>
        <wlevs:listener ref="FilterAsiaStream"/>
    </wlevs:adapter>
 
    <!-- This processor is simply here to filter the inbound event data
    to make it appear more realistic. It would not normally be required
    in a real application -->
    <wlevs:channel id="FilterAsiaStream" event-type="StockTick">
        <wlevs:listener ref="FilterAsia"/>
    </wlevs:channel>
    <wlevs:processor id="FilterAsia" provider="cql">
        <wlevs:listener ref="FxQuoteStream"/>
    </wlevs:processor>
 
    <wlevs:adapter id="fxMarketEuro" provider="loadgen">
        <wlevs:instance-property name="port" value="9013"/>
        <wlevs:listener ref="FilterEuroStream"/>
    </wlevs:adapter>
 
    <!-- This processor is simply here to filter the inbound event data
    to make it appear more realistic. It would not normally be required
    in a real application -->
    <wlevs:channel id="FilterEuroStream" event-type="StockTick">
        <wlevs:listener ref="FilterEuro"/>
    </wlevs:channel>
    <wlevs:processor id="FilterEuro" provider="cql">
        <wlevs:listener ref="FxQuoteStream"/>
    </wlevs:processor>
 
    <!--  this it to allow delivery of specifc values for testing -->
    <wlevs:adapter id="csvTestData" provider="csvgen">
        <wlevs:instance-property name="port" value="9014"/>
        <wlevs:instance-property name="eventTypeName" value="StockTick"/>
        <wlevs:instance-property
                name="eventPropertyNames"
                value="symbol,lastPrice"/>
        <wlevs:listener ref="FxQuoteStream"/>
    </wlevs:adapter>
 
    <wlevs:channel id="FxQuoteStream" event-type="CrossRateEvent">
        <wlevs:listener ref="FindCrossRates"/>
    </wlevs:channel>
 
    <wlevs:processor id="FindCrossRates" provider="cql">
        <wlevs:listener ref="CrossRateStream"/>
    </wlevs:processor>
 
    <wlevs:channel id="CrossRateStream" event-type="SpreaderOuputEvent" advertise="true">
        <wlevs:listener ref="summarizeResults"/>
        <wlevs:listener>
            <bean class="com.oracle.cep.sample.fx.OutputBean" autowire="byName"/>
        </wlevs:listener>
    </wlevs:channel>
 
    <wlevs:processor id="summarizeResults" provider="cql">
        <wlevs:listener ref="SummaryResultsStream"/>
    </wlevs:processor>
 
    <wlevs:adapter id="PublishSummaryResults" provider="httppub"></wlevs:adapter>
    <wlevs:channel id="SummaryResultsStream"
                   event-type="CrossrateSummaryEvent">
        <wlevs:listener>
            <bean class="com.oracle.cep.sample.fx.OutputBean" autowire="byName"/>
        </wlevs:listener>
 
        <wlevs:listener ref="PublishSummaryResults"/>
 
    </wlevs:channel>
</beans>

In the preceding example:

  • The wlevs:event-type-repository element registers the event types that are used throughout the application. These events are all of type tuple and include:

    • StockTick: input events.

    • CrossRateEvent: event type output by the FilterAmer, FilterAsia, and FilterEuro processors.

    • SpreaderOutputEvent: event type output by the FindCrossRates processor.

    • CrossrateSummaryEvent: event type output by the summarizeResults processor.

    Oracle CEP automatically creates instances of these event types when needed. You can then reference this data in the Oracle CQL rules of the application, the adapter Java class, and the POJO.

    For more information, see "Event Types" in the Oracle CEP Developer's Guide for Eclipse .

  • The set of wlevs:adapter, wlevs:processor, and wlevs:channel elements set up the event processor network by declaring each component in the network. The network consists of three adapters, four processors, and five streams, as described in Figure 3-80.

    Each component is given a unique ID which can be referenced by other components when they declare their listeners and sources.

    • The wlevs:adapter elements specify adapter components, for example:

      <wlevs:adapter id="fxMarketAmer" provider="loadgen">
          <wlevs:instance-property name="port" value="9011"/>
      </wlevs:adapter>
      

      The fxMarketAmer, fxMarketAsia, and fxMarketEuro adapters provide the principle input data sources. These adapters use the provider="loadgen" attribute of each wlevs:adapter element to specify that the adapters get their data from the Oracle CEP load generator utility. The wlevs:instance-property child element specifies the port number to which the adapter should listen.

      The csvTestData adapter is an optional adapter you can use to feed test data into the application. This adapter uses the provider="csvgen" attribute to specify that this adapter gets its data from a comma separated value (CSV) file. For more information, see "Testing Applications With the Load Generator and csvgen Adapter" in the Oracle CEP Developer's Guide for Eclipse

      The PublishSummaryResults adapter outputs events to the Oracle CEP http pub-sub server.

    • The wlevs:processor elements specify the complex event processors, for example:

      <wlevs:processor id="FilterAmer" provider="cql">
          <wlevs:listener ref="FxQuoteStream"/>
      </wlevs:processor>
      

      You can use the listeners attribute, common to all component elements, or a wlevs:listener child element to specify the components that listen to the processor; in this case, it is a channel called FxQuoteStream.

    • The wlevs:channel elements specify the event streams between components, for example:

      <wlevs:channel id="FxQuoteStream" event-type="CrossRateEvent">    <wlevs:listener ref="FindCrossRates"/></wlevs:channel>
      

      As with all components, you can use the wlevs:listener and wlevs:source child elements to specify the other components that act as listeners and sources for this component.

      In the example, the FindCrossRates processor listens to the FxQuoteStream channel.

      Example 3-6 shows how you can nest the definition of a component inside a wlevs:listener element:

      Example 3-6 Nested Component Definition

      <wlevs:channel id="CrossRateStream" event-type="SpreaderOuputEvent" advertise="true">
          <wlevs:listener ref="summarizeResults"/>
          <wlevs:listener>
              <bean class="com.oracle.cep.sample.fx.OutputBean" autowire="byName"/>
          </wlevs:listener>
      </wlevs:channel>
      

      In Example 3-6, the OutputBean POJO, declared as a standard Spring bean using the <bean> tag, listens to the CrossRateStream channel.

3.9.6 The FX Processor Component Configuration Files

The FX application uses five processors: three to handle the three data feeds, one that joins the resulting events, and one that generates summarized results.

The first four processors are configured in a single XML file, called spreader.xml. For more information, see Section 3.9.6.1, "FX Processor Component Configuration File: spreader.xml."

The fifth processor is configured in the XML file called SummarizeResults.xml. For more information, see Section 3.9.6.2, "FX Processor Component Configuration File: SummarizeResults.xml."

These XML files contain the Oracle CEP queries executed against input events. This sample uses the Oracle CQL language. For additional information and samples about using Oracle CEP query languages, see:

Note:

Oracle EPL is superseded by Oracle CQL.

3.9.6.1 FX Processor Component Configuration File: spreader.xml

The first four processors are configured in a single XML file, called spreader.xml, as Example 3-7 shows.

Example 3-7 FX Processor Component Configuration File: spreader.xml

<?xml version="1.0" encoding="UTF-8"?>
<n1:config xsi:schemaLocation="http://www.bea.com/ns/wlevs/config/application wlevs_application_config.xsd"
           xmlns:n1="http://www.bea.com/ns/wlevs/config/application"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <processor>
        <name>FilterAmer</name>
        <rules>
            <view id="UsdToEur" schema="lastPrice symbol"><![CDATA[
      select lastPrice, symbol from FilterAmerStream [range 1] where symbol="USDEUR"
      ]]></view>
            <view id="UsdToEurPre" schema="price fromRate toRate"><![CDATA[
      select avg(lastPrice) as price, "USD"  as fromRate, "EUR" as toRate
      from UsdToEur
      where lastPrice < 3.0 and lastPrice > 0.25
      ]]></view>
            <query id="AmerFilterCrossRates"><![CDATA[select * from UsdToEurPre]]></query>
        </rules>
    </processor>
    <processor>
        <name>FilterAsia</name>
        <rules>
            <view id="EurToJpy" schema="lastPrice symbol"><![CDATA[
      select lastPrice, symbol from FilterAsiaStream [range 1] where symbol="EURJPY"
      ]]></view>
            <view id="EurToJpyPre" schema="price fromRate toRate"><![CDATA[
      select avg(lastPrice) as price, "EUR" as fromRate, "JPY" as toRate
      from EurToJpy
      where lastPrice < 200.0 and lastPrice > 100.0
      ]]></view>
            <query id="AsiaFilterCrossRates"><![CDATA[select * from EurToJpyPre]]></query>
        </rules>
    </processor>
    <processor>
        <name>FilterEuro</name>
        <rules>
            <view id="EurToGbp" schema="lastPrice symbol"><![CDATA[
      select lastPrice, symbol from FilterEuroStream [range 1] where symbol="EURGBP"
      ]]></view>
            <view id="EurToGbpPre" schema="price fromRate toRate"><![CDATA[
      select avg(lastPrice) as price, "EUR" as fromRate, "GBP" as toRate 
      from EurToGbp 
      where lastPrice < 1.5 and lastPrice > 0.5
      ]]></view>
            <query id="EuroFilterCrossRates"><![CDATA[select * from EurToGbpPre]]></query>
        </rules>
    </processor>
 
    <processor>
        <name>FindCrossRates</name>
        <rules>
            <query id="FindCrossRatesRule"><![CDATA[
      select ((a.price * b.price) + 0.05) as internalPrice, 
            a.fromRate as crossRate1, 
            b.toRate as crossRate2 
      from FxQuoteStream [range 1] as a, FxQuoteStream [range 1] as b   
      where 
        NOT (a.price IS NULL)
      and
        NOT (b.price IS NULL)
      and
        a.toRate = b.fromRate
      ]]></query>
        </rules>
    </processor>
</n1:config>

The FilterAmer, FilterAsia, and FilterEuro processors in this file are all essentially the same; the differences lie only in the values used in the Oracle CQL queries for querying different items from the data feeds and applying different boundary conditions. For this reason, this section will discuss just the FilterAmer processor.

The Oracle CQL rules executed by the FilterAmer processor are:

    <processor>
        <name>FilterAmer</name>
        <rules>
            <view id="UsdToEur" schema="lastPrice symbol"><![CDATA[
      select lastPrice, symbol from FilterAmerStream [range 1] where symbol="USDEUR"
      ]]></view>
            <view id="UsdToEurPre" schema="price fromRate toRate"><![CDATA[
      select avg(lastPrice) as price, "USD" as fromRate, "EUR" as toRate
      from UsdToEur
      where lastPrice < 3.0 and lastPrice > 0.25
      ]]></view>
            <query id="AmerFilterCrossRates"><![CDATA[select * from UsdToEurPre]]></query>
        </rules>
    </processor>

To understand the query, one must look at the various clauses, as follows:

  • The UsdToEur view serves as a subquery that selects only those items from the StockTick data feed in which the symbol value is USDEUR (US dollar - European euro exchange) and should reject all other items. The from clause specifies also specifies that the window of time for which this Oracle CQL query executes is 1 second.

  • The UsdToEurPre view serves as a subquery that selects from the UsdToEur view. Its where clause specifies the boundary condition to ensure that the rates for a particular item from the feed fall within an accepted range; in this case, the lastPrice for a particular item from the feed must be between $3.00 and $0.25.

  • The AmerFilterCrossRates query selects everything from the UsdToEurPre view. Only the results of a query are output to the down-stream channels that listen to a processor.

The Oracle CQL rule executed by the FindCrossRates processor are:

    <processor>
        <name>FindCrossRates</name>
        <rules>
            <query id="FindCrossRatesRule"><![CDATA[
      select ((a.price * b.price) + 0.05) as internalPrice, 
            a.fromRate as crossRate1, 
            b.toRate as crossRate2 
      from FxQuoteStream [range 1] as a, FxQuoteStream [range 1] as b   
      where 
        NOT (a.price IS NULL)
      and
        NOT (b.price IS NULL)
      and
        a.toRate = b.fromRate
      ]]></query>
        </rules>
    </processor>

To understand the query, one must look at the various clauses, as follows:

  • The from and where clauses join two events from the CrossRateEvent object (which contains events selected by the FilterAmer, FilterAsia, and FilterEuro processors) where the value of the toRate and fromRate are the same. The from clause also sets the processing window, again of 1 second.

  • The select clause calculates an internal price of a particular currency, which averages the to and from rate of a the currency plus a fee of $.05, and also calculates a cross rate, which is defined as the price of one currency in terms of another currency in the market of a third country.

The result of this query is then sent to the business object POJO and the summarizeResults processor.

3.9.6.2 FX Processor Component Configuration File: SummarizeResults.xml

The fifth processor is configured in the XML file called SummarizeResults.xml as Example 3-8 shows.

Example 3-8 FX Processor Component Configuration File: SummarizeResults.xml

<?xml version="1.0" encoding="UTF-8"?>
<wlevs:config xmlns:wlevs="http://www.bea.com/ns/wlevs/config/application">
    <processor>
        <name>summarizeResults</name>
        <rules>
            <query id="Rule"><![CDATA[ 
                select  
                    crossRate1 || crossRate2 as crossRatePair,
                    count(*) as totalCount,
                    avg(internalPrice) as averageInternalPrice
                from CrossRateStream [RANGE 1 SLIDE 1]
                group by crossRate1,crossRate2 
                having count(*) > 0  
            ]]></query>
        </rules>
    </processor>
</wlevs:config>

The result of this query is then sent to the business object POJO and the PublishSummaryResults adapter.

3.10 Signal Generation Example

The signal generation sample application receives simulated market data and verifies if the price of a security has fluctuated more than two percent. The application also detects if there is a trend occurring by keeping track of successive stock prices for a particular symbol; if more than three successive prices fluctuate more than two percent, this is considered a trend.

Figure 3-81 shows the signal generation example Event Processing Network (EPN). The EPN contains the components that make up the application and how they fit together.

Figure 3-81 The Signal Generation Example Event Processing Network

Description of Figure 3-81 follows
Description of "Figure 3-81 The Signal Generation Example Event Processing Network"

The application simulates a market data feed using the Oracle CEP load generator utility; in this example, the load generator generates up to 10,000 messages per second. The example includes an HTML dashboard which displays the matched events along with the latencies; events consist of a stock symbol, a timestamp, and the price.

The example demonstrates very low latencies, with minimum latency jitter under high throughputs. Once the application starts running, the processor matches an average of 800 messages per second. If the application is run on the minimum configured system, the example shows very low average latencies (30-300 microsecond, on average) with minimal latency spikes (low milliseconds).

The example computes and displays latency values based on the difference between a timestamp generated on the load generator and timestamp on Oracle CEP. Computing valid latencies requires very tight clock synchronization, such as 1 millisecond, between the computer running the load generator and the computer running Oracle CEP. For this reason, Oracle recommends running both the load generator and Oracle CEP on a single multi-CPU computer where they will share a common clock.

The example also shows how to use the Oracle CEP event caching feature. In particular the single processor in the EPN sends events to both an event bean and a cache.

The example also demonstrates how to use Oracle CQL queries.

3.10.1 Running the Signal Generation Example

For optimal demonstration purposes, Oracle recommends that you run this example on a powerful computer, such as one with multiple CPUs or a 3 GHz dual-core Intel, with a minimum of 2 GB of RAM.

The signalgeneration_domain domain contains a single application: the signal generation sample application. To run the signal generation application, you simply start an instance of Oracle CEP in that domain.

To run the signal generation example:

  1. Open a command window and change to the default server directory of the signalgeneration_domain domain directory, located in ORACLE_CEP_HOME\ocep_11.1\samples\domains\signalgeneration_domain\defaultserver, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

    prompt> cd d:\oracle_cep\ocep_11.1\samples\domains\signalgeneration_domain\defaultserver
    
  2. Set your development environment, as described in Section 3.5, "Setting Your Development Environment."

  3. Start Oracle CEP by executing the appropriate script with the correct command line arguments:

    1. On Windows:

      • If you are using the JRockit JDK included in Oracle JRockit Real Time 3.0, enable the deterministic garbage collector by passing the -dgc parameter to the command:

        prompt> startwlevs.cmd -dgc
        
      • If you are not using the JRockit JDK included in Oracle JRockit Real Time 3.0:

        prompt> startwlevs.cmd
        
    2. On UNIX:

      • If you are using the JRockit JDK included in Oracle JRockit Real Time 3.0, enable the deterministic garbage collector by passing the -dgc parameter to the command:

        prompt> startwlevs.sh -dgc
        
      • If you are not using the JRockit JDK included in Oracle JRockit Real Time 3.0:

        prompt> startwlevs.sh
        
  4. Wait until you see console messages like this:

    <Apr 24, 2009 11:40:37 AM EDT> <Notice> <Server> <BEA-2046000> <Server STARTED>
    Throughput (msg per second): 0. Average latency (microseconds): 0
    Throughput (msg per second): 0. Average latency (microseconds): 0
    Throughput (msg per second): 0. Average latency (microseconds): 0
    Throughput (msg per second): 0. Average latency (microseconds): 0
    ...
    

    The signal generation application is now ready to receive data from the data feeds.

    Next, to simulate a data feed, you use a load generator programmed specifically for the example.

  5. 0pen a new command window.

  6. Change to the ORACLE_CEP_HOME\ocep_11.1\samples\domains\signalgeneration_domain\defaultserver\utils directory, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

  7. Run the startDataFeed command:

    1. On Windows:

      prompt> startDataFeed.cmd
      
    2. On UNIX:

      prompt> startDataFeed.sh
      
  8. Invoke the example dashboard by starting a browser and opening the following HTML page:

       http://host:9002/signalgeneration/dashboard.html
    

    Replace host with the name of the computer on which Oracle CEP is running; if it is the same computer as your browser, you can use localhost.

  9. In the browser, click Start on the HTML page.

    You should start seeing the events that match the Oracle CQL rules configured for this example as Figure 3-82 shows.

    Figure 3-82 Signal Generation Dashboard

    Description of Figure 3-82 follows
    Description of "Figure 3-82 Signal Generation Dashboard"

3.10.2 Building and Deploying the Signal Generation Example from the Source Directory

The signal generation sample source directory contains the Java source, along with other required resources, such as configuration XML files, EPN assembly file, and DOJO client Javascript libraries, that make up the signal generation application. The build.xml Ant file contains targets to build and deploy the application to the signalgeneration_domain domain, as described in Section 3.10.3, "Description of the Ant Targets to Build Signal Generation."

To build and deploy the signal generation example from the source directory:

  1. If the signal generation Oracle CEP instance is not already running, follow the procedure in Section 3.10.1, "Running the Signal Generation Example" to start the server. You must have a running server to successfully deploy the rebuilt application.

  2. Open a new command window and change to the signal generation source directory, located in ORACLE_CEP_HOME\ocep_11.1\samples\source\applications\signalgeneration, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

    prompt> cd d:\oracle_cep\ocep_11.1\samples\source\applications\signalgeneration
    
  3. Set your development environment, as described in Section 3.5, "Setting Your Development Environment."

  4. Execute the all Ant target to compile and create the application JAR file:

    prompt> ant all
    
  5. Execute the deploy Ant target to deploy the application JAR file to the ORACLE_CEP_HOME\ocep_11.1\samples\domains\signalgeneration_domain\defaultserver\applications\signalgeneration directory:

    prompt> ant deploy
    

    Caution:

    This target overwrites the existing signal generation application JAR file in the domain directory.
  6. If the load generator required by the signal generation application is not running, start it as described in Section 3.10.1, "Running the Signal Generation Example."

  7. Invoke the example dashboard as described in Section 3.10.1, "Running the Signal Generation Example."

3.10.3 Description of the Ant Targets to Build Signal Generation

The build.xml file, located in the top-level directory of the signal generation example source, contains the following targets to build and deploy the application:

  • clean—This target removes the dist and output working directories under the current directory.

  • all—This target cleans, compiles, and jars up the application into a file called com.bea.wlevs.example.signalgen_3.0.0.0.jar, and places the generated JAR file into a dist directory below the current directory.

  • deploy—This target deploys the JAR file to Oracle CEP using the Deployer utility.

    For more information, see "Deployer Command-Line Reference" in the Oracle CEP Administrator's Guide.

3.10.4 Implementation of the Signal Generation Example

The implementation of the signal generation example generally follows "Creating Oracle CEP Applications: Typical Steps" in the Oracle CEP Developer's Guide for Eclipse.

Refer to that section for a task-oriented procedure that describes the typical development process.

All the files of the signal generation are located relative to the ORACLE_CEP_HOME\ocep_11.1\samples\source\applications\signalgeneration directory, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory such as c:\oracle_cep. Oracle recommends that you use this example directory setup in your own environment, although it is obviously not required.

The files used by the signal generation example include:

  • A EPN assembly file that describes each component in the application and how all the components are connected together.

    In the example, the file is called epn_assembly.xml and is located in the META-INF/spring directory.

    For details, see Section 3.10.5, "The Signal Generation EPN Assembly File."

  • An XML file that configures the processor component of the application; this file is called config.xml and is located in the META-INF/wlevs directory

    The config.xml file configures the processor1 Oracle CQL processor, in particular the Oracle CQL rules that verify whether the price of a security has fluctuated more than two percent and whether a trend has occurred in its price.

    For details, see Section 3.10.6, "The Signal Generation Component Configuration Files."

  • A Java file that implements the SignalgenOutputBean component of the application, a POJO that contains the business logic. This POJO is an HttpServlet and an EventSink. Its onEvent method consumes PercentTick and TrendTick event instances, computes latency, and displays dashboard information.

    In the example, the file is called SignalgenOutputBean.java and is located in the src/oracle/cep/example/signalgen directory.

    For a detailed description of this file, as well as general information about programming event sinks, see "Stream Sources and Stream Sinks and Relation Sources and Relation Sinks" in the Oracle CEP Developer's Guide for Eclipse.

  • A MANIFEST.MF file that describes the contents of the OSGi bundle that will be deployed to Oracle CEP.

    In the example, the MANIFEST.MF file is located in the META-INF directory

    For more information about creating this file, as well as a description of creating the OSGi bundle that you deploy to Oracle CEP, see "Overview of Application Assembly and Deployment" in the Oracle CEP Developer's Guide for Eclipse.

  • A dashboard.html file in the main example directory; this HTML file is the example dashboard that displays events and latencies of the running signal generation application. The HTML file uses Dojo Javascript libraries from http://dojotoolkit.org/, located in the dojo directory.

For additional information about the Oracle CEP APIs referenced in ForeignExchangeBuilderFactory, see Oracle CEP Java API Reference.

The signal generation example uses a build.xml Ant file to compile, assemble, and deploy the OSGi bundle; see Section 3.10.2, "Building and Deploying the Signal Generation Example from the Source Directory" for a description of this build.xml file if you also use Ant in your development environment.

3.10.5 The Signal Generation EPN Assembly File

One of the main purposes of the EPN assembly file is to define the event processing network by declaring the components of the application and how they are all connected, or in other word, which components listen to which other components. Oracle CEP provides a set of custom Spring tags used to declare the network. You also use the EPN assembly file to register the event types used by your application and its Oracle CQL rules.

You use the EPN assembly file in the typical way to define the application component beans in the Spring application context; the application components beans are those implemented with Java classes, such as adapters and the POJO that contains the business logic.

For more information, see:

Example 3-9 shows the EPN assembly file used in the signal generation sample application; see the explanation after the example for details about the entries in bold.

Example 3-9 Signal Generation EPN Assembly File

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi" xmlns:wlevs="http://www.bea.com/ns/wlevs/spring" xmlns:cqlx="http://www.oracle.com/schema/cqlx/" xsi:schemaLocation="  http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans.xsd  http://www.springframework.org/schema/osgi  http://www.springframework.org/schema/osgi/spring-osgi.xsd  http://www.bea.com/ns/wlevs/spring  http://www.bea.com/ns/wlevs/spring/spring-wlevs-v11_1_1_3.xsd">
 
    <wlevs:event-type-repository>
        <wlevs:event-type type-name="TrendTick">
            <wlevs:properties>
                <wlevs:property name="symbol" type="char"/>
                <wlevs:property name="lastPrice" type="double"/>
                <wlevs:property name="trendLastPrice" type="bigint"/>
                <wlevs:property name="startTimestamp" type="bigint"/>
            </wlevs:properties>
        </wlevs:event-type>
        <wlevs:event-type type-name="PercentTick">
            <wlevs:properties>
                <wlevs:property name="symbol" type="char"/>
                <wlevs:property name="lastPrice" type="double"/>
                <wlevs:property name="percentLastPrice" type="double"/>
                <wlevs:property name="startTimestamp" type="bigint"/>
            </wlevs:properties>
        </wlevs:event-type>
        <wlevs:event-type type-name="Symbols">
            <wlevs:properties>
                <wlevs:property name="symbol" type="char" length="10"/>
            </wlevs:properties>
        </wlevs:event-type>
    </wlevs:event-type-repository>
 
    <wlevs:adapter id="loadgenAdapter" provider="loadgen">
        <wlevs:instance-property name="port" value="9001"/>
        <wlevs:instance-property name="threadContextTimestamp" value="true"/>
    </wlevs:adapter>
 
    <!-- definition for cache that holds the symbols -->
    <wlevs:caching-system id="signalgenCachingSystem"/>
    <wlevs:cache id="symbolsCache" key-properties="symbol" value-type="Symbols">
        <wlevs:caching-system ref="signalgenCachingSystem"/>
        <wlevs:cache-loader ref="symbolsCacheLoader"/>
    </wlevs:cache>
 
    <wlevs:processor id="processor1">
        <wlevs:cache-source ref="symbolsCache"/>
    </wlevs:processor>
 
    <!-- Streams are just place-holders in this scenario, they just pass-through -->
    <wlevs:channel id="StockTickStream" max-threads="0" max-size="0" event-type="OracleStockTick">
        <wlevs:listener ref="processor1"/>
        <wlevs:source ref="loadgenAdapter"/>
    </wlevs:channel>
 
    <!-- advertise for monitoring -->
    <wlevs:channel id="TrendStream" max-threads="0" max-size="0" advertise="true" event-type="TrendTick">
        
        <wlevs:listener ref="outputbean"/>
        <wlevs:source ref="processor1"/>
    </wlevs:channel>
 
    <wlevs:channel id="PercentStream" max-threads="0" max-size="0" advertise="true" event-type="PercentTick">
        
        <wlevs:listener ref="outputbean"/>
        <wlevs:source ref="processor1"/>
    </wlevs:channel>
 
    <bean id="outputbean" class="oracle.cep.example.signalgen.SignalgenOutputBean">
        <property name="timestampProperty" value="startTimestamp"/>
    </bean>
 
    <bean id="symbolsCacheLoader" class="oracle.cep.example.signalgen.SymbolsCacheLoader">
        <property name="symbolsFileName" value="applications/MySigGen/symbols.txt"/>
        <property name="eventTypeName" value="Symbols"/>
    </bean>
 
</beans>

In the preceding example:

  • The wlevs:event-type-repository element creates the event types that are used throughout the application as tuples; in the signal generation application, there are the following events:

    • TrendTick: defined in the EPN assembly file.

    • PercentTick: defined in the EPN assembly file.

    • Symbols: defined in the EPN assembly file.

  • The set of wlevs:adapter, wlevs:processor, wlevs:channel, and wlevs:caching-system entries set up the event processor network by declaring each component in the network as described in Figure 3-81.

    Each component is given a unique ID which can be referenced by other components when they declare their listeners and sources.

    • The wlevs:adapter element specifies the adapter, for example:

      <wlevs:adapter id="loadgenAdapter" provider="loadgen">
          <wlevs:instance-property name="port" value="9001"/>
          <wlevs:instance-property name="threadContextTimestamp" value="true"/>
      </wlevs:adapter>
      

      The wlevs:adapter element provider="loadgen" attribute specifies that the adapter gets its data from the Oracle CEP load generator utility. The wlevs:instance-property child element specifies the port number to which the adapter should listen.

    • The wlevs:processor element specifies the Oracle CQL processor, for example:

      <wlevs:processor id="processor1">
          <wlevs:cache-source ref="symbolsCache"/>
      </wlevs:processor>
      

      The listener attribute, common to all component tags, specifies the component that listens to the processor; in this case, the listener is symbolsCache.

    • The wlevs:caching-system element specifies the Oracle CEP local event cache the application uses to improve performance, for example:

      <wlevs:caching-system id="signalgenCachingSystem"/>
      <wlevs:cache id="symbolsCache" key-properties="symbol" value-type="Symbols">
          <wlevs:caching-system ref="signalgenCachingSystem"/>
          <wlevs:cache-loader ref="symbolsCacheLoader"/>
      </wlevs:cache>
      

      For more information on caches, see "Configuring Oracle CEP Caching" in the Oracle CEP Developer's Guide for Eclipse.

3.10.6 The Signal Generation Component Configuration Files

The Signal Generation application configures its processor and cache in a component configuration file that Example 3-10 shows.

Example 3-10 Signal Generation Component Configuration File

<?xml version="1.0" encoding="UTF-8"?>
<!-- this is here to test that we ignore this file  -->
<n1:config xsi:schemaLocation="http://www.bea.com/ns/wlevs/config/application wlevs_application_config.xsd"
    xmlns:n1="http://www.bea.com/ns/wlevs/config/application" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <processor>
    <name>processor1</name>
    <rules>
      <view id="S" schema="symbol price">
        <![CDATA[
          RStream(select T.symbol, T.lastPrice from StockTickStream[now] as T, symbolsCache as R where T.symbol = R.symbol)
        ]]> 
      </view>
      <query id="percent">
        <![CDATA[  
        select symbol, lastPrice, percentLastPrice, startTimestamp
        from S MATCH_RECOGNIZE (
          PARTITION BY symbol
          MEASURES
            B.symbol as symbol,
            B.price as lastPrice,
            100*(B.price - A.price)/A.price as percentLastPrice,
                B.ELEMENT_TIME as startTimestamp
              ALL MATCHES
          PATTERN (A B)
          DEFINE
            B AS (100*(B.price - A.price)/A.price > 2.0
                  or    100*(B.price - A.price)/A.price < -2.0
                 )
            ) as T
        ]]>
     </query> 
     <view id="vTrend" schema="symbol lastPrice trendLastPrice">
        <![CDATA[
            select symbol, lastPrice, trendLastPrice
            from S MATCH_RECOGNIZE (
             PARTITION BY symbol
             MEASURES
                Z.symbol as symbol,
                Z.price as lastPrice,
                count(A.*)-count(B.*) as trendLastPrice
             ALL MATCHES
             PATTERN (X (A|B|C) (A|B|C) (A|B|C) (A|B|C) )
             SUBSET Z = (A, B, C)
             DEFINE
                A AS (A.price > PREV(A.price)),  
                B AS (B.price < PREV(B.price)),
                C AS (C.price = PREV(C.price))
            ) as T
        ]]>
     </view>
     <query id="trend">
        <![CDATA[
         select symbol, lastPrice, trendLastPrice, ELEMENT_TIME as startTimestamp from vTrend where trendLastPrice > 2
        ]]>    
     </query>
    </rules>
 </processor>
 <channel>
    <name>TrendStream</name>
    <selector>trend</selector>
 </channel>
 <channel>
    <name>PercentStream</name>
    <selector>percent</selector>
 </channel>
</n1:config>

If your application contains multiple processors, adapters or channels, you can either declare them all in a single configuration file, or create separate configuration files for each component; the method you chose depends on which you find easier to manage.

For each component you configure, you must add the name child element to explicitly declare the specific component to which you are referring. The value of the name element must correspond to the component's unique identifier of its declaration in the EPN assembly file.

For example, assume a processor is declared in the EPN assembly file as follows:

<wlevs:processor id="processor1" ...>

Then its corresponding XML configuration would be as follows:

<processor>
    <name>processor1</name>
    ...
</processor>

The Signal Generation example uses a single configuration file for one processor with the name processor1 and one cache with the name symbolsCache. These names correspond with the declaration of the components in the EPN assembly file.

The processor element configures the processor component. The most important part of the processor configuration is the declaration of the set of Oracle Continuous Query Language (Oracle CQL) rules that this processor executes; these rules select the set of events that are eventually passed to the application business object. Each rule is declared with a query or relation element using an XML <![CDATA[...]]> section; all query and relation elements are grouped together within a single rules element. You can define as many rules as you want for a particular processor.

The Signal Generation application has the following rules:

    <rules>
      <view id="S" schema="symbol price">
        <![CDATA[
          RStream(select T.symbol, T.lastPrice from StockTickStream[now] as T, symbolsCache as R where T.symbol = R.symbol)
        ]]> 
      </view>
      <query id="percent">
        <![CDATA[  
        select symbol, lastPrice, percentLastPrice, startTimestamp
        from S MATCH_RECOGNIZE (
          PARTITION BY symbol
          MEASURES
            B.symbol as symbol,
            B.price as lastPrice,
            100*(B.price - A.price)/A.price as percentLastPrice,
                B.ELEMENT_TIME as startTimestamp
              ALL MATCHES
          PATTERN (A B)
          DEFINE
            B AS (100*(B.price - A.price)/A.price > 2.0
                  or    100*(B.price - A.price)/A.price < -2.0
                 )
            ) as T
        ]]>
     </query> 
     <view id="vTrend" schema="symbol lastPrice trendLastPrice">
        <![CDATA[
            select symbol, lastPrice, trendLastPrice
            from S MATCH_RECOGNIZE (
             PARTITION BY symbol
             MEASURES
                Z.symbol as symbol,
                Z.price as lastPrice,
                count(A.*)-count(B.*) as trendLastPrice
             ALL MATCHES
             PATTERN (X (A|B|C) (A|B|C) (A|B|C) (A|B|C) )
             SUBSET Z = (A, B, C)
             DEFINE
                A AS (A.price > PREV(A.price)),  
                B AS (B.price < PREV(B.price)),
                C AS (C.price = PREV(C.price))
            ) as T
        ]]>
     </view>
     <query id="trend">
        <![CDATA[
         select symbol, lastPrice, trendLastPrice, ELEMENT_TIME as startTimestamp from vTrend where trendLastPrice > 2
        ]]>    
     </query>
    </rules>

For more information, see Oracle CEP CQL Language Reference.

3.11 Event Record and Playback Example

The record and playback example shows how to configure a component to record events to an event store and then configure another component in the network to playback events from the store. The example uses the Oracle CEP-provided database server, Apache Derby, to store the events. The example also shows how to configure a publishing HTTP pub-sub adapter as a node in the event processing network.

Figure 3-83 shows the event record and playback example Event Processing Network (EPN). The EPN contains the components that make up the application and how they fit together.

Figure 3-83 The Event Record and Playback Example Event Processing Network

Description of Figure 3-83 follows
Description of "Figure 3-83 The Event Record and Playback Example Event Processing Network"

The application contains four components in its event processing network:

  • simpleEventSource: an adapter that generates simple events for purposes of the example. This component has been configured to record events, as shown in the graphic.

    The configuration source for this adapter is:

    <adapter>
        <name>simpleEventSource</name>
        <record-parameters>
            ...
        </record-parameters>
    </adapter>
    
  • eventStream: a channel that connects the simpleEventSource adapter and recplayEventSink event bean. This component has been configured to playback events.

    The configuration source for this channel is:

    <channel>
        <name>eventStream</name>
        <playback-parameters>
            ...
        </playback-parameters>
        ...
    </channel>
    
  • recplayEventSink: an event bean that acts as a sink for the events generated by the adapter.

  • playbackHttpPublisher: a publishing HTTP pub-sub adapter that listens to the recplayEventSink event bean and publishes to a channel called /playbackchannel of the Oracle CEP HTTP Pub-Sub server.

3.11.1 Running the Event Record/Playback Example

The recplay_domain domain contains a single application: the record and playback sample application. To run this application, you first start an instance of Oracle CEP in the domain, as described in the following procedure.

The procedure then shows you how to use Oracle CEP Visualizer to start the recording and playback of events at the simpleEventSource and eventStream components, respectively. Finally, the procedure shows you how to use Oracle CEP Visualizer to view the stream of events being published to a channel by the playbackHttpPublisher adapter.

To run the event record/playback example:

  1. Open a command window and change to the default server directory of the recplay_domain domain directory, located in ORACLE_CEP_HOME\ocep_11.1\samples\domains\recplay_domain\defaultserver, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

    prompt> cd d:\oracle_cep\ocep_11.1\samples\domains\recplay_domain\defaultserver
    
  2. Set your development environment, as described in Section 3.5, "Setting Your Development Environment."

  3. Start Oracle CEP by executing the appropriate script with the correct command line arguments:

    1. On Windows:

      • If you are using the JRockit JDK included in Oracle JRockit Real Time 3.0, enable the deterministic garbage collector by passing the -dgc parameter to the command:

        prompt> startwlevs.cmd -dgc
        
      • If you are not using the JRockit JDK included in Oracle JRockit Real Time 3.0:

        prompt> startwlevs.cmd
        
    2. On UNIX:

      • If you are using the JRockit JDK included in Oracle JRockit Real Time 3.0, enable the deterministic garbage collector by passing the -dgc parameter to the command:

        prompt> startwlevs.sh -dgc
        
      • If you are not using the JRockit JDK included in Oracle JRockit Real Time 3.0:

        prompt> startwlevs.sh
        

    After server status messages scroll by, you should see the following message printed to the output:

        SimpleEvent created at: 14:33:40.441
    

    This message indicates that the Oracle CEP server started correctly and that the simpleEventSource component is creating events.

  4. Invoke the following URL in your browser:

    http://host:port/wlevs
    

    where host refers to the name of the computer on which Oracle CEP is running and port refers to the Jetty NetIO port configured for the server (default value 9002).

    The Logon screen appears as Figure 3-84 shows.

    Figure 3-84 Oracle CEP Visualizer Logon Screen

    Description of Figure 3-84 follows
    Description of "Figure 3-84 Oracle CEP Visualizer Logon Screen"

  5. In the Logon screen, enter the User Id wlevs and Password wlevs, and click Log In.

    The Oracle CEP Visualizer dashboard appears as Figure 3-29 shows.

    Figure 3-85 Oracle CEP Visualizer Dashboard

    Description of Figure 3-85 follows
    Description of "Figure 3-85 Oracle CEP Visualizer Dashboard"

    For more information about the Oracle CEP Visualizer user interface, see "Understanding the Oracle CEP Visualizer User Interface" in the Oracle CEP Visualizer User's Guide.

  6. In the left pane, select WLEventServerDomain > NonClusteredServer > Applications > recplay > Stages > simpleEventSource.

  7. In the right pane, select the Record tab as shown in Figure 3-86.

    Figure 3-86 Event Record Tab

    Description of Figure 3-86 follows
    Description of "Figure 3-86 Event Record Tab"

    The DataSet Name field contains the value of the record-parameters child element dataset-name element from the simpleEventSource adapter application configuration file ORACLE-CEP-HOME\ocep_11.1\samples\domains\recplay_domain\defaultserver\applications\recplay\config.xml as Example 3-11 shows.

    Example 3-11 recplay Application Configuration File config.xml: adapter Element

    <adapter>
        <name>simpleEventSource</name>
        <record-parameters>
            <dataset-name>recplay_sample</dataset-name>
            <event-type-list>
                <event-type>SimpleEvent</event-type>
            </event-type-list>
            <provider-name>test-rdbms-provider</provider-name>
            <batch-size>1</batch-size>
            <batch-time-out>10</batch-time-out>
        </record-parameters>
    </adapter>
    

    The Provider Name contains the value of the rdbms-event-store-provider child element name which corresponds to the data-source child element name as Example 3-12 shows.

    Example 3-12 recplay Oracle CEP Server Configuration File config.xml: data-source and rdbms-event-store-provider Elements

    <data-source>
        <name>derby1</name>
        <connection-pool-params>
            <initial-capacity>15</initial-capacity>
            <max-capacity>50</max-capacity>
        </connection-pool-params>
        <driver-params>
            <url>jdbc:derby:dbtest1;create=true</url>
            <driver-name>org.apache.derby.jdbc.EmbeddedDriver</driver-name>
        </driver-params>
    </data-source>
    <rdbms-event-store-provider>
        <name>test-rdbms-provider</name>
        <data-source-name>derby1</data-source-name>
    </rdbms-event-store-provider>
    
  8. At the bottom of the Record tab, click Start.

    An Alert dialog appears as shown in Figure 3-87.

    Figure 3-87 Start Recording Alert Dialog

    Description of Figure 3-87 follows
    Description of "Figure 3-87 Start Recording Alert Dialog"

  9. Click OK.

    The Current Status field reads Recording....

    As soon as you click OK, events start to flow out of the simpleEventSource component and are stored in the configured database.

    You can further configure when events are recorded using the Start Recording and Stop Recording fields.

  10. In the left pane, select eventStream.

  11. In the right pane, select the Playback tab as shown in Figure 3-88.

    Figure 3-88 Event Playback Tab

    Description of Figure 3-88 follows
    Description of "Figure 3-88 Event Playback Tab"

  12. At the bottom of the tab, click Start.

    An Alert dialog appears as shown in Figure 3-89.

    Figure 3-89 Start Playback Alert Dialog

    Description of Figure 3-89 follows
    Description of "Figure 3-89 Start Playback Alert Dialog"

  13. Click OK.

    The Current Status field reads Playing....

    As soon as you click OK, events that had been recorded by the simpleEventSource component are now played back to the simpleStream component.

    You should see the following messages being printed to the command window from which you started Oracle CEP server to indicate that both original events and playback events are streaming through the EPN:

    SimpleEvent created at: 14:33:11.501
    Played back: Original time=14:15:23.141 Playback time=14:33:11.657
    

    You can further configure the playback parameters, such as the recorded time period for which you want playback events and the speed that they are played back, by updating the appropriate field and clicking Change Parameters. You must restart the playback after changing any playback parameters.

  14. To view the events that the playbackHttpPublisher adapter is publishing to a channel, follow these steps:

    1. In the top pane, select Viewstream.

      The Viewstream window appears as shown in Figure 3-90.

      Figure 3-90 Stream Visualizer

      Description of Figure 3-90 follows
      Description of "Figure 3-90 Stream Visualizer"

    2. In the right pane, click Initialize Client.

    3. In the Subscribe Channel text box, enter /playbackchannel.

    4. Click Subscribe.

    The Received Messages text box displays the played back event details. The played back events show the time at which the event was created and the time at which it was played back.

3.11.2 Building and Deploying the Event Record/Playback Example from the Source Directory

The record and playback sample source directory contains the Java source, along with other required resources, such as configuration XML file and EPN assembly file that make up the application. The build.xml Ant file contains targets to build and deploy the application to the signalgeneration_domain domain, as described in Section 3.11.3, "Description of the Ant Targets to Build the Record and Playback Example."

To build and deploy the event record/playback example from the source directory:

  1. If the record/playback Oracle CEP instance is not already running, follow the procedure in Section 3.11.1, "Running the Event Record/Playback Example" to start the server. You must have a running server to successfully deploy the rebuilt application.

  2. Open a new command window and change to the record/playback source directory, located in ORACLE_CEP_HOME\ocep_11.1\samples\source\applications\recplay, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

    prompt> cd d:\oracle_cep\ocep_11.1\samples\source\applications\recplay
    
  3. Set your development environment, as described in Section 3.5, "Setting Your Development Environment."

  4. Execute the all Ant target to compile and create the application JAR file:

    prompt> ant all
    
  5. Execute the deploy Ant target to deploy the application JAR file to the ORACLE_CEP_HOME\ocep_11.1\samples\domains\recplay_domain\defaultserver\applications\recplay directory:

    prompt> ant -Dusername=wlevs -Dpassword=wlevs -Daction=update deploy
    

    Caution:

    This target overwrites the existing event record/playback application JAR file in the domain directory.

    After an application redeploy message, you should see the following message printed to the output about every second:

        SimpleEvent created at: 14:33:40.441
    

    This message indicates that the record and playback example has been redeployed and is running correctly.

  6. Follow the instructions in Section 3.11.1, "Running the Event Record/Playback Example," starting at step 4, to invoke Oracle CEP Visualizer and start recording and playing back events.

3.11.3 Description of the Ant Targets to Build the Record and Playback Example

The build.xml file, located in the top-level directory of the record/playback source, contains the following targets to build and deploy the application:

  • clean—This target removes the dist and output working directories under the current directory.

  • all—This target cleans, compiles, and jars up the application into a file called com.bea.wlevs.example.recplay_3.0.0.0.jar, and places the generated JAR file into a dist directory below the current directory.

  • deploy—This target deploys the JAR file to Oracle CEP using the Deployer utility.

    For more information, see "Deployer Command-Line Reference" in the Oracle CEP Administrator's Guide.

3.11.4 Implementation of the Record and Playback Example

The implementation of the signal generation example generally follows "Creating Oracle CEP Applications: Typical Steps" in the Oracle CEP Developer's Guide for Eclipse.

Refer to that section for a task-oriented procedure that describes the typical development process.

All the files of the example are located relative to the ORACLE_CEP_HOME\ocep_11.1\samples\source\applications\recplay directory, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory such as c:\oracle_cep. Oracle recommends that you use this example directory setup in your own environment, although it is obviously not required.

The files used by the record and playback example include:

  • An EPN assembly file that describes each component in the application and how all the components are connected together as shown in Figure 3-83.

    In the example, the file is called com.bea.wlevs.example.recplay-context.xml and is located in the META-INF/spring directory.

  • Java source file for the simpleEventSource adapter.

    In the example, the file is called SimpleEventSource.java and is located in the src/com/bea/wlevs/adapter/example/recplay directory.

    For a detailed description of this file and how to program the adapter Java files in general, see "Creating Custom Adapters and Event Beans" in the Oracle CEP Developer's Guide for Eclipse.

  • Java source file that describes the PlayedBackEvent and SimpleEvent event types. The SimpleEvent event type is the one originally generated by the adapter, but the PlayedBackEvent event type is used for the events that are played back after having been recorded. The PlayedBackEvents look almost exactly the same as SimpleEvent except they have an extra field, the time the event was recorded.

    In the example, the two events are called SimpleEvent.java and PlayedBackEvent.java and are located in the src/com/bea/wlevs/event/example/recplay directory.

    For a detailed description of this file, as well as general information about programming event types, see "Creating the Event Types" in the Oracle CEP Developer's Guide for Eclipse.

  • A Java file that implements the recplayEventSink event bean of the application, which is an event sink that receives both realtime events from the simpleEventSource adapter as well as playback events.

    In the example, the file is called RecplayEventSink.java and is located in the src/com/bea/wlevs/example/recplay directory.

    For a detailed description of this file and how to program the adapter Java files in general, see "Creating Custom Adapters and Event Beans" in the Oracle CEP Developer's Guide for Eclipse.

  • An XML file that configures the simpleEventSource adapter and eventStream channel components. The adapter includes a <record-parameters> element that specifies that the component will record events to the event store; similarly, the channel includes a <playback-parameters> element that specifies that it receives playback events.

    In the example, the file is called config.xml and is located in the META-INF/wlevs directory.

  • A MANIFEST.MF file that describes the contents of the OSGi bundle that will be deployed to Oracle CEP.

    In the example, the MANIFEST.MF file is located in the META-INF directory

    For more information about creating this file, as well as a description of creating the OSGi bundle that you deploy to Oracle CEP, see "Overview of Application Assembly and Deployment" in the Oracle CEP Developer's Guide for Eclipse.

The record/playback example uses a build.xml Ant file to compile, assemble, and deploy the OSGi bundle; see Section 3.11.2, "Building and Deploying the Event Record/Playback Example from the Source Directory" for a description of this build.xml file if you also use Ant in your development environment.