6 Event Processing Samples in Oracle Event Processing

This chapter introduces the sample code provided with the Oracle Event Processing installation and describes how to set up and use the code. You must have installed Oracle Event Processing with the Examples check box checked.

This chapter covers the following topics:

6.1 About the Samples

When you choose to include examples during installation, the Oracle Event Processing installation includes the following samples:

  • HelloWorld: Provides a basic skeleton for an Oracle Event Processing application.

  • Oracle CQL: Shows how to use the Oracle Event Processing Visualizer Query Wizard to construct Oracle CQL queries to process event streams.

  • Oracle Spatial: Shows how to use Oracle Spatial with Oracle CQL queries to process a stream of Global Positioning System (GPS) events. The GPS events track the location of buses and generate alerts when a bus arrives at bus stop positions.

  • Foreign Exchange (FX): Includes multiple components.

  • Signal Generation: Simulates market trading and trend detection.

  • Event record and playback: Shows how to configure event record and playback using a persistent event store.

These samples are provided in the following two forms:

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

The Oracle Event Processing installation directory is referred to as /Oracle/Middleware/my_oep/.

6.1.1 Ready-to-Run Samples

The ready-to-run samples have domains that are preconfigured to deploy the assembled application. Each domain is a standalone server domain, and the server files are located in the defaultserver subdirectory of the domain directory. To deploy the application, start the default server in the domain.

6.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.

6.2 Environment Setup

To run the examples, your development environment must have JDK7_u55 or above installed. You must set JAVA_HOME as follows.

export JAVA_HOME=< path to installation directory >
export PATH=${JAVA_HOME}/bin:${PATH}

To build and run the sample source, your development environment must have Ant installed. You must set ANT_HOME as follows:

export ANT_HOME=<path to Ant directory>
export PATH=${ANT_HOME}/bin:${PATH}

6.3 Use Oracle Event Processing Visualizer with the Samples

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

Visualizer is itself an Oracle Event Processing 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 Event Processing. 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 user name and password. For the FX and signal generation samples, security is enabled, so use the following user name and password to log in:

   Username: oepadmin
   Password: welcome1

For more information about Oracle Event Processing Visualizer, see Using Visualizer to Perform Tasks.

6.4 Increase the Performance of the Samples

When you run Oracle Event Processing on a computer with a larger amount of memory, set the load generator and server heap sizes appropriately for the size of the computer.

On computers with sufficient memory, Oracle recommends a heap size of 1 GB for the server and between 512MB - 1GB for the load generator.

6.5 HelloWorld Example

The HelloWorld sample shows how to create a typical Oracle Event Processing application.

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

Figure 6-1 The HelloWorld Example Event Processing Network

Description of Figure 6-1 follows
Description of "Figure 6-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 typically reads a stream of data from a source, such as a data feed from a financial institution, and converts it into a stream of events that the Oracle CQL 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 Oracle CQL processor.

  • helloworldProcessor: Component that forwards the messages from the helloworldAdapter component to the Plain Old Java Object (POJO) that contains the business logic. In a real-world scenario, this component typically executes additional and possibly much more 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 Oracle CQL processor to the POJO that contains the user-defined business logic.

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

6.5.1 Run the HelloWorld Example from the helloworld Domain

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

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 install with install with /Oracle/Middleware/my_oep/oep/examples/domains/helloworld_domain/defaultserver.

  2. Start Oracle Event Processing by executing the appropriate server startup script with the correct command-line arguments:

    1. On Windows:

      • prompt> startwlevs.cmd
        
    2. On UNIX:

      • prompt> ./startwlevs.sh
        

    After the server starts, 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.

6.5.2 Build and Deploy the HelloWorld Example from the Source Directory

The HelloWorld sample source directory contains the Java source and 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.

See also Description of the Ant Targets to Build Hello World.

Build and deploy the HelloWorld example from the source directory:

  1. If the helloworld Oracle Event Processing server is not already running, follow the procedure in Run 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/Middleware/my_oep/oep/examples/source/applications/ helloworld.
  3. Execute the all Ant target to compile and create the application JAR file:
    prompt> ant all
    
  4. Execute the deploy Ant target to deploy the application JAR file to Oracle Event Processing:
    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.

6.5.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 puts the application into a JAR file called com.bea.wlevs.example.helloworld_12.1.3.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 Event Processing using the Deployer utility.

6.5.4 Implementation of the HelloWorld Example

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

All the example files are located relative to the /Oracle/Middleware/my_oep/examples/source/applications/helloworld directory.

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 Event Processing application.

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

  • 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/examples/helloworld directory.

  • 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/examples/helloworld directory.

    For a detailed description of this file, and general information about programming event types, see Defining and Using Event Types in Oracle Fusion Middleware Developing Application for Oracle Event Processing .

  • An XML file that configures the helloworldProcessor and helloworldOutputChannel components. An important part of this file is the set of Oracle CQL rules that select the set of events that the HelloWorld application processes. You are required to include a Oracle CQL processor configuration file in your Oracle Event Processing 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.

  • 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/examples/helloworld directory.

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

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

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

6.6 Oracle Continuous Query Language Example

The Oracle Continuous Query Language (Oracle CQL) example shows how to use the Oracle Event Processing Visualizer Query Wizard to construct various types of Oracle CQL queries.

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

Note:

This sample might not start on a configuration of multiple coherence clusters that have the same default multicast address and port numbers. The error message contains text similar to ... has been attempting to join the cluster at address /239.255.0.1:9100 with TTL 4 for 30 seconds without success.

To get around this problem, specify unique addresses and ports to create a distinct cluster.

Figure 6-2 The CQL Example Event Processing Network

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

The application contains two 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 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 Create the Missing Event Query.

  • Moving average: The 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.

  • 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.

6.6.1 Run 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 Event Processing 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/Middleware/my_oep/oep/examples/ domains/cql_domain/defaultserver.

  2. Start Oracle Event Processing by executing the appropriate script with the correct command line arguments:

    1. On Windows:

      • prompt> startwlevs.cmd
        
    2. On UNIX:

      • prompt> ./startwlevs.sh
        

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

  3. To simulate the data feed for the missing event query, open a new command window.

  4. Change to the /Oracle/Middleware/my_oep/oep/utils/load-generator.

  5. 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
      
  6. Change to the /Oracle/Middleware/my_oep/oep/utils/load-generator.

  7. To simulate the data feed for the moving average query, open a new command window

  8. 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
      
  9. 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 Event Processing Visualizer Query Plan.

6.6.2 Build and Deploy 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 Description of the Ant Targets to Build Hello World.

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

  1. If the CQL Oracle Event Processing instance is not already running, follow the procedure in Run 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/Middleware/my_oep/oep/examples/source/applications/cql.
  3. Execute the all Ant target to compile and create the application JAR file:
    prompt> ant all
    
  4. Execute the deploy Ant target to deploy the application JAR file to Oracle Event Processing:
    prompt> ant -Dusername=oepadmin -Dpassword=welcome1 -Daction=update deploy
    

    Caution:

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

  5. If the load generators required by the CQL application are not running, start them as described in Run the CQL Example.

6.6.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 puts the application into a JAR file called com.bea.wlevs.example.cql_12.1.2.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 Event Processing using the Deployer utility.

6.6.4 Implementation of the CQL Example

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

6.6.4.1 Create the Missing Event Query

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

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

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

Table 6-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 6-2 lists:

Table 6-2 Invalid Order Workflow

Event Type Description

C

Customer order

S

Shipment

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

