You can set the session on a terminal by either using the setSession method, or by passing the session object as part of a send or connect method.
"null" is also accepted as a session, meaning that you have no listening object in place for replies and exceptions, and that all calls are synchronous.
The session interface defines two methods that must be implemented: getSyncType and handleReply. The following code shows a sample implementation:
import com.ibm.ctg.epi.*;
public class myASession implements Session {
public int getSyncType() {
return Session.async;
}
public void handleReply(TerminalInterface term) {
System.out.println(
"Reply received Terminal state = " + term.getState());
}
public void handleException(TerminalInterface a, Exception e) {
System.out.println("Exception received:" + e.getMessage());
}
}
This example defines the session as an asynchronous session, because it returns Session.async on the getSyncType call. To make the session a synchronous session, you return Session.sync.
The example shows the handleReply and handleException methods:
You must implement the handleReply method. It is called for each transmission received from CICS®. Depending on the design of the CICS server program, a Terminal send call can result in one or more replies. The Terminal state property indicates whether the server has finished sending replies:
The implementation of the handleReply method can read and process data from the Screen object, update fields as required, set the cursor position and AID key in preparation for the return transmission to CICS, and then use the Terminal send method to drive the server application.
In synchronous mode, handleReply executes on the same thread that invoked the send. In asynchronous mode, handleReply executes on a separate thread.
The handleException method is not specified as part of the session interface and is optional unless you are using asynchronous mode sends, when it must be implemented. The compiler does not force implementation of the method. The Terminal class calls this method if it is present in the Session object.
It is recommended that you also implement the handleException method for synchronous mode sends with Automatic Transaction Initiation (ATI) enabled.
For the handleReply method, the Terminal state property shows information about the terminal connection.
Exceptions are passed in the Exception object. See Exception handling, for a list of the exceptions that can occur.