WebTJCA Inbound Communication

This chapter describes WebTJCA inbound communication.

1. Inbound Communication

The following is the inbound communication process.

figure inbound webtjca
Inbound Communication Model

A Tmax resource adapter cannot determine by itself which service needs to be called to process requests from a WAS to Tmax. Therefore, a message driver bean must be added to receive messages from the resource adapter and call the Tmax service according to the user’s request. Some configurations are required in the following file to enable each message driven bean to receive messages from a resource adapter.

ra.xml

Specify 'com.tmax.connector.spi.TmaxActivationSpec' under <activationspec-class>, and 'serviceName' under <config-property-name> in the ra.xml file.

<inbound-resourceadapter>
<messageadapter>
  <messagelistener>
  <messagelistener-type>javax.resource.cci.MessageListener</messagelistener-type>
  <activationspec>
    <activationspec-class>com.tmax.connector.spi.TmaxActivationSpec
    </activationspec-class>
    <required-config-property>
    <config-property-name>serviceName</config-property-name>
    </required-config-property>
  </activationspec>
  </messagelistener>
</messageadapter>
</inbound-resourceadapter>
ejb-jar.xml for Message Driven Bean

For the user-defined message-driven bean, configure the <message-destination-link> and <activation-config> settings in ejb-jar.xml as shown in the example below. When deploying, the <activation-config-property> settings are passed to the defined resource adapter. When Tmax requests the service specified by serviceName, the resource adapter forwards the message to the registered message-driven bean.

<message-destination-link>TmaxRA</message-destination-link>
<activation-config>
  <activation-config-property>
   <activation-config-property-name>serviceName</activation-config-property-name>
   <activation-config-property-value>ECHOSTRING,CREATE_ACCOUNT_B,TRANSFER_MONEY_B
   </activation-config-property-value>
  </activation-config-property>
</activation-config>

2. Worker Threads

During inbound communication, one thread is created to accept the specified port and a thread is created for each accepting socket. The number of the threads created is determined by the maximum value specified in the Worker Manager of the application server. Setting the number of the threads varies by the application server vendor.

When a request is sent from a Tmax client, the accepting thread of RA creates worker threads. The created worker threads send the request to MDB to be processed.

The following illustrates the inbound communication structure.

figure inbound webtjca ar
Inbound Communication Structure

3. Message Driven Bean

To create a message driven bean, javax.resource.cci.MessageListener must be implemented.

The following is an example of configuring a message driven bean.

public Record onMessage(Record in) throws ResourceException {
     String svcName = (String)((MappedRecord)in).get("$ServiceName");

     if( svcName.equalsIgnoreCase("echostring") ) {
        return in;
     }
     else if( svcName.equalsIgnoreCase("create_account_b")) {
     }
     else if( svcName.equalsIgnoreCase("transfer_money_b")) {
     }
     return in;
}
  • public Record onMessage(Record in) throws ResourceException

    This method is called when a method throws a record to the resource adapter to deliver the record to MappedRecord. A service name or specific value can be specified in the method by using a special key. The return value of OnMessage is the response message, which is sent from Tmax to the requestor.

    Enter $ReturnCode and $UserCode in the return value to notify of success or failure. If the record is successfully delivered, $ReturnCode is 0. If the record fails to be delivered, $ReturnCode is -1. Enter a user code in $UserCode to be referenced by Tmax.

// When succeeded
MappedRecord out = (MappedRecord) in.clone();
out.put("$ReturnCode", new Integer(0));

// When failed
out.put("$ReturnCode", new Integer(-1));
out.put("$UserCode", new Integer(usrcode));

4. Logging

Inbound communication logs are displayed when the log setting is specified in <resourceadapter> of ra.xml.

To configure inbound logging, add the following settings in ra.xml.

<resourceadapter>
   <config-property>
       <config-property-name>name</config-property-name>
       <config-property-type>java.lang.String</config-property-type>
       <config-property-value>tmaxin1</config-property-value>
   </config-property>
</resourceadapter>