Create the missing event query:

  1. If the CQL Oracle Event Processing instance is not already running, follow the procedure in Run the CQL Example to start the server.

    You must have a running server to use the Oracle Event Processing 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 Event Processing is running and port refers to the Jetty NetIO port configured for the server (default value 9002).

    The Logon screen displays.

  3. In the Logon screen, enter the Username oepadmin, Password welcome1 and click Login.

    The Oracle Event Processing Visualizer dashboard displays.

  4. In the right panel, expand WLEventServerDomain > NonClusteredServer > Applications.

  5. Select the cql node.

    The CQL application screen displays.

  6. Select the Event Processing Network tab.

    The Event Processing Network screen displays.

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

    The Oracle CQL processor screen displays.

  8. Select the Query Wizard tab.

    The Query Wizard screen Displays.

    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.

  9. Click the Templates tab.

    The Templates tab displays.

  10. Click and drag the Pattern Match Template from the Templates palette and drop it anywhere in the Query Wizard canvas.

  11. Double-click the SSource icon.

    The SSource configuration screen displays.

    The source of your query is 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 displays.

    Using the Pattern tab, you will define the pattern expression that matches when missed events occur. The expression is made in terms of named conditions that you 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 6-3 lists. Use the pattern quantifiers to specify the allowed range of pattern matches. The one-character pattern quantifiers are maximal (greedy). They attempt to match the biggest quantity first. The two-character pattern quantifiers are minimal (reluctant). They attempt to match the smallest quantity first.

    Table 6-3 MATCH_RECOGNIZE Pattern Quantifiers

    Maximal Minimal Description

    *

    *?

    0 or more times

    +

    +?

    1 or more times.

    ?

    ??

    0 or 1 time.

  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 Event Processing 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 displays.

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

    Table 6-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:

    • In the Variables list, double-click eventType.

    • In the Operands list, double-click =.

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

  22. Click Save.

  23. Click the Plus Sign button.

    The condition definition is added to the Object List as follows:

  24. Enter NoApproval in the Object Name field.

  25. Click the Expression Builder button and configure the Expression Builder:

    • 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.

  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 :

    • In the Variables list, double-click eventType.

    • In the Operands list, double-click =.

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

  30. Click Save.

  31. Click the Plus Sign button.

    The Define tab displays.

  32. Click the Measure tab.

    The Measure tab displays.

    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 Measure tab to specify the following:

    • CustOrder.orderid AS orderid

    • CustOrder.amount AS amount

  33. Enter orderid in the Object Name field.

  34. Click the Expression Builder button and configure the Expression Builder:

    • In the Variables list, double-click CustOrder.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:

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

  39. Click Save.

  40. Click the Plus Sign button.

    The Measure tab displays.

  41. Click Save.

  42. Double-click the Select icon.

    The Select configuration screen appears as follows:

  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 displays.

  50. Click Save.

  51. Click Save Query.

  52. Double-click the Output icon.

    The Output configuration screen displays.

  53. Configure the Output as follows:

    • Select Query.

    • Enter Tracking as the Query Name.

  54. Click Inject Rule.

    The Inject Rule Confirmation dialog displays.

  55. Click OK.

    The Query Wizard adds the rule to the cqlProc processor.

  56. Click Save.

  57. Click the CQL Rules tab.

    The CQL Rules tab displays.

  58. Click the Query radio button.

    Confirm that your Tracking query is present.

Test the missing event query:

  1. To simulate the data feed, change to the /Oracle/Middleware/my_oep/utils/load-generator directory.

  2. 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
      
  3. In the Oracle Event Processing Visualizer, click the ViewStream button in the top panel.

    The Stream Visualizer screen displays.

  4. Click Initialize Client.

  5. Click the Subscribe tab.

  6. Select the orderalert radio button.

  7. Click Subscribe.

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

6.6.4.2 Create the Moving Average Query

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

You do this in two steps:

Create a view source for the moving average query:

  1. If the CQL Oracle Event Processing instance is not already running, follow the procedure in Run the CQL Example to start the server.

    You must have a running server to use the Oracle Event Processing 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 Event Processing is running and port refers to the Jetty NetIO port configured for the server (default value 9002).

    The Logon screen displays.

  3. In the Logon screen, enter the Username oepadmin and Password welcome1, and click Login.

    The Oracle Event Processing Visualizer dashboard displays.

  4. In the right panel, expand WLEventServerDomain > NonClusteredServer > Applications.

  5. Select the cql node.

    The CQL application screen displays.

  6. Select the Event Processing Network tab.

    The Event Processing Network screen displays.

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

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

    Figure 6-3 Oracle CQL Processor: General Tab

    Description of Figure 6-3 follows
    Description of "Figure 6-3 Oracle CQL Processor: General Tab"
  8. Select the Query Wizard tab.

    The Query Wizard screen displays.

    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.

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

  10. Double-click the SSource icon.

    The SSource configuration screen appears.

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

  11. Configure the SSource as follows:

    • Select Stream as the Type.

      The source of your 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.

  14. When prompted, enter StockVolGt1000 in the Query Id field.

  15. Click Save.

    Next, you will add an Oracle CQL filter.

  16. Click and drag a Filter icon from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as follows:

  17. Click the SSource icon and drag to the Window icon to connect the Oracle CQL constructs as follows:

  18. Double-click the Filter icon.

    The Filter configuration screen displays:

  19. Click the Expression Builder button.

    The Expression Builder dialog appears.

  20. Configure the Expression Builder as follows:

  21. Click Save.

  22. Click Add Filter.

    The Query Wizard adds the expression to the Generated CQL Statement as follows:

  23. Click Save.

  24. Click Save Query.

    Next you want to add a select statement.

  25. Click and drag a Select icon from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as follows:

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

  27. Double-click the Select icon.

    The Select configuration screen appears.

    You want to select price, symbol, and volume from your StockVolGt1000 stream.

  28. 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 displays.

  29. Click Save.

  30. Click Save Query.

    Finally, you will add an Output.

  31. Click and drag an Output icon from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as follows:

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

  33. Double-click the Output icon.

    The Output configuration screen appears.

  34. Configure the Output as follows:

  35. Click Inject Rule.

    The Inject Rule Confirmation dialog appears as follows:

  36. Click OK.

    The Query Wizard adds the rule to the cqlProc processor.

  37. Click Save.

  38. Click the CQL Rules tab.

    The CQL Rules tab displays.

  39. Click the View radio button.

    Confirm that your StockVolGt1000 view is present.

