Application Development Guide

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Using a Persistent Store to Record and Playback Events

This section contains information on the following subjects:

 


Overview of Using a Persistent Store to Record and Playback Events

Oracle CEP event repository feature allows you to persist the events that flow out of a component of the event processing network (EPN) to a store, such as a database table, and then play them back at a later stage or explicitly query the events from a component such as an event bean.

A typical use case of this feature is the ability to debug a problem with a currently running application. If you have been recording the events at a node in the EPN when the problem occurred, you can later playback the same list of events to recreate the problem scenario for debugging purposes.

The following graphic shows the EPN of the Event Record and Playback example and demonstrates at what point events are recorded and where they are played back. The simpleEventSource adapter has been configured to record events; as indicated, the record happens as events flow out of the adapter. The eventStream stream has been configured to playback events; as indicated, the playback happens at the point where events flow into the stream.

Figure 9-1 Configuring Record and Playback in an EPN

Configuring Record and Playback in an EPN

The Event Store

Oracle CEP provides an RDBMS-based implementation of the event store; this implementation stores data in a relational database. You can use either the database server included with Oracle CEP (Apache Derby) or another database server, such as Oracle DBMS.

Oracle CEP includes a default database server, Apache Derby, that you can use to record events. Apache Derby is an open source relational database implemented entirely in Java. By default, Derby creates its database files and log file (derby.log) from the directory in which you started Oracle CEP, such as DOMAIN_DIR/servername. You can change this default location by setting the system property derby.system.home to a different directory.

You can also create a custom event store provider to store events in a non-RDBMS persistent store. For details, see Creating a Custom Event Store Provider.

Recording Events

You can configure recording for any component in the event processing network (EPN) that produces events: processors, adapters, streams, and event beans. Processors and streams always produce events; adapters and event beans must implement the EventSource interface. Additionally, you can configure that events from different components in the EPN be stored in different persistent stores, or that all events go to the same store. Note that only events that are outputted by the component are recorded.

You enable the recording of events for a component by updating its configuration file and adding the <record-parameters> element. Using the child elements of <record-parameters>, you specify the event store to which the events are recorded, an initial time period when recording should take place, the list of event types you want to store, and so on.

After you deploy the application and events start flowing through the network, recording begins either automatically because you configured it to start at a certain time or because you dynamically start it using administration tools. For each component you have configured for recording, Oracle CEP stores the events that flow out of it to the appropriate store along with a timestamp of the time it was recorded.

Playing Back Events

You can configure playback for any component in the event processing network (EPN): processors, adapters, streams, and event beans. Typically the playback component is a node later in the network than the node that recorded the events.

You enable the playback of events for a component by updating its configuration file and adding the <playback-parameters> element. Using the child elements of <playback-parameters>, you specify the event store from which the events are played back, the list event types you want to play back (by default all are played back), the time range of the recorded events you want to play back, and so on. By default, Oracle CEP plays back the events in a time accurate manner; however, you can also configure that the events get played back either faster or slower than they originally flowed out of the component from which they were recorded.

After you deploy the application and events start flowing through the network, you must start the playback by using the administration tools (Visualizer or wlevs.Admin). Oracle CEP reads the events from the appropriate persistent store and inserts them into the appropriate place in the EPN.

It is important to note that when a component gets a playback event, it looks exactly like the original event. Additionally, a component later in the network has been configured to record events, then Oracle CEP records the playback events as well as the "real" events.

Querying Stored Events

You can use the event store API to query a store for past events given a record time range and the component from which the events were recorded. The actual query you use depends on the event repository provider; for example, you would use EPL for the RDBMS provider included in Oracle CEP. You can also use these APIs to delete old events from the event store.

Restrictions on the Event Types that Can Be Recorded

In this release, the following restrictions apply to the event types that can be recorded to the event store if you use the Oracle RDBMS-based provider:

Record and Playback Example

The sample code in this section is taken from the recplay example, located in the ORACLE_CEP_HOME\ocep_10.3\samples\source\applications\recplay directory, where ORACLE_CEP_HOME refers to the main Oracle CEP installation directory, such as d:\oracle_cep.

See Event Record and Playback Example for details about running and building the example.

 


Implementing Record and Playback of Events in Your Application: Typical Steps

