JTC Classes and Functions

This chapter describes JTC classes and functions.

1. Overview

The following describes each class provided by JTC.

Class Description

TuxService

Provides functions for executing Tuxedo services.

TuxAsyncService

Inherited from TuxService to support the Async Listener structure.

TuxRemoteServiceManager

Allows a cluster domain to call a service.

TuxBuffer

Parent class of Tuxedo data buffers used to exchange data with Tuxedo.

Creates a buffer to use string (or byte array) data.

TuxFieldBuffer

Data class needed to use Tuxedo FML and FML32 buffers.

TuxFMLBeanGen

Creates a default Java bean class for a service handling FML-type messages.

2. TuxService

The TuxService class provides functions for executing Tuxedo services. All communication is enabled through TuxService.

The following describes each function provided in the TuxService class.

Function Description

createCarrayBuffer

Creates a byte array buffer used to communicate with Tuxedo.

createFieldBuffer

Creates a FML buffer used to communicate with Tuxedo.

createStringBuffer

Creates a string buffer used to communicate with Tuxedo.

setAttribute

Sets user flags to be applied to a service.

setDefaultCharset

Specifies a character set that encodes and decodes a value from a byte array to string or string to byte array when using string data.

setServiceName

Changes the default service name of a TuxService instance.

tpacall

Asynchronously calls a Tuxedo service.

tpcall

Synchronously calls a Tuxedo service.

tpconnect

Establishes Tuxedo conversational communication.

tpdiscon

Disconnects Tuxedo conversational communication.

tpgetrply

Gets a response to tpacall.

tprecv

Receives a message through a preset conversational service.

tpsend

Sends a message through a preset conversational service.

TuxService

Creates TuxService.

2.1. createCarrayBuffer

The createCarrayBuffer function creates a byte array buffer used to communicate with Tuxedo.

  • Prototype

    public TuxBuffer createCarrayBuffer([int size])
  • Parameter

    Parameter Description

    size

    Size of CarryBuffer to be created.

  • Return Value

    Returns TuxBuffer.

2.2. createFieldBuffer

The createFieldBuffer function creates a FML buffer used to communicate with Tuxedo.

  • Prototype

    public TuxBuffer createFieldBuffer([boolean isFML32, [int size,]]
                                       TuxFieldTable table)
  • Parameter

    Parameter Description

    isFML32

    Input options:

    • True: when FML32 is used

    • False: when FML16 is used

    size

    Size of FieldBuffer to be created.

    table

    Table class created using TuxFieldGen().

  • Return Value

    Returns TuxBuffer.

  • Example

    java -cp ..\webtJtc.jar tmax.webt.util.TuxFieldGen  -32 com.tys.sde.wtc anta.fld
    
    package com.tys.sde.wtc;
    
    import tmax.webt.util.TuxFieldTable;
    
    public class anta.fld implements TuxFieldTable {
        public static final int    ftp_hostdir = 167804166;
        public static final int    ftp_filename = 167804165;
        public static final int    ftp_dir = 167804164;
        public static final int    ftp_pswd = 167804163;
        public static final int    ftp_id = 167804162;
        public static final int    ftp_svr = 167804161;
        public static final int    split_filename = 167807162;
        public static final int    split_data = 167807161;
        public static final int    carray01 = 201349593;
        public static final int    string99 = 167792259;
        public static final int    string98 = 167792258;
        public static final int    string97 = 167792257;
        public static final int    string96 = 167792256;
        public static final int    string93 = 167792253;
    }
    javac -classpath .;webtJtc.jar;sdeLib.jar;%JEUS_HOME%/lib/
    system/jeus.jar WTCService.java 2> err

2.3. createStringBuffer

The createStringBuffer function creates a string buffer used to communicate with Tuxedo.

  • Prototype

    public TuxBuffer createStringBuffer([int size])
  • Parameter

    Parameter Description

    size

    Size of StringBuffer to be created.

  • Return Value

    Returns TuxBuffer.

2.4. setAttribute

The setAttribute function sets user flags applied to a service.

  • Prototype

    public void setAttribute(int attr, boolean value)
  • Parameter

    Parameter Description

    attr

    Target flags.

    value

    Input options:

    • True: sets WebtAttribute.

    • False: releases WebtAttribute.

2.5. setDefaultCharset