Create the moving average query using the view source:

  1. If the CQL Oracle Event Processing instance is not already running, follow the procedure in Run the CQL Example to start the server.

    You must have a running server to use the Oracle Event Processing 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 Event Processing is running and port refers to the Jetty NetIO port configured for the server (default value 9002).

    The Logon screen displays.

  3. In the Logon screen, enter the Username oepadmin and Password welcome1, and click Login.

    The Oracle Event Processing Visualizer dashboard displays.

  4. In the left panel, expand WLEventServerDomain > NonClusteredServer > Applications.

  5. Select the cql stage.

    The CQL application screen displays.

  6. Select the Event Processing Network tab.

    The Event Processing Network screen displays.

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

    The Oracle CQL processor screen displays.

  8. Select the Query Wizard tab.

    The Query Wizard screen displays. If you have been recently creating or editing queries for this Oracle CQL processor, you might see those queries on the Query Wizard canvas. Otherwise, the canvas will be blank.

    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.

  9. Click and drag an SSource icon (Stream Source) from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as follows:

  10. Double-click the SSource icon.

    The SSource configuration screen appears.

  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 follows:

  15. Click 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.

    You 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 follows:

  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 follows:

  22. Click 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.

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

    This is the source of moving average query: the view you created earlier (see "Create a view source for the moving average query:").

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

    This is the output event your moving average query will produced. You 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 follows:

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

  27. Click 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 follows:

  29. In the Source Properties list, select price.

    The selected source property is added to the Project Expression as follows:

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

  30. Click the Expression Builder button.

    The Expression Builder dialog appears.

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

    A list of the aggregate functions that Oracle CQL provides is displayed. You 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 your selection in the Expression Builder field as follows:

  34. Click Save.

    The expression is added to the Project Expression field as follows:

  35. Click 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 follows:

  37. Click Validate.

    A validation error dialog is shown as follows:

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

  38. Select the Group tab.

    The Group tab appears.

  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 follows:

  40. Click Save.

  41. Click Save Query.

    Next, you 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 follows:

  43. Click 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.

  45. Configure the Output as follows:

    • Select Query.

    • Enter MovingAverage as the Query Name.

  46. Click Inject Rule.

    The Inject Rule Confirmation dialog displays.

  47. Click OK.

    The Query Wizard adds the rule to the cqlProc processor.

  48. Click Save.

  49. Click the CQL Rules tab.

    The CQL Rules tab displays.

  50. Click the Query radio button.

    Confirm that your MovingAverage query is present.

Test the moving average query:

  1. To simulate the data feed for the moving average query, change to the /Oracle/Middleware/my_oep/utils/load-generator directory.

  2. 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
      
  3. In the Oracle Event Processing Visualizer, click the ViewStream button in the top panel.

    The Stream Visualizer screen displays.

  4. Click Initialize Client.

  5. Enter /stockmoving in the Initialize client field.

  6. Click Subscribe.

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

6.7 Oracle Spatial Example

This example shows how to use Oracle Spatial 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 6-4 shows Oracle Spatial example Event Processing Network (EPN). The EPN contains the components that make up the application and how they fit together.