Depending on how you are going to use the event repository, there are different tasks that you must perform, as described in the following procedure that in turn point to sections with additional details.

Note: It is assumed in this section that you have already created an Oracle CEP application along with component configuration file(s) for the components and that you want to update the application so that components record or playback events. If you have not, refer to Overview of Creating Oracle Complex Event Processing Applications for details.
  1. Configure an event store for your Oracle CEP server instance. You must perform this configuration step even if you plan to use the event store provider provided by Oracle CEP, Apache Derby.
  2. See Configuring an Event Store for Oracle CEP Server.

  3. Configure a component in your EPN to record events by updating the component’s configuration file. The component can be a processor, adapter, stream, or event bean. Only events flowing out of the component are recorded.
  4. See Configuring a Component to Store Events.

  5. Configure a component in your EPN to playback events by updating the component’s configuration file. The component can be a processor, adapter, stream, or event bean. Only components that are also event sinks can playback events; events are played to the input side of the component.
  6. See Configuring a Component to Playback Events.

  7. Redeploy your application for the changes to take effect.
  8. If you have not specified an explicit start and end time for recording events, you must use Visualizer or wlevs.Admin to start recording. You must always use these administration tools to start and end the playback of events.
  9. See Starting and Stopping the Record and Playback of Events.

Configuring an Event Store for Oracle CEP Server

Oracle CEP stores recorded events in a database, which means that before you can start using the record and playback feature in your own application, you must specify where the database server is located along with the name of the database server that will contain the recorded events. You do this by updating the config.xml file of your Oracle CEP server instance, as described in later procedures.

You do not, however, create the actual tables that store the recorded events; Oracle CEP automatically does this for you after you deploy the application that uses the record and playback feature and recording starts to take place. See Description of the Database Tables Created by the RDMBS Provider for information about how Oracle CEP creates these tables.

To configure Oracle CEP for an event store, including the default Apache Derby, follow these steps:

  1. Stop your Oracle CEP server instance, if it is running.
  2. Using your favorite XML editor, open the server’s config.xml file for edit. The config.xml file is located in the DOMAIN_DIR/servername/config directory of your server, where DOMAIN_DIR refers to the domain directory, such as /oracle_cep/user_projects/domains/myDomain and servername refers to the name of your server, such as defaultserver.
  3. Configure access to your relational database by adding a <data-source> element to the config.xml file. For details, see Configuring Access to a Relational Database.
  4. If you want to use the default Apache Derby database, add the following <data-source> element:

    <?xml version="1.0" encoding="UTF-8"?>
    <n1:config xmlns:n1="http://www.bea.com/ns/wlevs/config/server"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <domain> 
    <name>myDomain</name>
    </domain>
    ...
    <data-source>
    <name>derby1</name>
    <connection-pool-params>
    <initial-capacity>15</initial-capacity>
    <max-capacity>50</max-capacity>
    </connection-pool-params>
    <driver-params>
    <url>jdbc:derby:dbtest1;create=true</url>
    <driver-name>org.apache.derby.jdbc.EmbeddedDriver</driver-name>
    </driver-params>
    </data-source>
    </n1:config>

    You can, of course, name the data source anything you want, as well as specify different connection pool parameters and database name (the sample above connects to the database dbtest1 and specifies that the database should be created if it does not already exist). The only element that must be the same as in the sample above is <driver-name>, whose value must be org.apache.derby.jdbc.EmbeddedDriver. You are required to add a <transaction-manager> element, although you can name it anything you want.

  5. Add a <transaction-manager> element to the config.xml file:
  6. <data-source>
    ...
    </data-source>
    <transaction-manager>
    <name>myTransactionManager</name>
    </transaction-manager>
  7. Add an <rdbms-event-store-provider> element to the config.xml file that in turn references the previously configured data source. For example, to use the Apache Derby database configured in the previous step, add the following XML snippet:
  8. <data-source>
    <name>derby1</name>
    ...
    </data-source>
    <rdbms-event-store-provider>
    <name>my-rdbms-provider</name>
    <data-source-name>derby1</data-source-name>
    </rdbms-event-store-provider>

    Later, when you configure the components that record and playback the events, you will specify the name of this event store.

Oracle CEP is now configured for an event store and you can configure specific components in your application to record or playback events.

Configuring a Component to Store Events

