1.3.2 Using AppContext Class

The AppContext class is a key class used to perform Tuxedo service access functions. AppContext leverages the OO programming style in a multi-contexted client application.

Note:

For more multi-context information, see Programming a Multithreaded and Multicontexted ATMI Application in Programming an Oracle Tuxedo ATMI Application Using C.

Most Tuxedo ATMI C functions (for example, tpcall(), and tpnotify()), are defined as AppContext class methods. Creating an AppContext class instance is a key component in connecting to a Tuxedo domain and call services provided by that Tuxedo domain.

In a multi-contexted application written in C or COBOL, programmers typically have to switch between different Tuxedo context using two ATMI functions, tpgetctxt() and tpsetctxt(). This is not required using the Tuxedo .NET Workstation Client. Creating a class AppContext instance also creates specific Tuxedo context instance.

Operations on a particular AppContext will not impact other AppContext instances. You can develop multi-context applications and easily switch between them.

To create a Tuxedo context instance you need to invoke the static class method, AppContext.tpinit(TPINIT), instead of the class constructor.

Note:

Tuxedo context instances are not destroyed automatically. You must invoke AppContext.tpterm() before a Tuxedo context instance is destroyed, otherwise you may encounter the following:
  • The garbage collector (gc) may destroy AppContext class instances without terminating the Tuxedo context session.
  • The client and WSH connection remains live until it times-out.

The following C# Code snippet illustrates the how to connect to a single context client Tuxedo domain.

……

TypedTPINIT tpinfo = new TypedTPINIT();

AppContext ctx1 = AppContext.tpinit(tpinfo); // connect to Tuxedo domain

……

ctx1.tpterm(); // disconnect from Tuxedo domain

The following C# Code snippet illustrates how to connect to a multi-context client Tuxedo domain .

……

TypedTPINIT tpinfo = new TypedTPINIT();

tpinfo.flags = TypedTPINIT.TPMULTICONTEXTS; // set multi context flag

// connect to the first Tuxedo domain

AppContext ctx1 = AppContext.tpinit(tpinfo);

Utils.tuxputenv("WSNADDR=//10.2.0.5:1001");

// connect to the second Tuxedo domain

AppContext ctx2 = AppContext.tpinit(tpinfo);

……

ctx1.tpterm(); // disconnect from the first Tuxedo domain

ctx2.tpterm(); // disconnect from the second Tuxedo domain