Figure 6-4 Oracle Spatial Example Event Processing Network

Description of Figure 6-4 follows
Description of "Figure 6-4 Oracle Spatial Example Event Processing Network"

The example includes the following components:

  • BusPositionGen: Component that simulates an input stream of bus position GPS events. It uses the Oracle Event Processing 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/Middleware/my_oep/examples/domains/spatial_domain/defaultserver/applications/spatial_sample/bus_stops.csv.

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

  • BusStopRelation: Component that transmits BusPos events 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.

For more information about data cartridges, see Oracle Fusion Middleware Oracle CQL Language Reference for Oracle Event Processing.

6.7.1 Run the Oracle Spatial Example

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

Run the Oracle Spatial example from the spatial_domain domain:

  1. Open a command window and change to the default server directory of the Oracle Spatial example domain directory, located in /Oracle/Middleware/my_oep/oep/ examples/domains/spatial_domain/defaultserver.

  2. Start Oracle Event Processing by executing the appropriate script with the correct command line arguments:

    1. On Windows:

      • prompt> startwlevs.cmd
        
    2. On UNIX:

      • 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 example is running correctly.

  3. On the same host as the Oracle Spatial example is running, launch a browser and navigate to http://localhost:9002/bus/web/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 Event Processing.

    The Oracle Spatial example Web page displays.

    Click the Bus Top Arrivals tab to view bus stop arrivals as follows:

  4. Execute the Oracle Event Processing load generator to generate sample data:

    1. Open a command prompt and navigate to /Oracle/Middleware/my_oep/utils/load-generator.

    2. On Windows, type:

      • runloadgen.cmd bus_positions.prop

    3. On UNIX, type:

      • ./runloadgen.sh bus_positions.prop

  5. Observe the bus movements and alerts in the browser as follows:

6.7.2 Build and Deploy the Oracle Spatial Example

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

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

Build and deploy the Oracle Spatial example from the source directory:

  1. If the spatial_domain Oracle Event Processing instance is not already running, follow the procedure in Run the Oracle Spatial 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 source directory, located in /Oracle/Middleware/my_oep/oep/examples/source/applications/ spatial.
  3. Execute the all Ant target to compile and create the application JAR file:
    prompt> ant all
    
  4. Execute the deploy Ant target to deploy the application JAR file to Oracle Event Processing:
    prompt> ant -Daction=update deploy
    

    Caution:

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

6.7.3 Description of the Ant Targets to Build the Oracle Spatial Example

The build.xml file, located in the top level of the Oracle Spatial 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 outs the application into a JAR file called com.bea.wlevs.example.spatial_12.1.2.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 Event Processing using the Deployer utility.

6.7.4 Implementation of the Oracle Spatial Example

All the files of the Oracle Spatial example are located relative to the /Oracle/Middleware/my_oep/examples/source/applications/spatial directory.

The files used by the Oracle Spatial 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 Event Processing application.

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

  • 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.

  • Java files that implement:

    • BusStopAdapter: Custom adapter component that generates bus stop positions based on /Oracle/Middleware/my_oep/examples/domains/spatial_domain/defaultserver/applications/spatial_sample/bus_stops.csv.

    • 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 are located in the ~/source/applications/spatial/src/com/oracle/cep/sample/spatial directory.

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

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

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

    The Oracle Spatial example uses a build.xml Ant file to compile, assemble, and deploy the OSGi bundle; see Build and Deploy the Oracle Spatial Example for a description of this build.xml file if you also use Ant in your development environment.

6.8 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 Oracle CQL processors that handle information from multiple data feeds. In the example, the data feeds are simulated using the Oracle Event Processing load generator utility.

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

Figure 6-5 FX Example Event Processing Network

Description of Figure 6-5 follows
Description of "Figure 6-5 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 Oracle CQL 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 Oracle CQL 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 Oracle CQL processor, called FindCrossRates, 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 Oracle CQL 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 Event Processing 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 Event Processing http pub-sub server.

6.8.1 Run 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 Event Processing server.

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/Middleware/my_oep/oep/examples/ domains/fx_domain/defaultserver.

  2. Start Oracle Event Processing by executing the appropriate script with the correct command line arguments:

    1. On Windows:

      • prompt> startwlevs.cmd
        
    2. On UNIX:

      • prompt> ./startwlevs.sh
        
  3. When prompted, enter wlevs for the user name and password.

    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.

  5. Change to the /Oracle/Middleware/my_oep/utils/load-generator directory.

  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 (the message will likely be on one line):

    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.

