Forwarding Sensor Events to Oracle Streams by Using the Oracle Sensor Edge Server

Purpose

This tutorial shows how to use Streams Dispatcher with Sensor Edge Server.

Time to Complete

Approximately 30 minutes.

Topics

This tutorial covers the following topics:

 Overview
 Prerequisites

Configuring the Streams Dispatcher

 Adding Rules
 Summary
 Related information

Viewing Screenshots

 Place the cursor over this icon to load and view all the screenshots for this tutorial. (Caution: This action loads all screenshots simultaneously, so, depending on your Internet connection, may result in a slow response time.)

Note: Alternatively, you can place the cursor over an individual icon in the following steps to load and view only the screenshot associated with that step. You can hide an individual screenshot by clicking it.

Overview

The Oracle Sensor Edge Server is a middle-tier component that integrates sensors and other types of command or response indication equipment with applications. Sensors are hardware or software endpoints that make observations of certain changes of state in the environment. The Sensor Edge Server uses these sensors to integrate sensor data and applications.

Oracle Sensor Edge Server supports using Streams as one of the event distribution methods. When events are read in the devices, they are normalized by the drivers and sent to filters for filtering. After the data is "cleansed" and filtered, they are passed to the dispatchers for distribution. Oracle Sensor Edge Server uses plug-ins called dispatchers to communicate with applications and event distribution systems. One of the built-in dispatcher is the Streams Dispatcher. The Streams Dispatcher is a plug-in that sends and receives events using Oracle Streams technology.

Instead of talking directly to an application, the Streams Dispatcher hands off all the events into a Streams Staging area. Once the events are dropped off in the staging area, a background job will pick them up and evaluate it against a set of rules.

A rule is a condition that can be either matched or not matched by an event. If the condition is satisfied for this event, a corresponding user-defined action will be taken. A rule has four parts:

  1. Name: A unique name of this rule provided by the caller that created the rule.
  2. Condition: This is like a "WHERE" clause, but without the WHERE keyword.
  3. Command: This provides instructions on what to do, and it can be either "call" to call a PL/SQL procedure, or "queue" to push the event to another queue.
  4. Parameter: Param is the parameter for the command. For a "call" command, it is the PL/SQL name. For a "queue" command, it is the queue name.

Before you use the Streams Dispatcher, you have to set up a database instance to hold the Streams staging area, the rules, the queues, Sensor Data Archive, and other related data. Once the schema is ready, you point the Streams Dispatcher to it and start collecting data. This tutorial describes how to collect and route events using Streams technology.

Back to Topic List

 

Prerequisites

Before starting this tutorial, you should complete the following tasks:

1.

Have access to or have installed Standard or Enterprise Edition of Oracle Database 9i Release 2 or later version. The steps to install the database are shown in Installing Oracle Database 10g on Windows tutorial.
Install Oracle9i Database Release 2 (or a later version).

2.

Have access to or have installed Oracle Application Server 10g 10.1.3. You can download Oracle Application Server 10g 10.1.3 from here.

3. Have access to or have installed Oracle Sensor Edge Server. You can download Oracle Sensor Edge Server from here.
4. Have installed Sensor Data Repository (SDR) and Sensor Data Streams (SDS).

Back to Topic List

 

Configuring the Streams Dispatcher

Configuring the Oracle Sensor Edge Server to use Oracle Streams and Advanced Queuing enables you to control how the edge dispatcher retrieves and distributes event messages. Unlike the Web Services, or HTTP Dispatcher options, event messages dispatched using the Streams Dispatcher do not have to be relayed directly to an entry point. The Streams Dispatcher supports rule-based process and agent technologies.

To configure Sensor Edge Server to use the streams dispatcher, perform the following steps:

1.

Open a browser window and enter the URL for the Sensor Edge Server:

http://<hostname>.<domain>:<port>/edge

For example, http://localhost:8888/edge

Enter the OC4J administrator username and OC4J administrator password. Click Login.

 

2.

Scroll down the Edge Server Configuration page and click Change Dispatcher. Also make sure that the Log Level is set to monitor.

 

3.

Select Streams Dispatcher V2. Click Select.

 

4.

Click Save Changes.

 

5.

When you make any change in an Oracle Sensor Edge Server instance, the Sensor Edge Server (SES) console displays a message notifying you to restart the Oracle Sensor Edge Server instance using OracleAS Enterprise Manager. Click the Enterprise Manager link to restart OC4J.

 

6.

The Login page for OracleAS Enterprise Manager appears. Enter the OC4J username and password. Click Login.

 

7.

Click the home link on the Cluster Topology page.

 

8.

Click Applications.

 

9.

Select edge, and click Restart.

 

10.

