BEA Logo BEA WebLogic Enterprise Release 5.0

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

 

   WLE Doc Home   |   Notification Services & Related Topics   |   Previous   |   Next   |   Contents   |   Index

Building the Advanced Sample Application

This chapter contains the following topics:

Overview

The Advance sample application simulates a newsroom environment in which a news reporter posts a story, a wire service posts the story as an event to the Notification Service, and a news subscriber consumes the story.

Two implementations of the Advanced sample application are provided: one in the Java programming language that uses the BEA Simple Events application programming interface (API), and another in C++ that uses the CosNotification Service API.

The Advanced sample application consists of the reporter, subscriber, and wire service applications that use the WLE Notification Service. The reporter application implements a client application. This application prompts the user to enter news articles and calls the WireService server using application specific IDL. The WireService server, in turn, posts the events. The subscriber implements a joint client/server application. This application acts as client when it subscribes and unsubscribes for events, and acts as a server when it receives events. To receive events, the Subscriber implements callback objects which are invoked by the Notification Service when an event needs to be delivered.

Note: On UNIX systems, you cannot immediately restart the subscriber because the port takes some time (the actual time depends on the platform) to become available again. If you restart too soon, you will get a CORBA::OBJ_ADAPTER exception. If this occurs, just wait and try again. On Solaris systems, the port can take up to 10 minutes to become available. To see if the port is still in use this command: "Restart -a | grep < the port number>"

This sample demonstrates how to use the BEA Simple Events API, the CosNotification Service API, transient and persistent subscriptions, and data filtering.

This Advanced sample provides three executables (See Figure 6-1):

The event poster, the WireService application, uses the structured event domain_name, type_name, and filterable_data fields to construct three events: 1) a news event, 2) a subscriber shutdown event, and a subscriber cancel event.

The Subscriber application, uses the structured event domain_name, type_name, and filterable_data fields to construct two subscriptions: 1) a news subscription that processes news stories and 2) a shutdown subscription that processes Cancel and Shutdown events. At run time, the Subscriber application establishes these two subscriptions with the Notification Service.

The Reporter application is responsible for implementing the user interface for reporting news as well as for producing Shutdown and Cancel events. Rather than use the Notification Service directly to post events, it calls methods on the Wire Service server.

The Wire Service uses the Notification Service to post three kinds of events:

The Notification Service, in turn, delivers the events to the subscribers.

The subscriber uses the Notification Service to create a persistent subscription to news events. The subscriber implements a persistent callback object (via the NewsConsumer_i servant class), which is used to receive and process news events. When the subscriber subscribes, it gives the Notification Service a reference to this callback object. When a matching event occurs, the Notification Service invokes a push_structured_event method on this callback object to push the event to the subscriber. This method prints out the event.

The subscriber also uses the Notification Service to create a transient subscription to Shutdown and Cancel events. The subscriber implements another callback object (via the ShutdownConsumer_i servant class), which is used to receive and process these events.

Whenever the subscriber runs, it prompts the user for a name. The first time this user runs the subscriber program, the subscriber creates a persistent subscription to News events. To do this, the subscriber prompts the user for which kind of news stories to subscribe to and which port number the subscriber should run on. The subscriber runs on this port, subscribes, then writes the subscription id, the filter id (if using the CosNotification API), and the port number to a file (the name of the file is < user_name >.pstore ). The next time the subscriber runs, the subscriber prompts the user for a name, opens up the file < user_name >.pstore then reads the subscription id, filter id (if using the CosNotification API) and port number for this user from the file. This satisfies the requirement that the subscriber runs on the same port number each time because its news callback object's object reference is persistent.

The Subscriber creates a transient subscription to receive the Shutdown and Cancel events, therefore, the transient subscription is created and destroyed every time the subscriber is run and shutdown. This subscription id is not written out to the file < user_name >.pstore .

When the subscriber receives a Shutdown event, it destroys the shutdown/callback subscription but leaves the News subscription intact. If News events are posted after the subscriber is shut down and before it is restarted, then the notification service will either deliver the events when the subscriber is restarted, or will put the events on the error queue. (You can use the ntsadmin utility to either delete these events from the error queue or retry delivering them).