6.8.2 Build and Deploy 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 Description of the Ant Targets to Build Hello World.

Build and deploy the foreign exchange example from the source directory:

  1. If the FX Oracle Event Processing instance is not already running, follow the procedure in Run 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/Middleware/my_oep/oep/examples/source/applications/fx.
  3. Execute the all Ant target to compile and create the application JAR file:
    prompt> ant all
    
  4. Execute the deploy Ant target to deploy the application JAR file to Oracle Event Processing:
    prompt> ant -Dusername=wlevs -Dpassword=wlevs -Daction=update deploy
    

    Caution:

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

  5. If the load generators required by the FX application are not running, start them as described in Run the Foreign Exchange Example.

    After the server starts, 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.

6.8.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 puts the application into a JAR file called com.bea.wlevs.example.fx_12.1.3.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 Event Processing using the Deployer utility.

6.8.4 Implementation of the FX Example

All the files of the FX example are located relative to the /Oracle/Middleware/my_oep/examples/source/applications/fx directory.

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 Event Processing application.

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

  • The processor.xml file configures the processor components for the application:

    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 summarizeResults Oracle CQL processor 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.

  • 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 Event Processing APIs referenced in this POJO, see Java API Reference for Oracle Event Processing.

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

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

    The FX example uses a build.xml Ant file to compile, assemble, and deploy the OSGi bundle; see Build and Deploy 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.

6.9 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 the pattern occurring by keeping track of successive stock prices for a particular symbol; if more than three successive prices are larger than the one before it, this is considered a pattern.

Figure 6-6 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 6-6 The Signal Generation Example Event Processing Network

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

The application simulates a market data feed using the Oracle Event Processing 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 Event Processing. Computing valid latencies requires very tight clock synchronization, such as 1 millisecond, between the computer running the load generator and the computer running Oracle Event Processing. For this reason, Oracle recommends running both the load generator and Oracle Event Processing on a single multi-CPU computer where they will share a common clock.

The example also shows how to use the Oracle Event Processing 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.

6.9.1 Run 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 Event Processing in that domain.

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/Middleware/my_oep/oep/examples/domains/signalgeneration_domain/defaultserver.

  2. Start Oracle Event Processing by executing the appropriate script with the correct command line arguments:

    1. On Windows:

      • prompt> startwlevs.cmd
        
    2. On UNIX:

      • prompt> ./startwlevs.sh
        
  3. When prompted, enter wlevs for the user name and password.

  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/Middleware/my_oep/examples/domains/signalgeneration_domain/defaultserver/utils directory.

  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 Event Processing 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 follows:

6.9.2 Build and Deploy 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 Description of the Ant Targets to Build Signal Generation.

Build and deploy the signal generation example from the source directory:

  1. If the signal generation Oracle Event Processing instance is not already running, follow the procedure in Run 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/Middleware/my_oep/oep/examples/source/ applications/signalgeneration.
  3. Execute the all Ant target to compile and create the application JAR file:
    prompt> ant all
    
  4. Execute the deploy Ant target to deploy the application JAR file to the /Oracle/Middleware/my_oep/examples/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.

  5. If the load generator required by the signal generation application is not running, start it as described in Run the Signal Generation Example.
  6. Invoke the example dashboard as described in Run the Signal Generation Example.

6.9.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 puts the application into a JAR file called com.bea.wlevs.example.signalgen_12.1.2.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 Event Processing using the Deployer utility.

6.9.4 Implementation of the Signal Generation Example

All the files of the signal generation are located relative to the /Oracle/Middleware/my_oep/examples/source/applications/signalgeneration directory.

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.

  • 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.

  • 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 general information about programming event sinks, see Handling Events with Sources and Sinks in Oracle Fusion Middleware Developing Application for Oracle Event Processing .

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

    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 Event Processing, see Overview of Application Assembly and Deployment in Oracle Fusion Middleware Developing Application for Oracle Event Processing .

  • 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 Event Processing APIs referenced in ForeignExchangeBuilderFactory, see Java API Reference for Oracle Event Processing.

The signal generation example uses a build.xml Ant file to compile, assemble, and deploy the OSGi bundle; see Build and Deploy 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.