You can configure any processor, adapter, stream, or event bean in your application to record events. As with all other component configuration, you specify that a component records events by updating its configuration file. For general information about these configuration files, see Component Configuration Files.

This section describes the main steps to configure a component to record events. For simplicity, it is assumed in the procedure that you are configuring an adapter to record events and that you have already created its component configuration file.

See XSD Schema Reference for Component Configuration Files for the complete XSD Schema that describes the event recording configuration file elements.

Using your favorite XML editor, open the component configuration XML file and add a <record-parameters> child element to the component you want to configure to record events. For example, to configure an adapter called simpleEventSource:

  <?xml version="1.0" encoding="UTF-8"?>
<n1:config xmlns:n1="http://www.bea.com/ns/wlevs/config/application"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <adapter>
<name>simpleEventSource</name>
<record-parameters>
...
</record-parameters>
...
</adapter>
    ...
  </n1:config>

Add child elements to <record-parameters> to specify the name of the event store provider, the events that are stored, the start and stop time for recording, and so on. For example:

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

The following table lists the child elements of <record-parameters> that you can specify. Although only <dataset-name> is required, Oracle recommends that you also include <provider-name> to explicitly specify the name of the event store provider.

Table 9-1 Child Elements of <record-parameters>
Child Element
Description
<dataset-name>
Specifies the group of data that the user wants to group together.
In the case of the Oracle RDBMS-based provider, it specifies the database area, or schema, in which the tables that store the recorded events are created.
When configuring the Oracle RDBMS-based provider, you are required to specify this element.
<provider-name>
Specifies the name of the event store provider.
The value of this element corresponds to the value of the <name> child element of the <rdbms-event-store-provider> element in the config.xml file of the Oracle CEP server instance.
When configuring the Oracle RDBMS-based provider, you are required to specify this element.
<event-type-list>
Specifies the event types that are recorded to the event store. If this element is not specified, then Oracle CEP records all event types that flow out of the component.
Use the <event-type> child component to list all events, such as:
<event-type-list>
<event-type>EventOne</event-type>
<event-type>EventTwo</event-type>
</event-type-list>
When configuring the Oracle RDBMS-based provider, you are required to specify this element.
<time-range>
Specifies the time period during which recording should take place using a start and end time.
The time period is configured by using a <start> child element to specify a start time and an <end> child element to specify the end time. The start and end time formats are both MM-dd-yyyy:HH:mm:ss, such as 10-20-2007:11:22:07. For example, to specify that recording should start on April 7, 2009, at 6:00am and end on April 10, 2009, at 10:00 pm, enter the following
<time-range-offset>
<start>04-07-2009:06:00:00</start>
<end>04-10-2009:22:00:00</end>
</time-range-offset>
If you do not specify a time period, then no events are recorded when the application is deployed and recording will only happen after you explicitly start it using Visualizer or wlevs.Admin.
You can specify <time-range> or <time-range-offset>, but not both.
<time-range-offset>
Specifies the time period during which recording should take place, using a start time and a duration.
The time period is configured by using a <start> child element to specify a start time and <duration> child element to specify the amount of time after the start time that recording should stop. The start time format is MM-dd-yyyy:HH:mm:ss, such as 10-20-2007:11:22:07. The duration format is HH:mm:ss, such as 01:00:00. For example, to specify that recording should start on April 7, 2009, at 6:00am and continue for 3 hours, enter the following
<time-range-offset>
<start>04-07-2009:06:00:00</start>
<duration>03:00:00</duration>
</time-range-offset>
If you do not specify a time period, then no events are recorded when the application is deployed and recording will only happen after you explicitly start it using Visualizer or wlevs.Admin.
You can specify <time-range> or <time-range-offset>, but not both.
<batch-size>
Specifies the number of events that Oracle CEP picks up in a single batch from the event buffer to write the event store.
Default value is 1000.
<batch-time-out>
Specifies the number of seconds that Oracle CEP waits for the event buffer window to fill up with the <batch-size> number of events before writing to the event store.
Default value is 60
<max-size>
If specified, Oracle CEP uses a stream when writing to the event store, and this element specifies the size of the stream, with non-zero values indicating asynchronous writes.
Default value is 1024.
<max-threads>
If specified, Oracle CEP uses a stream when writing to the event store, and this element specifies the maximum number of threads that will be used to process events for this stream. Setting this value has no effect when <max-size> is 0.
The default value is 1.
<store-policy-paramters>
Specifies policy parameters, specific to the event store provider. Use the <name> and <value> child elements to specify a particular parameter, such as:
<store-policy-parameters>
<name>supportsTransactions</name>
<value>true</value>
</store-policy-parameters>

Configuring a Component to Playback Events

You can configure any processor, adapter, stream, or event bean in your application to playback events, although the component must be a node downstream of the recording component so that the playback component will actually receive the events and play them back. As with all other component configuration, you specify that a component plays back events by updating its configuration file. For general information about these configuration files, see Component Configuration Files.

This section describes the main steps to configure a component to play back events. For simplicity, it is assumed in the procedure that you are configuring a stream to playback events from a node upstream in the EPN that has recorded events, and that you have already created the stream’s configuration file.

See XSD Schema Reference for Component Configuration Files for the complete XSD Schema that describes the event playback configuration file elements.

Using your favorite XML editor, open the component configuration XML file and add a <playback-parameters> child element to the component you want to configure to playback events. For example, to configure a stream called eventStream:

  <?xml version="1.0" encoding="UTF-8"?>
<n1:config xmlns:n1="http://www.bea.com/ns/wlevs/config/application"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <stream>
<name>eventStream</name>
<playback-parameters>
...
</playback-parameters>
</stream>
    ...
  </n1:config>

Add child elements to <playback-parameters> to specify the name of the event store provider, the events that are played back, and so on. For example:

    <stream>
<name>eventStream</name>
<playback-parameters>
<dataset-name>recplay_sample</dataset-name>
<event-type-list>
<event-type>SimpleEvent</event-type>
</event-type-list>
<provider-name>test-rdbms-provider</provider-name>
</playback-parameters>
</stream>

The following table lists the child elements of <playback-parameters> that you can specify. Although only <dataset-name> is required, Oracle recommends that you also include <provider-name> to explicitly specify the name of the event store provider.

Table 9-2 Child Elements of <playback-parameters>
Child Element
Description
<dataset-name>
Specifies the group of data that the user wants to group together.
In the case of the Oracle RDBMS-based provider, it specifies the database area, or schema, in which the tables that store the recorded events are queried for the playback events.
When configuring the Oracle RDBMS-based provider, you are required to specify this element.
<provider-name>
Specifies the name of the event store provider.
The value of this element corresponds to the value of the <name> child element of the <rdbms-event-store-provider> element in the config.xml file of the Oracle CEP server instance.
When configuring the Oracle RDBMS-based provider, you are required to specify this element.
<event-type-list>
Specifies the event types that are played back from the event store. If this element is not specified, then Oracle CEP plays back all event types.
Use the <event-type> child component to list all events, such as:
<event-type-list>
<event-type>EventOne</event-type>
<event-type>EventTwo</event-type>
</event-type-list>
When configuring the Oracle RDBMS-based provider, you are required to specify this element.
<time-range>
Specifies the time period of the recorded events that you want to play back. In other words, this element acts as a filter so that only the events recorded during the specified time period are played back. This element does not specify a time period when the playback itself occurs.
The time period is configured by using a <start> child element to specify a start time and an <end> child element to specify the end time. The start and end time formats are both MM-dd-yyyy:HH:mm:ss, such as 10-20-2007:11:22:07. For example, to specify that you want to playback events that were recorded starting on April 7, 2009, at 6:00am and ending on April 10, 2009, at 10:00 pm, enter the following
<time-range-offset>
<start>04-07-2009:06:00:00</start>
<end>04-10-2009:22:00:00</end>
</time-range-offset>
If you do not specify a time period, then all events are played back.
You can specify <time-range> or <time-range-offset>, but not both.
<time-range-offset>
Specifies the time period of the recorded events that you want to play back. In other words, this element acts as a filter so that only the events recorded during the specified time period are played back. This element does not specify a time period when the playback itself occurs.
The time period is configured by using a <start> child element to specify a start time and <duration> child element to specify an amount of time after the start time. The start time format is MM-dd-yyyy:HH:mm:ss, such as 10-20-2007:11:22:07. The duration format is HH:mm:ss, such as 01:00:00. For example, to specify that you want to playback events that were recorded starting on April 7, 2009, at 6:00am and continued for three hours enter the following:
<time-range-offset>
<start>04-07-2009:06:00:00</start>
<duration>03:00:00</duration>
</time-range-offset>
If you do not specify a time period, then all events are played back.
<playback-speed>
Specifies the playback speed as a positive float.
The default value is 1, which corresponds to normal speed. A value of 2 means that events will be played back 2 times faster than the original record speed. Similarly, a value of 0.5 means that events will be played back at half the speed.
<repeat>
Specifies whether to playback events again after the playback of the specified time interval is over.
Valid values are true and false. Default value is false. A value of true means that the repeat of playback continues an infinite number of times until it is deliberately stopped. False means that events will be played back only once.
<max-size>
If specified, Oracle CEP uses a stream when playing back events from the event store, and this element specifies the size of the stream, with non-zero values indicating asynchronous writes.
Default value is 1024.
<max-threads>
If specified, Oracle CEP uses a stream when playing back events from the event store, and this element specifies the maximum number of threads that will be used to process events for this stream. Setting this value has no effect when <max-size> is 0.
The default value is 1.
<store-policy-paramters>
Specifies policy parameters, specific to the event store provider. Use the <name> and <value> child elements to specify a particular parameter, such as:
<store-policy-parameters>
<name>supportsTransactions</name>
<value>true</value>
</store-policy-parameters>