Whether the event is redelivered or is put on the error queue depends on whether the subscriber restarts quickly enough. This depends on the retry parameters of the queue. See advanced.inc (in the notification samples' common directory) for the values of the queue retry parameters.

News events have two parts: a category (for example, headline) and a story (a multiple-line text string). The Subscriber application prompts the user to input a news category. Next the subscriber subscribes to news events whose category matches this string. The Reporter application prompts the user for a news category and a story. Next the reporter (by invoking a method on the wire service) posts a corresponding news event. The event will only be delivered to subscribers who subscribed to that category of news.

Note: The category is a string. The same string must be used by the Reporter user and the Subscriber user. There are no fixed categories in this sample. Therefore both users, the reporter user and the subscriber user, must type the same string when prompted for a category (including case and white space).

This sample also uses data filtering. When a user first runs the Subscriber, the user will be prompted for a "keyword." Events whose category matches and whose story contains the keyword will be delivered to the subscriber. For example, if the user enters a keyword of "none," data filtering will not be used (thus the user will receive all events for the chosen news category). If the user enters a keyword "smith", it translates to "Story %% '.*smith.*'" . This keyword specifies that the subscription only accepts events that have a "Story" field that contains a string, and that the field starts with any number of characters, has a literal string "smith", and then ends with any number of characters.

To run this sample, you need to run at least one Reporter and at least one Subscriber; however, you may run multiple Reporters and multiple Subscribers. Events posted by any Reporter will be delivered to all matching Subscribers (based on category).

Also, be sure to start any subscribers before posting events. Events posted before the subscribers are started will not be delivered.

Building and Running the Advanced Sample Application

To build and run the Introductory sample application, you must perform these steps:

  1. Verify that the "TUXDIR" and "JAVA_HOME" environment variables are set to the correct directory path.

    Note: The "JAVA_HOME" environment variable is required for Java applications only.

  2. Copy the files for the Introductory sample application into a work directory.

  3. Change the protection attributes on the files to grant write and execute access.

  4. For UNIX, ensure the make file is in your path. For Microsoft Windows NT, ensure the nmake file is in your path

  5. Set the application environment variables.

  6. Build the sample.

  7. Boot the system.

  8. Run the Subscriber and Reporter Applications.

  9. Shut down the system.

  10. Restore the directory to its original state.

These steps are described in detail in the following sections.

Verifying the Settings of the Environment Variables

Before you build and run the Introductory sample application, you need to ensure that the TUXDIR environment variable is set on your system. In most cases, this environment variable is set as part of the installation procedure. However, you need to check the environment variables to ensure they reflect correct information.

Table 6-1 lists the environment variables required to run the Callback sample application.

Table 6-1 Required Environment Variables for the Callback Sample Application

Environment Variable

Description

TUXDIR

The directory path where you installed the WLE software. For example:

Windows NT

TUXDIR=c:\wledir

UNIX

TUXDIR=/usr/local/wledir

JAVA_HOME (For Java applications only)

The directory path where you installed the JDK software. For example:

Windows NT

JAVA_HOME=c:\JDK1.2

UNIX

JAVA_HOME=/usr/local/JDK1.2

To verify that the information for the environment variables defined during installation is correct, perform the following steps:

Microsoft Windows NT

  1. From the Start menu, select Settings.

  2. From the Settings menu, select the Control Panel.

    The Control Panel appears.

  3. Click the System icon.

    The System Properties window appears.

  4. Click the Environment tab.

    The Environment page appears.

  5. Check the setting for TUXDIR and JAVA_HOME .

UNIX

ksh prompt>printenv TUXDIR

ksh prompt>printenv JAVA_HOME

To change the settings, perform the following steps:

Microsoft Windows NT

  1. On the Environment page in the System Properties window, click the environment variable you want to change.

  2. Enter the correct information for the environment variable in the Value field.

  3. Click OK to save the changes.

UNIX

ksh prompt>export TUXDIR= directorypath

ksh prompt>export JAVA_HOME= directorypath

Copying the Files for the Advanced Sample Application into a Work Directory

You need to copy the files for the Advanced sample application into a work directory on your local machine.

Note: The application directory and the common directory must be copied to the same parent directory.

The files for the Advanced sample application are located in the following directories:

Microsoft Windows NT

For the C++ Advanced sample: drive:\wledir \samples\corba\notification\advanced_cos_cxx
drive:\wledir \samples\corba\notification\common

For the Java Advanced sample: drive:\wledir \samples\corba\notification\advanced_simple_java
drive:\wledir \samples\corba\notification\common

UNIX

For the C++ Advanced sample: /usr/local/wledir /samples/corba/notification/advanced_cos_cxx
/usr/local/wledir /samples/corba/notification/common

For the Java Advanced sample: /usr/local/wledir /samples/corba/notification/advanced_simple_java
/usr/local/wledir /samples/corba/notification/common

You use the files listed in Table 6-2 and Table 6-4 to build and run the Java Advanced sample application, which is implemented using the BEA Simple Events API. You use the files listed in Table 6-3 and Table 6-4 to build and run the C++ Advanced sample application, which is implemented using the CosNotification API.

Table 6-2 Files Located in the advanced_simple_java Notification Directory

File

Description

Readme.txt

Describes the Advanced sample application and provides instructions for setting up the environment and building and running the application.

setenv.cmd

Sets the environment for Microsoft Windows NT systems.

setenv.ksh

Sets the environment for UNIX systems.

makefile.nt

Makefile for Microsoft Windows NT systems.

makefile.mk

Makefile for UNIX systems.

makefile.inc

Common makefile used by the makefile.nt and the makefile.mk files.

Reporter.java

Code for the reporter.

Subscriber.java

Code for the subscriber.

NewsConsumer_i.java

Callback servant class that subscribers use to receive news events. (For the Subscriber application.)

ShutdownConsumer_i.java

Callback servant classes that subscribers use to receive Shutdown and Cancel events. (For the Subscriber application.)

WireService.xml

Server Description file for the WireService server.

WireService_i.java

Implements the WireService interfaces.

WireServiceFactory_i.java

Implements the WireService factory interface.

WireServiceServer.java

Code for the WireService server.

You use the files listed in Table 6-3 and Table 6-4 to build and run the Advanced sample application.

Table 6-3 Files Located in the advanced_cos_c++ Notification Directory

File

Description

Readme.txt

Describes the Advanced sample application and provides instructions for setting up the environment and building and running the application.

setenv.cmd

Sets the environment for Microsoft Windows NT systems.

setenv.ksh

Sets the environment for UNIX systems.

makefile.nt

Makefile for Microsoft Windows NT systems.

makefile.mk

Makefile for UNIX systems.

makefile.inc

Common makefile used by the makefile.nt and the makefile.mk files.

Reporter.cpp

Code for the reporter.

Subscriber.cpp

Code for the subscriber.

NewsConsumer_i.h and NewsConsumer.cpp

Callback servant class that subscribers use to receive news events. (For the Subscriber application.)

ShutdownConsumer_i.h and ShutdownConsumer.cpp

Callback servant classes that subscribers use to receive Shutdown and Cancel events. (For the Subscriber application.)

WireServiceServer.cpp

Code for the WireService server.

News.icf

ICF file for the WireService interfaces.

WireService_i.h and WireService.cpp

Implements the WireService interfaces.

Table 6-4 lists other files that the Advanced sample uses. With the exception of the IDL files, the files are located in the Notification common directory.

Table 6-4 Other Files that the Advanced Sample Uses

File

Description

The following files are located in the common directory.

News.idl

IDL definitions for the WireService server.

news_flds

FML field definitions used to perform data filtering and news events.

common.nt

Makefile symbols for Microsoft Windows NT systems.

common.mk

Makefile symbols for UNIX systems.

advanced.inc

Makefile for administrative targets.

ex.h

Utilities to print exceptions. (C++ only.)

client_ex.h

Client utilities to handle exceptions. (C++ only.

server_ex.h

Server utilities to handle exceptions.

The following files are located in the \tuxdir\include directory.

CosEventComm.idl

The OMG IDL code that declares the CosEventComm module.

CosNotification.idl

The OMG IDL code that declares the CosNotification module.

CosNotifyComm.idl

The OMG IDL code that declares the CosNotifyComm module.

Tobj_Events.idl

The OMG IDL code that declares the Tobj_Events module.

Tobj_SimpleEvents.idl

The OMG IDL code that declares the Tobj_SimpleEvents module.

Note: This file is needed only for the application that was developed using BEA Simple Events API.

The following files are needed only for the application that was developed using CosNotification Service API.

CosEventChannelAdmin.idl

The OMG IDL code that declares the CosEventChannelAdmin module.

CosNotifyFilter.idl

The OMG IDL code that declares the CosNotifyFilter module.

CosNotifyChannelAdmin.idl

The OMG IDL code that declares the CosNotifyChannelAdmin module.

Tobj_Notification.idl

The OMG IDL code that declares the Tobj_Notification module.

Changing the Protection Attribute on the Files for the Advanced Sample Application

During the installation of the WLE software, the sample application files are marked read-only. Before you can edit or build the files in the Advanced sample application, you need to change the protection attribute of the files you copied into your work directory, as follows:

Microsoft Windows NT

  1. Change (cd) to your work directory

  2. prompt>attrib -r drive: \workdirectory \*.*

UNIX

  1. Change (cd) to your work directory

  2. prompt>/bin/ksh

  3. ksh prompt>chmod u+w / workdirectory /*.*

On the UNIX operating system platform, you also need to change the permission of setenv.ksh to give execute permission to the file, as follows:

ksh prompt>chmod +x setenv.ksh

Setting Up the Environment

To set up the environment, enter the following command:

Microsoft Windows NT

prompt>.\setenv.com

UNIX

prompt>. ./setenv.ksh

Building the Advanced Sample Application

You use the make command to run makefiles , which are provided for Microsoft Windows NT and UNIX, to build the sample application. For Microsoft Windows NT, use nmake . For UNIX, use make .

Makefile Summary

The makefile automates the following steps:

  1. Checks that the set environment command (setenv.cmd ) has been run. If the environment variables have not been set, the makefile prints an error message to the screen and exits.

  2. Includes the common.nt (for Microsoft Windows NT) or common.mk (for UNIX) command file. This file defines the makefile symbols used by the samples. These symbols allow the UNIX and Microsoft Windows NT makefiles to delegate the build rules to platform-independent makefiles.

  3. Includes the makefile.inc command file. This file builds the is_reporter , is_subscriber and AS_WIRESERVICE executables, and cleans up the directory of unneeded files and directories.

  4. Includes the advanced.inc command file. This file executes tmadmin and qadmin commands to create the transaction log and the queues required by the persistent subscriptions. It also creates the UBBCONFIG file and executes the tmloadcf -y ubb command to create the TUXCONFIG file.

Executing the Makefile

Before executing the makefile , you need to check the following:

To build the Advanced sample application, enter the make command as follows:

Microsoft Windows NT

nmake -f makefile.nt

UNIX

make -f makefile.mk

Starting the Advanced Sample Application

To start the Advanced application, enter the following commands:

  1. To boot the WLE system:

prompt>tmboot -y

This command starts the following server processes:

  1. To start the Subscriber application:

    For C++: prompt>is_subscriber
    For Java on Microsoft Windows NT: prompt>java %IC_SUBSCRIBER%
    For Java on UNIX: prompt>java $IC_SUBSCRIBER

    To start another Subscriber, open another window, change (cd ) to your work directory, set the environment variables (by running setenv.cmd or setenv.ksh ), and enter the start command that is appropriate for your platform.

  2. To start the Reporter application, open another window and enter the following:

    For C++: prompt>is_reporter
    For Java on Microsoft Windows NT: prompt>java %IC_REPORTER%
    For Java on UNIX: prompt>java $IC_REPORTER

    To start another Reporter, open another window, change (cd ) to your work directory, set the environment variables (by running setenv.cmd or setenv.ksh ), and enter the start command that is appropriate for your platform.

Using the Advanced Sample Application

To use the Advanced sample application, you must use the Subscriber application to subscribe to an event and the Reporter application to post an event. Be sure to subscribe before you post each event; otherwise, events will be lost.

Using the Subscriber Application to Subscribe to Events

Perform these steps:

  1. When you start the Subscriber application (prompt>is_subscriber) for the first time, the following prompts are displayed:

    Name? (Enter a name (without spaces).)
    Port (e.g. 2463) (Enter the port number that this subscriber should run on.)
    Category (or all) (Enter the category of news you want or "all".)
    Keyword (or none) (Enter a keyword that you want all delivered stories to
    contain.)

    Note: If the Subscriber application is shutdown by a Shutdown event from the Reporter application (Shutdown events do not cancel persistent subscriptions), on subsequent startups of the Subscriber application, you will only be prompted for your name. The Subscriber application retrieves the remaining information from the <user_name>.pstore file. This guarantees that the same port number is used, which is required for persistent subscriptions.

    If the Subscriber application is shutdown by a Cancel event from the Reporter application (Cancel events cancel all subscriptions including persistent subscriptions), on subsequent startups of the Subscriber application, you will be prompted for your name, port number, category, and keyword.

  2. You may type in any string for the news category, that is, there is no fixed list of news categories. However, when you use the Reporter application to post an event, make sure you specify the same string for the news category.

    Similarly, you may type in a string for a keyword. There is no fixed list of keywords either so when you run the reporter and enter the story, make sure that the story contains the same string; otherwise, the story will not be delivered to your subscription.

    The first time the subscribe application is run for your user name, category (or all), and keyword (optional), it creates a news subscription. On subsequent runs, the subscriber reuses this subscription. In all cases, the Subscribe application prints "Ready" when it is ready to receive events.

    The Subscriber application creates a subscription then prints "Ready" when it is ready to receive events.

    Note: You should always use the Subscriber application to subscribe to events before you use the Reporter application to post events; otherwise, events will be lost. This is because even though the Subscriber application creates a persistent subscription to News events, that subscription is not created until the Subscriber application is start.

    Note: You can start multiple subscribers by starting another window and repeating this procedure.

Using the Reporter Application to Post Events

Perform these steps:

  1. When you start the Reporter application (prompt> is_reporter ), the following prompt is displayed:

    (r) Report news
    (s) Shutdown subscribers
    (c) Cancel Subscribers
    (e) Exit

    Option?

  2. Enter r to report news. The following prompt is displayed:

    Category?

  3. Enter the news category. It must match exactly the category you typed on the Subscriber application (including white space and case).

    After you enter the news category, the following prompt is displayed:

    Enter story (terminate with '.')

  4. Enter your story. It can span multiple lines. Finish the story by typing a period only (".") on a line, followed by a carriage return. If you typed in a keyword when subscribing, make sure the story contains this string (including white space and case).

    Subscribers whose category and keyword (if specified) matches the category and a keyword in this story will receive and print out the story.

  5. If you choose the "s" option, a Shutdown event will be posted and received by all the subscribers and the subscribers will shut down. While the subscribers are shut down, you may post another news story (by using the "r" option again). The Notification Service will place the news story on the pending queue but the News event subscription is persistent and, therefore, is still in effect. After you restart the subscribers, they will receive this second news story (unless a restart delay caused the event to be moved to the error queue). This is because the subscriber created a persistent subscription for news stories.

    Note: You can use the ntsadmin retryerrevents command to move events from the error queue back to the pending queue.

  6. If you choose the "c" option, a Cancel event will be posted and received by all the subscribers. The subscribers will cancel their news subscriptions and shutdown. If you try to restart the subscribers, then you will be prompted again for port, category and keyword because you are creating a new subscription.

  7. When you are finished reporting news, choose the Exit (e) option.

    Note: You can start multiple reporters by opening another window and repeating this procedure. Any news story reported by any reporter will be delivered to all matching subscribers. Make sure you have exited all reporters before shutting down the system.

Shutting Down the System and Cleaning Up the Directory

Make sure the Reporter and Subscriber processes have stopped and perform these steps:

  1. To shutdown the system, in any window, type:

prompt>tmshutdown -y

  1. To restore the directory to its original state, in any window, type:

Microsoft Windows NT

prompt>nmake -f makefile.nt clean

UNIX

prompt>make -f makefile.mk clean