bea.com | products | dev2dev | support | askBEA |
![]() |
![]() |
|
![]() |
e-docs > WebLogic Server > WebLogic Tuxedo Connector Programmer's Guide > Developing WebLogic Tuxedo Connector Client EJBs |
WebLogic Tuxedo Connector Programmer's Guide
|
Developing WebLogic Tuxedo Connector Client EJBs
Note: For more information on the WebLogic Tuxedo Connector JATMI, view the Javadocs for WebLogic Classes.The WebLogic Tuxedo Connector classes are located in the weblogic.wtc.jatmi and weblogic.wtc.gwt packages.
The following sections describe how to create client EJBs that take user input and send service requests to a server process or outbound object that offers a requested service.
WebLogic Tuxedo Connector JATMI client classes are used to create clients that access services found in Tuxedo.
Joining and Leaving Applications
Tuxedo and WebLogic Tuxedo Connector have different approaches to connect to services.
The following section compares how Tuxedo and WebLogic Tuxedo Connector join an application:
Listing 2-1 Example Client Code to Join a Tuxedo Application
.
.
.
try {
ctx = new InitialContext();
tcf =
(TuxedoConnectionFactory) ctx.lookup("tuxedo.services.TuxedoConnection");
} catch (NamingException ne) {
// Could not get the tuxedo object, throw TPENOENT
throw new TPException(TPException.TPENOENT,
"Could not get TuxedoConnectionFactory : " + ne);
}
myTux = tcf.getTuxedoConnection();
.
.
.
The following section compares how Tuxedo and WebLogic Tuxedo Connector leave an application:
A client process uses Java and JATMI primitives to provide the following basic application tasks:
A client may send and receive any number of service requests before leaving the application.
Establish a connection to a remote domain by using the TuxedoConnectionFactory to lookup "tuxedo.services.TuxedoConnection" in the JNDI tree and get a TuxedoConnection object using getTuxedoConnection().
Use the following TypedBuffers when sending and receiving messages between your application and Tuxedo:
WebLogic Tuxedo Connector clients support three types of communications with Tuxedo service applications:
Request/Response Communication
Note: WebLogic Tuxedo Connector does not provide a JATMI primitive to support setting the priority of a message request. All messages originating from a WebLogic Tuxedo Connector client have a message priority of 50.
Use the following JATMI primitives to request and receive response messages between your WebLogic Tuxedo Connector client application and Tuxedo:
Using Synchronous Service Calls
Use tpcall to send a request to a service and synchronously await for the reply. The service specified must be advertised by your Tuxedo application. Logically, tpcall() has the same functionality as calling tpacall() and immediately calling tpgetreply().
Using Deferred Synchronous Service Calls
A deferred synchronous tpacall allows you to send a request to a Tuxedo service and not immediately wait for the reply. This allows you to send a request, perform other work, and then retrieve the reply.
A deferred tpacall() service call sends a request to a Tuxedo service and immediately returns from the call. The service specified must be advertised by your Tuxedo application. Upon successful completion of the call, tpacall() returns an object that serves as a descriptor. The calling thread is now available to perform other tasks. You can use the call descriptor to:
When you are ready to retrieve the reply, use tpgetreply() to dequeue the reply using the call descriptor returned by tpacall(). If the reply is not immediately available, the calling thread polls for the reply.
If tpacall() is in a transaction, you must receive the reply using tpgetreply() before the transaction can commit. You can not use tpcancel to cancel a call descriptor associated with a transaction. For example: If you make three tpacall() requests in a transaction, you must make three tpgetreply() calls and successfully dequeue a reply for each of the three requests for the transaction to commit.
The asynchronous tpacall allows you to send a request to a Tuxedo service and release the thread resource that performed the call to the thread pool. This allows a very large number of outstanding requests to be serviced with a much smaller number of threads.
An asynchronous tpacall() service call sends a request to a Tuxedo service. The service specified must be advertised by your Tuxedo application. Upon successful completion of the call, asynchronous tpacall() returns an object that serves as a descriptor. The calling thread is now available to perform other tasks. You can use the call descriptor to identify the correct message reply from TpacallAsynchReply for a sent message request or cancel an outstanding message reply using tpcancel().
Note: You can not use the call descriptor to invoke tpgetreply().
When the service reply is ready, the callback object is invoked on a different thread. If the original request succeeded, the TpacallAsynchReply.sucess method returns the reply from the service. If the original request failed, the TpacallAsynchReply.failure method returns a failure code.
You should implement the callback object using the following guidelines:
Note: For more information on Conversational Communication, see WebLogic Tuxedo Connector JATMI Conversations.
Use the following conversational primitives when creating conversational clients that communicate with Tuxedo services:
Enqueuing and Dequeuing Messages
Use the following JATMI primitives to enqueue and dequeue messages between your WebLogic Tuxedo Connector client application and Tuxedo /Q:
Close a Connection to a Tuxedo Object
Use tpterm() to close a connection to an object and prevent future operations on this object.
The following Java code provides an example of the ToupperBean.java client EJB which sends a string argument to a server and receives a reply string from the server.
Listing 2-2 Example Client Application
.
.
.
public String Toupper(String toConvert)
throws TPException, TPReplyException
{
Context ctx;
TuxedoConnectionFactory tcf;
TuxedoConnection myTux;
TypedString myData;
Reply myRtn;
int status;
log("toupper called, converting " + toConvert);
try {
ctx = new InitialContext();
tcf = (TuxedoConnectionFactory) ctx.lookup(
"tuxedo.services.TuxedoConnection");
}
catch (NamingException ne) {
// Could not get the tuxedo object, throw TPENOENT
throw new TPException(TPException.TPENOENT, "Could not get TuxedoConnectionFactory : " + ne);
}
myTux = tcf.getTuxedoConnection();
myData = new TypedString(toConvert);
log("About to call tpcall");
try {
myRtn = myTux.tpcall("TOUPPER", myData, 0);
}
catch (TPReplyException tre) {
log("tpcall threw TPReplyExcption " + tre);
throw tre;
}
catch (TPException te) {
log("tpcall threw TPException " + te);
throw te;
}
catch (Exception ee) {
log("tpcall threw exception: " + ee);
throw new TPException(TPException.TPESYSTEM, "Exception: " + ee);
}
log("tpcall successfull!");
myData = (TypedString) myRtn.getReplyBuffer();
myTux.tpterm(); // Closing the association with Tuxedo
return (myData.toString());
}
.
.
.
![]() |
![]() |
![]() |
![]() |
||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |