web analytics

How to Create a Tuxedo Server Application in C++

Options

codeling 1602 - 6666
@2019-11-22 15:12:55

A Tuxedo server is a process that provides one or more services to a client. To build server processes, applications combine their service subroutines with a controlling program provided by the Tuxedo system. You can follow the following steps to create a Tuxedo server appilcation.

  1. Create and compile an C++ application that performs a specific task or service.
  2. Create a configuration file for the service to establish the identifiers
  3. Edit/rename the "appinit.c" program (provided by BEA) to include runtime initialization and shutdown functions specific to your application. 

    The program calls the standard BEA Tuxedo ATMI initialization and shutdown subroutines tpsvrinit() and tpsvrdone(). The tpsvrinit routine calls two functions: tpopen opens the resource manager, and userlog posts a message that the server has started. The tpsvrdone routine also calls a tpclose function, which closes the resource manager

  4. Link your application executables and libraries into the controlling program provided by the BEA Tuxedo system using buildserver command.
@2019-11-22 15:29:01

To facilitate the development of servers, the BEA Tuxedo system provides a predefined main() routine for server load modules. When you execute the buildserver command, the main() routine is automatically included as part of the server.

Note: The main() routine that the system provides is a closed abstraction; you cannot modify it.

In addition to joining and exiting from an application, the predefined main() routine accomplishes the following tasks on behalf of the server.

  • Executes the process ignoring any hangups (that is, it ignores the SIGHUP signal).
  • Initiates the cleanup process on receipt of the standard operating system software termination signal (SIGTERM). The server is shut down and must be rebooted if needed again.
  • Attaches to shared memory for bulletin board services.
  • Creates a message queue for the process.
  • Advertises the initial services to be offered by the server. The initial services are either all the services link edited with the predefined main(), or a subset specified by the BEA Tuxedo system administrator in the configuration file.
  • Processes command-line arguments up to the double dash (--), which indicates the end of system-recognized arguments.
  • Calls the function tpsvrinit() to process any command-line arguments listed after the double dash (--) and optionally to open the resource manager. These command-line arguments are used for application-specific initialization.
  • Until ordered to halt, checks its request queue for service request messages.
  • When a service request message arrives on the request queue, main() performs the following tasks until ordered to halt:
    • If the -r option is specified, records the starting time of the service request.
    • Updates the bulletin board to indicate that the server is BUSY.
    • Allocates a buffer for the request message and dispatches the service; that is, calls the service subroutine.
  • When the service returns from processing its input, main() performs the following tasks until ordered to halt:
    • If the -r option is specified, records the ending time of the service request.
    • Updates statistics.
    • Updates the bulletin board to indicate that the server is IDLE; that is, that the server is ready for work.
    • Checks its queue for the next service request.
  • When the server is required to halt, calls tpsvrdone() to perform any required shutdown operations.

As indicated above, the main() routine handles all of the details associated with joining and exiting from an application, managing buffers and transactions, and handling communication.

Note: Because the system-supplied main() accomplishes the work of joining and leaving the application, you should not include calls to the tpinit() or tpterm() function in your code. If you do, the function encounters an error and returns TPEPROTO in tperrno.

@2019-11-22 15:32:11

The following example illustrates another common use of tpsvrinit(): opening a resource manager. The BEA Tuxedo system provides functions to open a resource manager, tpopen() and tx_open(). It also provides the complementary functions, tpclose() and tx_close(). 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 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 with the previous example.

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);
}

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com