Starting and Stopping the Record and Playback of Events

After you configure the record and playback functionality for the components of an application, and you deploy the application to Oracle CEP, the server starts to record events only if you specified an explicit start/stop time in the initial configuration.

For example, if you included the following element in a component configuration:

  <time-range-offset>
<start>04-07-2009:06:00:00</start>
<end>04-10-2009:22:00:00</end>
</time-range-offset>

then recording will automatically start on April 7, 2009.

The only way to start the playback of events, however, is by using Visualizer or wlevs.Admin. You also use these tools to dynamically start and stop the recording of events. For details, see:

Visualizer and wlevs.Admin use managed beans (MBeans) to dynamically start and stop event recording and playback, as well as manage the event store configuration. A managed bean is a Java bean that provides a Java Management Extensions (JMX) interface. JMX is the Java EE solution for monitoring and managing resources on a network. You can create your own administration tool and use JMX to manage event store functionality by using the com.bea.wlevs.management.configuration.StageMBean.

Description of the Database Tables Created by the RDMBS Provider

When you enable event recording for a component, Oracle CEP automatically creates, if they do not already exist, the database tables that stores the actual data. The server connects to the database using the data source configured for the event store provider.

Oracle recommends that you allow Oracle CEP to create and manage these tables; however, if you want more control you can create your own tables.

The following guidelines describe how Oracle CEP creates the database tables, and thus the requirements if you decide to create your own tables. If the default name of a database object (schema, table, column) is a reserved word, Oracle CEP adds a suffix to come up with a non-reserved word.

The following table lists the supported Java types that can be fields of the event type.

Table 9-3 Supported Java Types
Java Type
Corrsponding Java SQL Type
boolean, java.lang.Boolean
java.sql.Types.BIT
byte, java.lang.Byte
java.sql.Types.TINYINT
short, java.lang,Short
java.sql.Types.SMALLINT
int, java.lang.Integer
java.sql.Types.INTEGER
long, java.lang.Long
java.sql.Types.BIGINT
float, java.lang.Float
java.sql.Types.REAL
double, java.lang.Double
java.sql.Types.DOUBLE
java.lang.String
java.sql.Types.VARCHAR
java.math.BigDecimal
java.sql.Types.BIGINT
java.sql.Date, java.util.Date
java.sql.Types.TIMESTAMP
java.sql.Time
java.sql.Types.TIME
java.sql.Timestamp
java.sql.Types.TIMESTAMP

 


Creating a Custom Event Store Provider

Oracle CEP provides an event store API that you can use to create a custom event store provider. Oracle provides an RDBMS-based implementation for storing events in a relational database, or one that supports JDBC connections. If you want to store events in a different kind of database, or for some reason the Oracle RDBMS provider is not adequate for your needs, then you can create your own event store provider using the event store API.

The event store API is in the com.bea.wlevs.eventstore package; the following list describes the most important interfaces:


  Back to Top       Previous  Next