•
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, use this command: “Restart -a | grep <the port number>”.Figure 6‑1 Advanced Sample Application ComponentsThe event poster, the WireService application, uses the structured event domain_name, type_name, and filterable_data fields to construct three events: a news event, 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: a news subscription that processes news stories; and a shutdown subscription that processes Cancel and Shutdown events. At run time, the Subscriber application establishes these two subscriptions with the Notification Service.The Subscriber application uses the structured event domain_name, type_name, and filterable_data fields to create a subscription to the Notification Service. The subscription defines the domain name as a fixed string with the content of “News”. At run time, the Subscriber application queries the user for the “News Category” and “Keyword” and uses the inputs to define the type_name and data_filter fields in the subscription. Obviously, the users of both applications, the reporter and the subscriber, must collaborate on the “News Category” and “keyword” strings for the subscription to match an event, otherwise, no News events will be delivered to the subscriber. The subscription does not do any checking of the filterable_data field, but rather assumes that the body of the story will be a string, and that the story will be in the first Named/Value pair in the filterable_data field of a structured event.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.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.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.
1. Verify that the "TUXDIR" environment variable is set to the correct directory path.
2. Unset and “JAVA_HOME”
5. For UNIX, ensure the make file is in your path. For Microsoft Windows, ensure the nmake file is in your pathBefore you build and run the Advanced 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 the correct information.Table 6‑1 lists the environment variables required to run the Callback sample application.
5. Check the setting for TUXDIRksh prompt>export TUXDIR=directorypath
Note: For the C++ Advanced sample: drive:\tuxdir\samples\corba\notification\advanced_cos_cxx
drive:\tuxdir\samples\corba\notification\commonFor the C++ Advanced sample: /usr/local/tuxdir/samples/corba/notification/advanced_cos_cxx
/usr/local/tuxdir/samples/corba/notification/commonYou use the files listed in Table 6‑2 and Table 6‑3 to build and run the C++ Advanced sample application, which is implemented using the CosNotification API.You use the files listed in Table 6‑2 and Table 6‑3 to build and run the Advanced sample application.
NewsConsumer_i.h and NewsConsumer.cpp ShutdownConsumer_i.h and ShutdownConsumer.cpp WireService_i.h and WireService.cpp Table 6‑3 lists other files that the Advanced sample application uses. With the exception of the IDL files, the files are located in the Notification common directory.
The following files are needed only for the application that was developed using CosNotification Service API.
1. Change (cd) to your work directory
2.
1. Change (cd) to your work directory
3. 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:You use the make command to run makefiles, which are provided for Microsoft Windows and UNIX, to build the sample application. For Microsoft Windows, use nmake. For UNIX, use make.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) 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 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 unnecessary 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.Before executing the makefile, you need to check the following:
• On Microsoft Windows, make sure nmake is in the path of your machine.
• On UNIX, make sure make is in the path of your machine.To build the Advanced sample application, enter the make command as follows:
•
• The message queue manager is an Oracle Tuxedo system-provided server that enqueues and dequeues messages on behalf of programs calling tpenqueue(3) and tpdequeue(3), respectively. This server is required for persistent subscriptions.The message forwarding server is an Oracle Tuxedo system-provided server that forwards messages that have been stored using tpenqueue(3c) for later processing. This server is required for persistent subscriptions.
• For C++: prompt>is_subscriberTo 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.For C++: prompt>is_reporterTo 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.
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 shut down 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.
1. When you start the Reporter application (prompt> is_reporter), the following prompt is displayed:
2. Enter r to report news. The following prompt is displayed:
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 shut down. 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.