6.10 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 Event Processing-provided default Berkeley database to store the events. The example also shows how to configure a publishing HTTP pub-sub adapter as a stage in the event processing network.

Figure 6-7 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 6-7 The Event Record and Playback Example Event Processing Network

Description of Figure 6-7 follows
Description of "Figure 6-7 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 Event Processing HTTP Pub-Sub server.

6.10.1 Run 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 Event Processing in the domain, as described in the following procedure.

The procedure then shows you how to use Oracle Event Processing 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 Event Processing Visualizer to view the stream of events being published to a channel by the playbackHttpPublisher adapter.

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/Middleware/my_oep/oep/ examples/domains/recplay_domain/defaultserver.

  2. Start Oracle Event Processing by executing the appropriate script with the correct command line arguments:

    1. On Windows:

      • prompt> startwlevs.cmd
        
    2. On UNIX:

      • prompt> ./startwlevs.sh
        

    After the server starts, you should see the following message printed to the output:

        SimpleEvent created at: 14:33:40.441
    

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

  3. Invoke the following URL in your browser:

    http://host:port/wlevs
    

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

    The Logon screen displays.

  4. In the Logon screen, enter the Username oepadmin and Password welcome1, and click Login.

    The Oracle Event Processing Visualizer dashboard displays.

  5. In the left panel, select WLEventServerDomain > NonClusteredServer > Applications > recplay > stages > simpleEventSource.

  6. In the right panel, select the Record tab as follows:

    The DataSet Name field contains the value of the record-parameters child element dataset-name element from the simpleEventSource adapter application configuration file /Oracle/Middleware/my_oep/examples/domains/recplay_domain/defaultserver/applications/recplay/config.xml.

    <adapter>
        <name>simpleEventSource</name>
        <record-parameters>
            <dataset-name>recplay_sample</dataset-name>
            <event-type-list>
                <event-type>SimpleEvent</event-type>
            </event-type-list>
            <batch-size>1</batch-size>
            <batch-time-out>10</batch-time-out>
        </record-parameters>
    </adapter>
    
  7. At the bottom of the Record tab, click Start.

    An Alert dialog displays.

  8. 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.

  9. In the left panel, select eventStream.

  10. In the right panel, select the Playback tab as follows:

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

    An Alert dialog appears as shown in Figure 6-8.

    Figure 6-8 Start Playback Alert Dialog

    Description of Figure 6-8 follows
    Description of "Figure 6-8 Start Playback Alert Dialog"
  12. 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 Event Processing 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.

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

    1. In the top panel, select Viewstream.

      The Viewstream window displays.

    2. In the right panel, 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.

6.10.2 Build and Deploy the Event Record/Playback Example

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 Description of the Ant Targets to Build the Record and Playback Example.

Build and deploy the event record/playback example from the source directory:

  1. If the record/playback Oracle Event Processing instance is not already running, follow the procedure in Run 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/Middleware/my_oep/oep/examples/source/ applications/recplay.
  3. Execute the all Ant target to compile and create the application JAR file:
    prompt> ant all
    
  4. Execute the deploy Ant target to deploy the application JAR file to the /Oracle/Middleware/my_oep/examples/domains/recplay_domain/defaultserver/applications/recplay directory:
    prompt> ant -Dusername=oepadmin -Dpassword=welcome1 -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.

  5. Follow the instructions in Run the Event Record/Playback Example, starting at step 4, to invoke Oracle Event Processing Visualizer and start recording and playing back events.

6.10.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 puts the application into a JAR file called com.bea.wlevs.example.recplay_12.1.2.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 Event Processing using the Deployer utility.

6.10.4 Implementation of the Record and Playback Example

All the files of the example are located relative to the /Oracle/Middleware/my_oep/examples/source/applications/recplay directory.

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 6-7.

    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 how to program the adapter Java files in general, see Overview of Custom Adapters in Oracle Fusion Middleware Developing Application for Oracle Event Processing .

  • 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.

  • 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.

  • 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 Event Processing.

    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 Event Processing, see Overview of Application Assembly and Deployment.

The record/playback example uses a build.xml Ant file to compile, assemble, and deploy the OSGi bundle; see Build and Deploy the Event Record/Playback Example for a description of this build.xml file if you also use Ant in your development environment.