C++ Internal Poller Example


What is the C++ Internal Poller Example ?

OPUS is distributed with a sample pipeline which demonstrates some of the capabilities of the OPUS system. That pipeline includes both internal and external pollers as pipeline applications. Of course, externally polling applications can be written in any language or script. Users may also take advantage of the OPUS API (OAPI) to create their own internally polling pipeline applications. These can be written to the OAPI and built with the libraries provided with OPUS.

This C++ example is included to illustrate such an application. It is written in standard C++ and can be built to run on any platform which OPUS supports. There is some preliminary work required (to build the application), but hopefully that will be made less complicated by the following information. By linking with the supplied OPUS and ACE/TAO libraries, there is no need to install a separate CORBA package, as is the case with the Python example. After succesfully building and running this, it may be modified and used as a model for the user's own internal pollers.

As a side note, if a C++ internal poller is required for a platform on which OPUS is not yet supported (to communicate with servers running on a supported platform), an example is included on the CD at  "opus/src/rem_c++poller.cpp". This requires a separate CORBA ORB and IDL compiler. Note that Java is usually a simpler choice for such a case, due to its run-anywhere nature and its built-in support for CORBA.


What do I have to do to set this up ?

The application for this OPUS process needs to be compiled then installed. Since the necessary OPUS and CORBA libraries are provided with OPUS, this should be relatively easy. Tested versions of this example were built with the GCC 3.2 compiler, though it should be possible to use other standard C++ compilers. Perform the following steps, where it is assumed that OPUS is installed in /usr/local/opus, though you can use any location:

  1. Create a directory in which to build, e.g.:

    mkdir ~/mybuild

  2. cd ~/mybuild

  3. Copy the single C++ source code file to your build directory. This has been included and is located in "opus/src/CxxPoller.cpp":

    cp /usr/local/opus/src/CxxPoller.cpp ~/mybuild

  4. Copy the supplied make file (" opus/install/c++poller.make") to your build directory:

    cp /usr/local/opus/install/c++poller.make ~/mybuild

  5. Edit the make file (c++poller.make) to change the line starting with OPUS_DIST. Make sure this is set to the path of your local OPUS installation.

  6. Use gmake to compile the application:

    gmake -f c++poller.make

  7. When it builds successfully, install the resulting executable into some place in your path so it will be found when OPUS tries to run it:

    cp c++poller /usr/local/opus/bin/[platform]/.

    You have now compiled and installed the C++ application. Next, make sure the appropriate process-related files are in place.

  8. Install the process resource file. This has been included and is located in "opus/definitions/unix/c++poller.resource". Simply copy this into your OPUS_DEFINITIONS_DIR. If you are already setup to run the sample pipeline, then you may skip this step.

  9. Install the path file. You may create your own, or you may use the included "quick.path" path file that has been installed for use with the sample pipeline. If you wish to create your own, follow the format of "quick.path", set the directory locations to your needs, then simply copy it into your OPUS_DEFINITIONS_DIR. If you are already setup to run the sample pipeline, and you wish to use "quick.path", then you may skip this step.


Now that I have configured everything, how do I run it ?

Via the PMG and the OMG.

Once the C++ executable has been built and is in your path, and the resource and path files are located in your OPUS_DEFINITIONS_DIR directory, simply start the OPUS servers and then run the PMG (as explained in detail in the OPUS PMG documentation). Find "c++poller" under the "Processes" tree in the PMG, listed under OPUS / Processes / SAMPLE / ALL. Drag it to the "quick" path tab on the right side of the PMG and select a node to run it on in the popup window. When it is listed as "pending", use the PMG menu to start the pending process.

If all goes well, it will eventually sit, listed as "idle", waiting to be triggered. At this point, you will be able to view the process log file ("View" menu) and verify that the c++poller process has started.

The C++ internal poller example uses an OSF trigger. Therefore, you must create an OSF and then set the appropriate column to the appropriate value (as defined in the resource file) before OPUS will trigger the process. Follow these steps:
  1. At the command line, create an OSF with the name "my_osf" by typing:

    osf_create -p quick.path -f my_osf -s _

    This will create an OSF named "my_osf" and will set the status of all its columns to "_".

  2. This particular example is coded to look for files in the path's input directory named similar to the OSF, so create an empty file for it to find and "work on":

    touch ~/opus_test/quick/input/my_osf_file.txt

  3. In the OMG, open the "quick" path.

  4. Your newly created OSF will show up. Set the "KW" column to "w" to trigger the process. Click "OK" in the popup dialog. There is no special significance to the "KW" stage/column for this example, we simply chose an existing stage in an existing path. This C++ example does nothing with keywords.

The c++poller task has now been triggered to process a dataset. Within 10 seconds (i.e., the default POLLING_TIME), the c++poller process will wake up. You will be able to see the status change in the PMG as well as in the OMG. In the OMG, the "KW" column of the OSF will change to "p" while processing, then to "c" when complete, or to "e" if an error is encountered. You will be able to view the results in the log file. You have successfully processed a dataset though a C++ internal poller using OPUS.


Now that I can run the example, how do I make my own ?

The most difficult part of this process was getting the example to run. If that was successful, then you can either write your own from scratch, or simply copy the example as a template. You may only want or need to edit the contents of the "process_dataset()" method in CxxPoller.cpp, inserting the code that does your own specific processing. Or you may want to make further changes which take more full advantage of the OAPI than is done by this example.

 

Back to the Top

Top of OPUS FAQ