Click Yes on the Confirmation page.

 

11.

The Oracle Sensor Edge Server instance has been restarted successfully.

 

The Streams Dispatcher will attempt to connect to the Sensor Data Streams schema.

Back to Topic List

 

Adding Rules

 

This section shows how to invoke a PL/SQL procedure to handle data from the streams apply process. When you create a rule and add it, the rule will fire when an event occurs and a specified condition is met. This in turn calls the PL/SQL procedure. To add rules to the instance, perform the following steps:

1.

Open a browser window and enter the following URL:

http://<hostname>.<domain>:<port>/edge/tools/rules.jsp

If required, enter the username and password as oc4jadmin and welcome1. Click Login.

 

2.

Scroll down to Add New Rule in the SDS Rules section. Enter or select the following:

Name: myrule
Condition: :event.type=200
Action: Call PL/SQL Procedure
Parameter: testProc

Click Add Rule.

You are creating a rule, which will fire if the incoming event type is 200 (which means an RFID sensor reading).


3.

Invoke the URL and verify that the rule has been added (Observe the top section of the table).

http://<hostname>.<domain>:<port>/edge/tools/rules.jsp

 

4.

Open a command window and change directory to < edgeserver_home>\edge\sql\10.1.3 where edgeserver_home is the folder in which edge server is installed. Log in to SQL*Plus as the edge user by issuing the following command:

sqlplus edge/< password for edge user>

 

5.

If you run events in to the SDS, and you have registered the PL/SQL callback, you will see the event being logged in to edg_log table. All logging is done at the edg_utl.tcDebug log level. Execute the following command to set the log level:

exec edg_utl.set_log_level(edg_utl.tcdebug);

 

6.

The Streams Apply process that calls these procedures runs in a separate database session, setting the log level in your SQL*Plus session will not be reflected in the session in which the Streams Apply process is running. You must stop and start the Streams Apply process called EDG_APPLY to get the value of the log level using the following commands:

exec DBMS_APPLY_ADM.STOP_APPLY('EDG_APPLY');

exec DBMS_APPLY_ADM.START_APPLY('EDG_APPLY');

 

7.

Only events with ID = 200 will cause the callback to get called. Look at your Sensor Data Archive. Execute the following query:

SELECT count(*) FROM edg_log;

 

8.

You can now test the rule that you have created. To test the rule, send a false event by invoking the procedure as follows:

http://<hostname>.<domain>:<port>/edge/tools/sendEvent.html

Enter the following values:
Type: 200
SubType: 1
Id: 125
Direction: true

Click Submit Query.

The procedure generates a dummy event with ID set to 125 and sends it out. The Direction parameter has to be set to true since SendEvents simulates events that comes from the device to SDS.

 

9.

You receive confirmation that the send event was successful.

 

10.

Open a browser window and enter the URL for Sensor Edge Server:

http://<hostname>.<domain>:<port>/edge

Enter the OC4J administrator username and OC4J administrator password. Click Login.

 

11.

Click Monitor Events. You should be able to view the following:

Type Description: Custom (type=200 subtype=1)

ID: 200

 

12.

Open a command window and change directory to < edgeserver_home>\edge\sql\10.1.3 where edgeserver_home is the folder in which edge server is installed. Log in to SQL*Plus as the edge user by issuing the following command:

sqlplus edge/< password for edge user>

 

13.

If you run events in to the SDS, and you have registered the PL/SQL callback, you will see the event being logged in to edg_log table. All logging is done at the edg_utl.tcDebug log level. Execute the following command to set the log level:

exec edg_utl.set_log_level(edg_utl.tcdebug);

 

14.

The Streams Apply process that calls these procedures runs in a separate database session, setting the log level in your SQL*Plus session will not be reflected in the session in which the Streams Apply process is running. You must stop and start the Streams Apply process called EDG_APPLY to get the value of the log level using the following commands:

exec DBMS_APPLY_ADM.STOP_APPLY('EDG_APPLY');

exec DBMS_APPLY_ADM.START_APPLY('EDG_APPLY');

 

15.

Only events with ID = 200 will cause the callback to get called. Look at the Sensor Data Archive. Execute the following query

SELECT count(*) FROM edg_log;

 

Back to Topic List

 

Summary

In this lesson, you have learned how to:

 Configure Streams Dispatcher for sensor events

Back to Topic List

Related Information

To learn more about Sensor Edge Server Enterprise Edition, refer to additional OBEs on the OTN Web site

 To ask a question about this OBE tutorial, post a query on the OBE Discussion Forum

Back to Topic List

 Place the cursor over this icon to hide all screenshots.

 

 

 

Left Curve
Popular Downloads
Right Curve
Untitled Document