The setDefaultCharset function specifies a character set (ISO-8859-1, UFT-8, EUC-KR and others) that encodes and decodes a value from a byte array to string or string to byte array when using string data.

The character set must be specified before a buffer is created. The default is ISO-8859-1.

  • Prototype

    public void setDefaultCharset(String charset)
  • Parameter

    Parameter Description

    charset

    Character set value to be encoded. (Default: ISO-5589-1)

  • Example

    TuxService service = new TuxService("SAMPLE", "TUXDOM");
    service.setDefaultCharset("ISO-8859-1");
    TuxBufferImpl buf = service.createStringBuffer(); // ISO-8859-1
    
    service.setDefaultCharset("ISO-8859-2");
    TuxBufferImpl buf2 = service.createStringBuffer(); // ISO-8859-2

2.6. setServiceName

The setServiceName function changes the default service name of a TuxService instance.

  • Prototype

    public void setServiceName(String serviceName)
  • Parameter

    Parameter Description

    serviceName

    Name of Tuxedo service name to be called.

  • Example

    TuxService service = new TuxService("SAMPLE", "TUXDOM");
    Service.tpcall(buf);// calls “SAMPLE” service
    
    service.setServiceName ("SAMPLE2");
    Service.tpcall(buf);// calls “SAMPLE2” service

2.7. tpacall

The tpacall function asynchronously calls a Tuxedo service. A client calls a service and then gets a handler for the service call. The client use the handler to get the result value at anytime.

  • Prototype

    public TuxCallDescripter tpacall([String svcname,] TuxBuffer input
                                     [, WebtAttribute attr])
  • Parameter

    Parameter Description

    svcname

    Tuxedo service name.

    input

    TuxBuffer buffer to be requested.

    attr

    Service attribute.

  • Return Value

    Returns TuxCallDescripter.

2.8. tpcall

The tpcall function synchronously calls a Tuxedo service. A client waits for a result value in the blocked status for a specified period. A service name can be specified to call a service other than the default service, which is set when a TuxService instance is created.

  • Prototype

    public TuxBuffer tpcall(String svcname, TuxBuffer input[[, WebtAttribute attr],
                            int timeout])
  • Parameter

    Parameter Description

    svcname

    Tuxedo service name.

    input

    TuxBuffer buffer to be requested.

    timeout

    Maximum time to wait for a result.

  • Return Value

    Returns TuxBuffer.

  • Example

    try {
         TuxBufferImpl rcvbuf = service.tpcall(sndbuf);
         out.println(rcvbuf.getString());
    }
    catch (WebtException e) {
         e.printStackTrace();
         out.println("error Occurred");
         return;
    }

2.9. tpconnect

The tpconnect function establishes Tuxedo conversational communication.

  • Prototype

    public TuxCallDescripter tpconnect([TuxBuffer sndbuf,] [WebtAttribute attr,]
                                        boolean recvNext)
  • Parameter

    Parameter Description

    sndbuf

    TuxBuffer buffer to be requested.

    attr

    Service attribute.

    recvNext

    Input options:

    • True: receives the next response.

    • False: receives a response only once.

  • Return Value

    Returns TuxCallDescripter.

2.10. tpdiscon

The tpdiscon function disconnects Tuxedo conversational communication.

  • Prototype

    public void tpdiscon(TuxCallDescripter cd)
  • Parameter

    Parameter Description

    cd

    Handler returned by tpconnect().

2.11. tpgetrply

The tpgetrply function gets a response to tpacall.

  • Prototype

    public TuxBuffer tpgetrply(TuxCallDescripter cd[, WebtAttribute attr]
                               [, int timeout])
  • Parameter

    Parameter Description

    cd

    Handler returned by tpacall().

    attr

    Service attribute.

    timeout

    Maximum time to wait for a result.

  • Return Value

    Returns TuxBuffer.

  • Example

    TuxService service = new TuxService("READDATA", "TUXDOM");
    TuxBufferImpl sndbuf = service.createCarrayBuffer();
    sndbuf.setBytes(toconv);
    
    try {
          TuxCallDescripter cd = service.tpacall(sndbuf);
          TuxBufferImpl rcvbuf = service.tpgetrply(cd);
          out.println(rcvbuf.getString());
    }
    catch (WebtException e) {
        e.printStackTrace();
        out.println("error Occurred");
        return;
    }

2.12. tprecv

The tprecv function receives a message through a preset conversational service.

  • Prototype

    public TuxBuffer tprecv(TuxCallDescripter cd[,WebtAttribute attr])
  • Parameter

    Parameter Description

    cd

    Handler returned by tpacall().

    attr

    Service attribute.

  • Return Value

    Returns TuxBuffer.

  • Example

    TuxService service = new TuxService("TMXDOM","TOUPPER_CONVN");
    TuxBuffer sndbuf = service.createStringBuffer();
    sndbuf.setString("conversation service");
    TuxCallDescripter cd = service.tpconnect(false);
    
    if(cd == null) {
          out.println("tpconnect failed!");
    }
    else {
          service.tpsend(cd, sndbuf, true);
          WebtAttribute attr = new WebtAttribute();
          attr.setTPNOTIME(true);
    
          if(service.isRecvNext()) {
                 TuxBuffer rcvbuf = service.tprecv(cd,attr);
          }
    }
    service.tpdiscon(cd);

2.13. tpsend

The tpsend function sends a message through a preset conversational service.

  • Prototype

    public void tpsend(TuxCallDescripter cd,TuxBuffer tx[, WebtAttribute attr],
                       boolean recvNext)
  • Parameter

    Parameter Description

    cd

    Handler returned by tpacall().

    tx

    TuxBuffer buffer to be requested.

    attr

    Service attribute.

    recvNext

    Input options:

    • True: receives the next response.

    • False: receives a response only once.

2.14. TuxService

The TuxService function creates TuxService. If there is only one Tuxedo domain, the domainName argument can be omitted.

  • Prototype

    public TuxService([String domainName,] String serviceName)
  • Parameter

    Parameter Description

    domainName

    Tuxedo domain name.

    serviceName

    Tuxedo service name.

  • Return Value

    Returns TuxService.

3. TuxAsyncService

The TuxAsyncService class is a class inherited from TuxService to support the Async Listener structure.

The following describes each function provided in the TuxAsyncService class.

Function Description

getXAResource

Creates XA resources.

tpacall

Asynchronously calls a Tuxedo service.

TuxAsyncService

Creates TuxService.

The following example uses TuxAsyncService to use the Async listener structure.

TmaxXid xid = new TmaxXid(1,4,0);
TuxAsyncService service = new TuxAsyncService("TUXGW1","TUX_INSERT");
try {
    service.getXAResource().start(xid, 0);
}
catch (XAException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
TuxBuffer input = service.createStringBuffer();
input.setString("abc");
TuxAsyncMsgListener listener = new TestMsgListener(service, xid);
service.tpacall(input, null, listener );

The following example uses TuxAsyncService to implement the TuxAsyncMsgListener interface. The interface has two methods: void handleEvent(TuxBuffer rcvBuffer) in which reception actions are implemented and void handleError(Exception e).

public class TestMsgListener implements TuxAsyncMsgListener {
       TuxAsyncService service;
       Xid xid;

       public TestMsgListener(TuxAsyncService service, Xid xid) {
              this.service = service;
              this.xid = xid;
       }

       public void handleError(Exception e) {
              System.out.println(e);
       }

       public void handleEvent(TuxBuffer rcvBuffer) {
              System.out.println(Thread.currentThread().getName()
                                 +" ] rcv " + rcvBuffer);
              try {
                   service.getXAResource().prepare(xid,
                                 new TestTuxPrepareMsgListener(service,xid));
              }
              catch (XAException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              }
       }
}

3.1. getXAResource

The getXAResource function creates XA resources.

  • Prototype

    public TuxAsyncXAResource getXAResource()
  • Return Value

    Returns TuxAsyncXAResource.

    The following methods are additionally implemented in TuxAsyncXAResource for Async Listener.

    public int prepare(Xid xid, TuxAsyncMsgListener listener)
    public void commit(Xid xid, TuxAsyncMsgListener listener)
    public void rollback(Xid xid, TuxAsyncMsgListener listener)

3.2. tpacall

The tpacall function asynchronously calls a Tuxedo service. A listener parameter in addition to the parameters in tpacall is added.

  • Prototype

    public TuxCallDescripter tpacall(TuxBuffer input, WebtAttribute attr,
                                     TuxAsyncMsgListener listener)
  • Parameter

    Parameter Description

    input

    TuxBuffer buffer to be requested.

    attr

    Service attribute.

    listener

    Object in which reception actions are implemented.

  • Return Value

    Returns TuxCallDescripter.

3.3. TuxAsyncService

The TuxAsyncService function creates TuxService. If there is only one Tuxedo domain, a domainName argument can be omitted.

  • Prototype

    public TuxAsyncService([String domainName,] String serviceName)
  • Parameter

    Parameter Description

    domainName

    Tuxedo domain name.

    serviceName

    Tuxedo service name.

  • Return Value

    Returns TuxAsyncService.

4. TuxRemoteServiceManager

When using a JTC cluster, TuxRemoteServiceManager class APIs are used to efficiently call a service. This class allows a service to be called through an appropriate remote domain.

If a service is called through TuxService, it is called through a different domain each time. However, if a service is called through TuxedoRemoteServiceManager and a service is called through a specific remote domain once, the service is always called through the same domain.

The following describes each function provided in the TuxRemoteServiceManager class.

Function Description

TuxedoRemoteServiceManager

Creates the TuxedoRemoteServiceManager class.

createStringBuffer

Creates a string buffer used to communicate with Tuxedo.

createCarrayBuffer

Creates a byte array buffer used to communicate with Tuxedo.

createFiledBuffer

Creates a field buffer used to communicate with Tuxedo.

tpcall

Calls a Tuxedo service.

4.1. TuxedoRemoteServiceManager

The TuxedoRemoteServiceManager function creates the TuxedoRemoteServiceManager class.

  • Prototype

    Public TuxedoRemoteServiceManager()

4.2. createStringBuffer

The createStringBuffer function creates a string buffer used to communicate with Tuxedo. It operates in the same way as the createStringBuffer function of the TuxService class.

  • Prototype

    Public TuxBuffer createStringBuffer([int size])
  • Return Value

    Returns TuxBuffer.

4.3. createCarrayBuffer

The createCarrayBuffer function creates a byte array buffer used to communicate with Tuxedo. It operates in the same way as the createCarrayBuffer function of the TuxService class.

  • Prototype

    Public TuxBuffer createCarrayBuffer([int size])
  • Return Value

    Returns TuxBuffer.

4.4. createFiledBuffer

The createFieldBuffer function creates a field buffer used to communicate with Tuxedo. It operates in the same way as the createFieldBuffer(TuxFieldTable) function of the TuxService class.

  • Prototype

    Public TuxBuffer createFiledBuffer(TuxFieldTable table)
  • Parameter

    Parameter Description

    table

    Table class created using TuxFieldGen.

  • Return Value

    Returns TuxBuffer.

4.5. tpcall

The tpcall function calls a Tuxedo service.

  • Prototype

    Public TuxBuffer tpcall(String svcname, TuxBuffer input)
  • Parameter

    Parameter Description

    svcname

    Name of the service requested.

    input

    TuxBuffer buffer requested.

  • Return Value

    Returns TuxBuffer.

5. TuxBuffer

The TuxBuffer class is a parent class of Tuxedo data buffers used to exchange data with Tuxedo. It does not provide a function but provides interfaces for child data buffer classes. A Tuxedo data buffer is created using a method of a TuxService instance or a Static method of the WebBuffer class.

6. TuxStringBuffer/TuxCarrayBuffer

The TuxStringBuffer and TuxCarrayBuffer classes create a buffer to use string and byte array data respectively.

The following describes each function provided in the TuxStringBuffer and TuxCarrayBuffer classes.

Function Description

getBytes

Gets a byte array value converted from a saved string value.

getString

Gets a saved string value.

setBytes

Saves a byte array value.

setString

Saves a string value.

6.1. getBytes

The getBytes function gets a byte array value converted from a saved string value.

  • Prototype

    public byte[] getBytes()
  • Return Value

    Returns a byte array value converted from a saved string value.

6.2. getString

The getString function gets a saved string value.

  • Prototype

    public String getString([String charset])
  • Parameter

    Parameter Description

    charset

    Character set for encoding. If it is not necessary, specify NULL.

  • Return Value

    Returns a saved string value.

6.3. setBytes

The setBytes function saves a byte array value.

  • Prototype

    public void setBytes(byte[] val)
  • Parameter

    Parameter Description

    val

    Byte data to be requested.

6.4. setString

The setString function saves a string value.

  • Prototype

    public void setString(String value[, String charset])
  • Parameter

    Parameter Description

    value

    String data to be requested.

    charset

    Character set for decoding. If it is not necessary, specify NULL.

7. TuxFieldBuffer

The TuxFieldBuffer class is a data class needed to use Tuxedo FML and FML32 buffers. This class has multiple fields that have a unique key and a key name. Each field has multiple values. To save a value, a field that saves an actual value must be created.

Two types of fields are supported: a field to save string or byte array data and a field to save numeric data. If another type of data is saved, WebtBufferException occurs.

The following describes each function provided in the TuxFieldBuffer class.

Function Description

createField

Creates a field within TuxFieldBuffer.

getField

Gets a field that corresponds to a key value.

getFields

Gets all fields within a field buffer as a vector.

7.1. createField

The createField function creates a field within TuxFieldBuffer.

  • Prototype

    public WebtField createField(int fldkey|string fldkey)
  • Parameter

    Parameter Description

    int fldkey

    Int field key value to be created.

    string fldkey

    String field key value to be created.

  • Return Value

    If there is already a field that corresponds to a field key value, the field is returned.

  • Example

    Table table = new Table()
    TuxBufferImpl buf = WebtBuffer.createTuxFieldBuffer(true, table);
    
    // Creates a WebField object that a field key value is INT1.
    WebtField field1 = buf.createField(table.INT1);
    
    // Creates a WebField object that a field key name is "INT2."
    WebtField field2 = buf.createField("INT2");

7.2. getField

The getField function gets a field that corresponds to a key value.

  • Prototype

    public WebtField getField(int fldkey|string fldkey)
  • Parameter

    Parameter Description

    int fldkey

    Int field key value to be read from a returned Tuxbuffer.

    string fldkey

    String field key value to be read from a returned Tuxbuffer.

  • Return Value

    Returns a field that corresponds to a key value. If no field exists, NULL is returned.

7.3. getFields

The getFields function gets all fields within a field buffer as a vector.

  • Prototype

    public Vector getFields()
  • Return Value

    Returns all fields within a field buffer as a vector.

  • Example

    Table table = new Table();
    TuxBufferImpl buf = WebtBuffer.createTuxFieldBuffer(true, table);
    
    WebtField field = buf.createField(table.INPUT);
    field.add("VALUE1");
    field.add("VALUE2");
    field.add("VALUE3");
    
    Vector fields = buf.getFields();
    String[] fieldValues = (String[])fields.toArray(new String[0]);
    
    for (int i=0; i++; i<fieldValues.length) {
        System.out.prinln("Value[" + i + "]  : " + fieldValues[i]);

8. TuxFMLBeanGen

The TuxFMLBeanGen utility generates a default JavaBean class for FML-type request/reply messages in a service. It is provided to simplify use by Java users.

  • Usage

    java -cp webt*.jar tmax.jtc.util.TuxFMLBeanGen -f service definition file[,service definition file]
    -m fml file[,fml file] -o output directory [-s service[,service]] [-p package name]
  • Parameter

    Parameter Description

    -f service definition file[,service definition file]

    List of service definition files. Multiple files can be specified.

    -m fml file[,fml file]

    FML file to use.

    -o output directory

    Directory where the result java files are generated.

    -s service[,service]

    List of the services in the service definition file to be converted to Java source code. Multiple service names can be specified, separated by commas (,) without spaces.

    -p package name

    Name of the package containing the generated files.

  • Service definition file format

    *Service name
    *request
    FIELDNAME1
    FIELDNAME2
    
    *reply
    FIELDNAME3
    FIELDNAME4
    
    
    Iterate...

    Multiple services can be defined in a single file. *request is composed of messages to be sent to the services, and *reply contains messages to be returned by the services through tpreturn.

  • Java file converted

    The user creates two files, a request file and a reply file, using the name of the specified service.

    • service name+RequestBean.java

    • service name+ReplyBean.java

      The following describes each field value and method.

      Item Description

      Field value

      Defines the field value with the public type field name.

      getter/setter

      • public type get field name

      • public set field name (type)