OTL 4.0, OTL subscriber interface

This class is Oracle 10gR2 (or higher) specific, and optional. It can be enabled by defining #define OTL_ORA_SUBSCRIBE. otl_subscriber uses the Oracle Database Change Notification Interface, which allows the user to get Change Notifications on database tables of interest. The class implements basic functions like subscribe / unsubscribe, plus pure virtual functions that need to be overriden in a derived class. The pure virtual functions are actually a callback mechanism for delivering change notifications back to the user. See also example 585 for more detail.

Potentially, the otl_subscriber class may throw the following OTL defined exception.

class otl_subscriber {
public:
     otl_subscriber(otl_connect* adb);
     virtual ~otl_subscriber();
     void subscribe(const char *name=0, // optional subscription name
                    int port=0, // Application listening TCP port number to receive
                                // subscription notifications (optional). When it's left
                                // as defualt, the OCI layer gets the next available port.
                    int timeout=1800 // Subscription expiration time, seconds (optional,
                                     // default value is 1800 sec, 0 means "never expires").
                                     // When subscription expires, OnDeRegistration() is called.
                   );

     void unsubscribe();
     void associate_table(const char *table_name);
              void associate_query(const char *query_stmt);
protected:
// Pure virtual functions // callbacks to be implemented in a derived class

  virtual void OnException(otl_exception& e) = 0;
      // "On otl_exception" callback. When OTL throws otl_exception,
      // this function is called.

  virtual void OnDeRegistration(void) = 0;
      // "On deregistration" callback. This function gets called
      // when the current subscription expires. Inside this function,
      // repeated calls to subscribe(), associate_table(), associate_query()
      // are allowed.

  // --- DB-wide  events:
  virtual void OnStartup(void) = 0;
      // "On Oracle Instance startup" callback. This function gets called
      // on the Oracle Instance startup


  virtual void OnInstanceShutdown(void) = 0;
      // "On Oracle Instance shutdown" callback. This function gets called
      // when the Oracle Instance which the client
      // program is connected to shuts down.

  virtual void OnAnyInstanceShutdown(void) = 0;
      // "On Any Oracle Instance shutdown" callback. This function gets called
      // when Any Oracle Instance in the RAC which the client
      // program is connected to shuts down.

  // --- Table-wide events:
  virtual void OnTableInvalidate(text *table_name) = 0;
       // "On table invalidate" callback. This function gets called
       // when the table gets invalidated.

  virtual void OnTableAlter(text *table_name) = 0;
       // "On table alter" callback. This function gets called
       // when the table gets ALTERed.

  virtual void OnTableDrop(text *table_name) = 0;
       // "On table drop" callback. This function gets called
       // when the table gets DROPped.

  virtual void OnTableChange(text *table_name) = 0;
       // "On table change" callback. This function gets called
       // when the table gets changed: INSERT, UPDATE, DELETE. This
       // callback only informs of the fact that the table got
       // changed, but it doesn't specify which row(s) got changed.
       // In order to get the info on individual rows, see "Row events".

  // --- Row events:
  virtual void OnRowInsert(text *table_name, text *row_id ) = 0;
       // "On row insert" callback. This function gets called when a row
       // is inserted into the table. If a query was
       // associated with the current subscription that involves more than one
       // table, this callback will be invoked for each table of the query.
       // "row_id" is the ROWID of the inserted row.

  virtual void OnRowUpdate(text *table_name, text *row_id ) = 0;
       // "On row update" callback. This function gets called when a table row
       // is updated. If a query was
       // associated with the current subscription that involves more than one
       // table, this callback will be invoked for each table of the query.
       // "row_id" is the ROWID of the updated row.

  virtual void OnRowDelete(text *table_name, text *row_id ) = 0;
       // "On row delete" callback. This function gets called when a table row
       // is updated. If a query was
       // associated with the current subscription that involves more than one
       // table, this callback will be invoked for each table of the query.
       // "row_id" is the ROWID of the updated row.

public:
     bool is_online(void);
}; // end of otl_subscriber
Oracle user id that is used to connect to the database and get  Change Notifications needs to have the CHANGE NOTIFICATION privilege given by the DBA, for example:

        grant change notification to scott;

Active subscriptions can be viewed via the USER_CHANGE_NOTIFICATION_REGS system view by the current Oracle user:
    select * from USER_CHANGE_NOTIFICATION_REGS
When a subscription gets registered, the OCI layer opens a specified TCP/IP port, and spawns a new listener thread. Firewalls need to take the TCP/IP port into account.


Prev NextContentsGo Home

Copyright © 1996, 2008, Sergei Kuchin, email: skuchin@aceweb.com, skuchin@gmail.com .

Permission to use, copy, modify and redistribute this document for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies.