This chapter introduces the sample code provided with the Oracle Stream Analytics installation and describes how to set up and use the code. You must have installed Oracle Stream Analytics with the Examples check box checked.
This chapter covers the following topics:
When you choose to include examples during installation, the Oracle Stream Analytics installation includes the following samples:
HelloWorld: Provides a basic skeleton for an Oracle Stream Analytics application.
Oracle CQL: Shows how to use the Oracle Stream Analytics 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 Stream Analytics installation directory is referred to as /Oracle/Middleware/my_oep/.
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.
The sample HelloWorld domain is located in /Oracle/Middleware/my_oep/oep/ examples/domains/helloworld_domain
.
See Run the HelloWorld Example from the helloworld Domain for details.
The sample CQL domain is located in /Oracle/Middleware/my_oep/oep/ examples/domains/cql_domain.
See Run the CQL Example for details.
The sample Oracle Spatial domain is located in /Oracle/Middleware/my_oep/oep/ examples/domains/spatial_domain
.
See Run the Oracle Spatial Example for details.
The sample Foreign Exchange domain is located in /Oracle/Middleware/my_oep/ oep/examples/domains/fx_domain
.
See Run the Foreign Exchange Example for details.
The sample Signal Generation domain is located in /Oracle/Middleware/my_oep/ oep/examples/domains/signalgeneration_domain
.
See Run the Signal Generation Example for details.
The sample Record and Playback domain is in /Oracle/Middleware/my_oep/ oep/examples/domains/recplay_domain
.
See Run the Event Record/Playback Example for details.
The Java and configuration XML source for each sample is provided in a separate source directory that describes a sample development environment.
The HelloWorld source directory is located in /Oracle/Middleware/my_oep/oep/ examples/source/applications/helloworld
.
See Implementation of the HelloWorld Example for details.
The CQL source directory is located in /Oracle/Middleware/my_oep/oep/ examples/source/applications/cql
.
See Implementation of the CQL Example for details.
The Oracle Spatial source directory is in /Oracle/Middleware/my_oep/oep/examples/source/applications/spatial
.
See Implementation of the Oracle Spatial Example for details.
The Foreign Exchange source directory is located in /Oracle/Middleware/my_oep/ oep/examples/source/applications/fx
.
See Implementation of the FX Example for details.
The Signal Generation source directory is located in /Oracle/Middleware/my_oep/ oep/ examples/source/applications/signalgeneration
.
See Implementation of the Signal Generation Example for details.
The Record and Playback source directory is located in /Oracle/Middleware/my_oep/ oep/examples/source/applications/recplay
.
See Implementation of the Record and Playback Example for details.
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}
The Oracle Stream Analytics Visualizer is a Web 2.0 application that consumes data from Oracle Stream Analytics, 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 Stream Analytics so as to change its configuration.
Visualizer is itself an Oracle Stream Analytics 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 Stream Analytics. 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 Stream Analytics Visualizer, see Developing Applications for Event Processing with Oracle Stream Analytics.
When you run Oracle Stream Analytics 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.
The HelloWorld sample shows how to create a typical Oracle Stream Analytics application.
Figure 7-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 7-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.
The HelloWorld application is pre-deployed to the helloworld
domain. To run the application, start an instance of Oracle Stream Analytics server.
Run the HelloWorld example from the helloworld domain:
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.
Start Oracle Stream Analytics by executing the appropriate server startup script with the correct command-line arguments:
On Windows:
prompt> startwlevs.cmd
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.
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:
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.
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 Stream Analytics using the Deployer utility.
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 Stream Analytics 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 Stream Analytics 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.
For a detailed description of this file and how to program the adapter Java files in general, see Integrating an External Component Using a Custom Adapter in Developing Applications for Event Processing with Oracle Stream Analytics.
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.
For a detailed description of this file and general information about programming event sinks, see Handling Events with Java in Oracle Fusion Middleware Developing Application for Oracle Event Processing .
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.
For more information about creating this file and a description of creating the OSGi bundle that you deploy to Oracle Event Processing, see Oracle Fusion Middleware Developing Application for Oracle Event Processing .
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.
The Oracle Continuous Query Language (Oracle CQL) example shows how to use the Oracle Stream Analytics Visualizer Query Wizard to construct various types of Oracle CQL queries.
Figure 7-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 7-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.
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 Stream Analytics server.
To run the CQL example:
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.
Start Oracle Stream Analytics by executing the appropriate script with the correct command line arguments:
On Windows:
prompt> startwlevs.cmd
On UNIX:
prompt> ./startwlevs.sh
The CQL application is now ready to receive data from the data feeds.
To simulate the data feed for the missing event query, open a new command window.
Change to the /Oracle/Middleware/my_oep/oep/utils/load-generator
.
Run the load generator using the orderData.prop
properties file:
On Windows:
prompt> runloadgen.cmd orderData.prop
On UNIX:
prompt> ./runloadgen.sh orderData.prop
Change to the /Oracle/Middleware/my_oep/oep/utils/load-generator
.
To simulate the data feed for the moving average query, open a new command window
Run the load generator using the StockData.prop
properties file:
On Windows:
prompt> runloadgen.cmd StockData.prop
On UNIX:
prompt> ./runloadgen.sh StockData.prop
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 Stream Analytics Visualizer Query Plan.
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:
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 Stream Analytics using the Deployer utility.
This section describes how to create the queries that the CQL example uses, including:
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 7-1 lists:
Table 7-1 Valid Order Workflow
Event Type | Description |
---|---|
|
Customer order |
|
Approval |
|
Shipment |
However, it is an error if an order is shipped without an approval event as Table 7-2 lists:
Table 7-2 Invalid Order Workflow
Event Type | Description |
---|---|
|
Customer order |
|
Shipment |
You will create and test a query that detects the missing approval event and generates an alert event:
Create the missing event query:
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.
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.
In the Logon screen, enter the Username oepadmin
, Password welcome1
and click Login.
The Oracle Event Processing Visualizer dashboard displays.
In the right panel, expand WLEventServerDomain > NonClusteredServer > Applications.
Select the cql node.
The CQL application screen displays.
Select the Event Processing Network tab.
The Event Processing Network screen displays.
Double-click the orderProcessor Oracle CQL processor icon.
The Oracle CQL processor screen displays.
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.
Click the Templates tab.
The Templates tab displays.
Click and drag the Pattern Match Template from the Templates palette and drop it anywhere in the Query Wizard canvas.
Double-click the SSource icon.
The SSource configuration screen displays.
The source of your query is the orderChannel
stream.
Configure the SSource as follows:
Select Stream as the Type.
Select orderChannel from the Select a source pull-down menu.
Click Save.
Click Save Query.
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.
Enter the following expression in the Pattern Expression field:
CustOrder NoApproval*? Shipment
This pattern uses the Oracle CQL pattern quantifiers that Table 7-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 7-3 MATCH_RECOGNIZE Pattern Quantifiers
|
For more information, see Oracle Fusion Middleware Oracle CQL Language Reference for Oracle Event Processing.
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.
Enter Orders in the Alias field.
This assigns an alias (Orders
) for the pattern to simplify its use later in the query.
Click the Define tab.
The Define tab displays.
You will now define each of the conditions named in the pattern clause as Table 7-4 lists:
Table 7-4 Condition Definitions
Condition Name | Definition |
---|---|
|
|
|
|
|
|
Enter CustOrder in the Object Name field.
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'
.
Click Save.
Click the Plus Sign button.
The condition definition is added to the Object List as follows:
Enter NoApproval in the Object Name field.
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.
Click Save.
Click the Plus Sign button.
The condition definition is added to the Object List.
Enter Shipment in the Object Name field.
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'
.
Click Save.
Click the Plus Sign button.
The Define tab displays.
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
For more information, see Oracle Fusion Middleware Oracle CQL Language Reference for Oracle Event Processing.
Enter orderid in the Object Name field.
Click the Expression Builder button and configure the Expression Builder:
In the Variables list, double-click CustOrder.orderid.
Click Save.
Click the Plus Sign button.
Enter amount in the Object Name field.
Click the Expression Builder button and configure the Expression Builder:
In the Variables list, double-click CustOrder.amount.
Click Save.
Click the Plus Sign button.
The Measure tab displays.
Click Save.
Double-click the Select icon.
The Select configuration screen appears as follows:
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.
Double-click orderid in the Properties list and select orderid from the Select or Input Alias pull-down menu.
Click the Plus Sign button to add the property to the Generated CQL Statement.
Double-click amount in the Properties list and select amount from the Select or Input Alias pull-down menu.
Click the Plus Sign button to add the property to the Generated CQL Statement.
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.
Click the Plus Sign button to add the property to the Generated CQL Statement.
The Project tab displays.
Click Save.
Click Save Query.
Double-click the Output icon.
The Output configuration screen displays.
Configure the Output as follows:
Select Query.
Enter Tracking as the Query Name.
Click Inject Rule.
The Inject Rule Confirmation dialog displays.
Click OK.
The Query Wizard adds the rule to the cqlProc
processor.
Click Save.
Click the CQL Rules tab.
The CQL Rules tab displays.
Click the Query radio button.
Confirm that your Tracking
query is present.
Test the missing event query:
To simulate the data feed, change to the /Oracle/Middleware/my_oep/utils/load-generator
directory.
Run the load generator using the orderData.prop
properties file:
On Windows:
prompt> runloadgen.cmd orderData.prop
On UNIX:
prompt> ./runloadgen.sh orderData.prop
In the Oracle Event Processing Visualizer, click the ViewStream button in the top panel.
The Stream Visualizer screen displays.
Click Initialize Client.
Click the Subscribe tab.
Select the orderalert radio button.
Click Subscribe.
As missing events are detected, the Oracle Event Processing updates the Received Messages area showing the AlertEvents
generated.
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:
First, you create a view (the Oracle CQL equivalent of a subquery) that serves as the source of the moving average query.
Second, you create the moving average query using the source view.
See "Create the moving average query using the view source:".
Finally, you test the moving average query.
Create a view source for the moving average query:
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.
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.
In the Logon screen, enter the Username oepadmin
and Password welcome1
, and click Login.
The Oracle Event Processing Visualizer dashboard displays.
In the right panel, expand WLEventServerDomain > NonClusteredServer > Applications.
Select the cql node.
The CQL application screen displays.
Select the Event Processing Network tab.
The Event Processing Network screen displays.
Double-click the stockProcessor Oracle CQL processor icon.
The Oracle CQL processor screen appears as Figure 7-3 shows.
Figure 7-3 Oracle CQL Processor: General Tab
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.
Click and drag an SSource icon (Stream Source) from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as.
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.
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.
Click Save.
Click Save Query.
When prompted, enter StockVolGt1000 in the Query Id field.
Click Save.
Next, you will add an Oracle CQL filter.
Click and drag a Filter icon from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as follows:
Click the SSource icon and drag to the Window icon to connect the Oracle CQL constructs as follows:
Double-click the Filter icon.
The Filter configuration screen displays:
Click the Expression Builder button.
The Expression Builder dialog appears.
Configure the Expression Builder as follows:
Select StockVolGt100 from the Select an Event Type pull-down menu to define the variables you can use in this expression.
Double-click the volume 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.
Click Save.
Click Add Filter.
The Query Wizard adds the expression to the Generated CQL Statement as follows:
Click Save.
Click Save Query.
Next you want to add a select statement.
Click and drag a Select icon from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as follows:
Click the Filter icon and drag to the Select icon to connect the Oracle CQL constructs.
Double-click the Select icon.
The Select configuration screen appears.
You want to select price
, symbol
, and volume
from your StockVolGt1000
stream.
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.
Click Save.
Click Save Query.
Finally, you will add an Output.
Click and drag an Output icon from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as follows:
Click the Select icon and drag to the Output icon to connect the Oracle CQL constructs.
Double-click the Output icon.
The Output configuration screen appears.
Configure the Output as follows:
Select View.
Configure View Name as StockVolGt1000
.
Delete the contents of the View Schema field.
You can let the Oracle Event Processing server define the view schema for you.
Click Inject Rule.
The Inject Rule Confirmation dialog appears as follows:
Click OK.
The Query Wizard adds the rule to the cqlProc
processor.
Click Save.
Click the CQL Rules tab.
The CQL Rules tab displays.
Click the View radio button.
Confirm that your StockVolGt1000
view is present.
Create the moving average query using the view source:
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.
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.
In the Logon screen, enter the Username oepadmin
and Password welcome1
, and click Login.
The Oracle Event Processing Visualizer dashboard displays.
In the left panel, expand WLEventServerDomain > NonClusteredServer > Applications.
Select the cql stage.
The CQL application screen displays.
Select the Event Processing Network tab.
The Event Processing Network screen displays.
Double-click the stockProcessor Oracle CQL processor icon.
The Oracle CQL processor screen displays.
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.
Click and drag an SSource icon (Stream Source) from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as follows:
Double-click the SSource icon.
The SSource configuration screen appears.
Configure the SSource dialog as follows:
Select View as the Type.
Select the StockVolGt1000 view from the Select a source pull-down menu.
Click Save.
Click Save Query.
Click and drag a Window icon from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as follows:
Click the SSource icon and drag to the Window icon to connect the Oracle CQL constructs.
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
.
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.
Click Add Window.
The Query Wizard adds the sliding window to the Generated CQL Statement as follows:
Click Save.
Click Save Query.
Click and drag a Select icon from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as follows:
Click the Window icon and drag to the Select icon to connect the Oracle CQL constructs.
Double-click the Select icon.
The Select configuration screen appears.
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:").
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.
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.
Click the pull-down menu next to the AS field and select symbol.
Click the Plus Sign button.
The source property is added to the project expression of the Generated CQL Statement as follows:
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.
Click the Expression Builder button.
The Expression Builder dialog appears.
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.
Select the StockVolGt1000.price in the Expression Builder field.
Double-click the AVG function.
The AVG()
function is wrapped around your selection in the Expression Builder field as follows:
Click Save.
The expression is added to the Project Expression field as follows:
Click the pull-down menu next to the AS field and select movingAvgPrice.
Click the plus Sign button.
The source property is added to the project expression of the Generated CQL Statement as follows:
Click Validate.
A validation error dialog is shown as follows:
Because you are partitioning, you must specify a GROUP BY
clause.
Select the Group tab.
The Group tab appears.
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:
Click Save.
Click Save Query.
Next, you want to connect the query to an output.
Click and drag an Output icon from the CQL Constructs palette and drop it anywhere in the Query Wizard canvas as follows:
Click the Select icon and drag to the Output icon to connect the Oracle CQL constructs.
Double-click the Output icon.
The Output configuration screen appears.
Configure the Output as follows:
Select Query.
Enter MovingAverage as the Query Name.
Click Inject Rule.
The Inject Rule Confirmation dialog displays.
Click OK.
The Query Wizard adds the rule to the cqlProc
processor.
Click Save.
Click the CQL Rules tab.
The CQL Rules tab displays.
Click the Query radio button.
Confirm that your MovingAverage
query is present.
Test the moving average query:
To simulate the data feed for the moving average query, change to the /Oracle/Middleware/my_oep/utils/load-generator
directory.
Run the load generator using the stockData.prop
properties file:
On Windows:
prompt> runloadgen.cmd stockData.prop
On UNIX:
prompt> ./runloadgen.sh stockData.prop
In the Oracle Event Processing Visualizer, click the ViewStream button in the top panel.
The Stream Visualizer screen displays.
Click Initialize Client.
Enter /stockmoving
in the Initialize client field.
Click Subscribe.
As the moving average query outputs events, the Oracle Event Processing updates the Received Messages area showing the events generated.
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 7-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 7-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 Stream Analytics 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 Stream Analytics.
The Oracle Spatial application is pre-deployed to the spatial_domain
domain. To run the application, you simply start an instance of Oracle Stream Analytics server.
Run the Oracle Spatial example from the spatial_domain domain:
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
.
Start Oracle Stream Analytics by executing the appropriate script with the correct command line arguments:
On Windows:
prompt> startwlevs.cmd
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.
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 Stream Analytics.
The Oracle Spatial example Web page displays.
Click the Bus Top Arrivals tab to view bus stop arrivals as follows:
Execute the Oracle Stream Analytics load generator to generate sample data:
Open a command prompt and navigate to /Oracle/Middleware/my_oep/utils/load-generator.
On Windows, type:
runloadgen.cmd bus_positions.prop
On UNIX, type:
./runloadgen.sh bus_positions.prop
Observe the bus movements and alerts in the browser as follows:
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:
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 Stream Analytics using the Deployer utility.
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 Stream Analytics 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 Stream Analytics APIs referenced in this POJO, see Java API Reference for Oracle Stream Analytics.
A MANIFEST.MF
file that describes the contents of the OSGi bundle that will be deployed to Oracle Stream Analytics.
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 Stream Analytics, see Developing Applications for Event Processing with Oracle Stream Analytics.
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.
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 Stream Analytics load generator utility.
Figure 7-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 7-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 Stream Analytics 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 Stream Analytics http pub-sub server.
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 Stream Analytics server.
Run the foreign exchange example:
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
.
Start Oracle Stream Analytics by executing the appropriate script with the correct command line arguments:
On Windows:
prompt> startwlevs.cmd
On UNIX:
prompt> ./startwlevs.sh
When prompted, enter wlevs for the user name and password.
The FX application is now ready to receive data from the data feeds.
To simulate an American data feed, open a new command window.
Change to the /Oracle/Middleware/my_oep/utils/load-generator
directory.
Run the load generator using the fxAmer.prop
properties file:
On Windows:
prompt> runloadgen.cmd fxAmer.prop
On UNIX:
prompt> ./runloadgen.sh fxAmer.prop
Repeat steps 4 - 6 to simulate an Asian data feed, using the fxAsia.prop
properties file:
On Windows:
prompt> runloadgen.cmd fxAsia.prop
On UNIX:
prompt> ./runloadgen.sh fxAsia.prop
Repeat steps 4 - 6 to simulate an European data feed, using the fxEuro.prop
properties file:
On Windows:
prompt> runloadgen.cmd fxEuro.prop
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.
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:
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 Stream Analytics using the Deployer utility.
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 Stream Analytics 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 Stream Analytics APIs referenced in this POJO, see Java API Reference for Oracle Stream Analytics.
A MANIFEST.MF
file that describes the contents of the OSGi bundle that will be deployed to Oracle Stream Analytics.
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 Stream Analytics, see Overview of Application Assembly and Deployment in Developing Applications for Event Processing with Oracle Stream Analytics.
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.
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 7-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 7-6 The Signal Generation Example Event Processing Network
The application simulates a market data feed using the Oracle Stream Analytics 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 Stream Analytics. Computing valid latencies requires very tight clock synchronization, such as 1 millisecond, between the computer running the load generator and the computer running Oracle Stream Analytics. For this reason, Oracle recommends running both the load generator and Oracle Stream Analytics on a single multi-CPU computer where they will share a common clock.
The example also shows how to use the Oracle Stream Analytics 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.
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 Stream Analytics in that domain.
Run the signal generation example:
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
.
Start Oracle Stream Analytics by executing the appropriate script with the correct command line arguments:
On Windows:
prompt> startwlevs.cmd
On UNIX:
prompt> ./startwlevs.sh
When prompted, enter wlevs for the user name and password.
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.
0pen a new command window.
Change to the /Oracle/Middleware/my_oep/examples/domains/signalgeneration_domain/defaultserver/utils
directory.
Run the startDataFeed
command:
On Windows:
prompt> startDataFeed.cmd
On UNIX:
prompt> ./startDataFeed.sh
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 Stream Analytics is running; if it is the same computer as your browser, you can use localhost
.
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:
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:
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 Stream Analytics using the Deployer utility.
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 Stream Analytics .
A MANIFEST.MF
file that describes the contents of the OSGi bundle that will be deployed to Oracle Stream Analytics.
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 Stream Analytics, see Overview of Application Assembly and Deployment in Oracle Fusion Middleware Developing Application for Oracle Stream Analytics .
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 Stream Analytics APIs referenced in ForeignExchangeBuilderFactory
, see Java API Reference for Oracle Stream Analytics.
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.
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 Stream Analytics-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 7-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 7-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 Stream Analytics HTTP Pub-Sub server.
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 Stream Analytics in the domain, as described in the following procedure.
The procedure then shows you how to use Oracle Stream Analytics 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 Stream Analytics Visualizer to view the stream of events being published to a channel by the playbackHttpPublisher
adapter.
Run the event record/playback example:
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
.
Start Oracle Stream Analytics by executing the appropriate script with the correct command line arguments:
On Windows:
prompt> startwlevs.cmd
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 Stream Analytics server started correctly and that the simpleEventSource
component is creating events.
Invoke the following URL in your browser:
http://host:port/wlevs
where host refers to the name of the computer on which Oracle Stream Analytics is running and port refers to the Jetty NetIO port configured for the server (default value 9002
).
The Logon screen displays.
In the Logon screen, enter the Username oepadmin
and Password welcome1
, and click Login.
The Oracle Stream Analytics Visualizer dashboard displays.
In the left panel, select WLEventServerDomain > NonClusteredServer > Applications > recplay > stages > simpleEventSource.
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>
At the bottom of the Record tab, click Start.
An Alert dialog displays.
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.
In the left panel, select eventStream.
In the right panel, select the Playback tab as follows:
At the bottom of the tab, click Start.
An Alert dialog appears as shown in Figure 7-8.
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 Stream Analytics 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.
To view the events that the playbackHttpPublisher
adapter is publishing to a channel, follow these steps:
In the top panel, select Viewstream.
The Viewstream window displays.
In the right panel, click Initialize Client.
In the Subscribe Channel text box, enter /playbackchannel
.
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.
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:
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 Stream Analytics using the Deployer utility.
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 7-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 Stream Analytics .
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 Overview of Oracle Stream Analytics Event Types in Developing Applications for Event Processing with Oracle Stream Explorer.
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 more information about event sources and sinks, see Handling Events with Sources and Sinks in Oracle Fusion Middleware Developing Application for Oracle Stream Analytics .
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 Stream Analytics.
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 Stream Analytics, 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.