5.2.2.2 Opening a Resource Manager

The following example illustrates another common use of tpsvrinit(): opening a resource manager. The Oracle Tuxedo system provides functions to open a resource manager, tpopen(3c) and tx_open(3c). It also provides the complementary functions, tpclose(3c) and tx_close(3c). Applications that use these functions to open and close their resource managers are portable in this respect. They work by accessing the resource manager instance-specific information that is available in the configuration file.

Note:

If writing a multithreaded server, you must use the tpsvrthrinit() function to open a resource manager, as described in Programming a Multithreaded and Multicontexted ATMI Application.

These function calls are optional and can be used in place of the resource manager specific calls that are sometimes part of the Data Manipulation Language (DML) if the resource manager is a database. Note the use of the userlog(3c) function to write to the central event log.

Note:

To create an initialization function that both receives command-line options and opens a database, combine the following example shown in the following listing with the previous example.

Listing Opening a Resource Manager in tpsvrinit( )

tpsvrinit()
{

   /* Open database */

   if (tpopen() == -1) {
         (void)userlog("tpsvrinit: failed to open database: ")
        switch (tperrno) {
          case TPESYSTEM:
              (void)userlog("System error\n");
               break;
          case TPEOS:
              (void)userlog("Unix error %d\n",Uunixerr);
               break;
          case TPEPROTO:
              (void)userlog("Called in improper context\n");
               break;
         case TPERMERR:
             (void)userlog("RM failure\n");
              break;
         }
         return(-1); /* causes the server to exit */
     }
    return(0);
  }

To guard against errors that may occur during initialization, tpsvrinit() can be coded to allow the server to exit gracefully before starting to process service requests.

See Also:

For more information about tpopen(3c) and tx_open(3c)It also provides the complementary functions, tpclose(3c) and tx_close(3c) refer to Section 3c - C Functions