OpenTP1 Version 7 TP1/Client User's Guide TP1/Client/J
Declare import of the TP1/Client/J package in the program.
Import the TP1/Client/J package in the same manner as when the package of each Java facility is imported.
import java.applet.*; // Import java.applet package import java.awt.*; // Import java.awt package import JP.co.Hitachi.soft.OpenTP1.*; // Import TP1Client package
The class name of TP1/Client/J is TP1Client. Create an instance of the TP1Client class when you need to access TP1/Server.
TP1Client stock; // Declare the instance variable named stock stock = new TP1Client(); // Create an instance of the TP1Client class // (constructor call)
Initialize the RPC environment to call TP1/Server's SPP. To initialize the RPC environment, call the rpcOpen method.
If an error occurs during the call, the rpcOpen method returns an exception. Execute exception processing, if necessary.
If you are issuing an RPC that uses the scheduler direct facility, an RPC that uses the name service, or an RPC specifying the communication target, be sure to call the rpcOpen method. If you are issuing an RPC that uses the remote API facility, you need not call the rpcOpen method.
try { stock.rpcOpen(); // Initialize the RPC environment } catch(ErrFatalException e) { // Occurrence of RPC environment // initialization error System.out.println("CUP Initialize error"); } catch (TP1ClientException e) { // Occurrence of other error System.out.println("error occured"); }
try { stock.rpcOpen("C:\\Clt4J\\conf\\clt4j.ini"); // Initialize the RPC environment } catch(ErrFatalException e) { // Occurrence of RPC environment // initialization error System.out.println("CUP Initialize error"); } catch (TP1ClientException e) { // Occurrence of other error System.out.println("error occured"); }
To issue an RPC that uses the remote API facility, connection is established with TP1/Server's RAP-processing listener and server. A dedicated TCP/IP connection is established between the Java applet, application, or servlet and the RAP-processing server until the connection is released.
To establish a connection, call the openConnection method of the TP1Client class. If an error occurs during the call, the openConnection method returns an exception. Execute exception processing, if necessary.
If you are issuing an RPC that uses the scheduler direct facility, an RPC that uses the name service, an RPC specifying the communication target, or an RPC that uses the auto connect mode, do not call the openConnection method.
try { stock.openConnection("stocksv",12000); // Establish connection with RAP-processing // listener and server } catch(ErrTimedOutException e) { // Occurrence of connection timeout System.out.println("server inactive"); } catch (TP1ClientException e) { // Occurrence of other error System.out.println("error occured"); }
The CUP may not be able to detect release of the permanent connection if the RAP-processing listener, RAP-processing server, or OpenTP1 system terminates abnormally while the permanent connection is established. In such a case, the next method issued (rpcCall or closeConnection) may return ErrTimedOutException.
If connection is established successfully with the RAP-processing server, you can call (RPC) a remote service (SPP). To issue an RPC, call the rpcCall method. In the arguments of the rpcCall method, specify the service group name for the service, the service name, inquiry data, inquiry data length, response data reception area, response data reception area size, and RPC execution mode.
If an error occurs during the call, the rpcCall method returns an exception. Execute exception processing, if necessary.
int in_len[] = new int[1]; int out_len[] = new int[1]; byte in_data[]; byte out_data[]; String in = "PN=0012-2456-12"; // Inquiry data (fixed character string // for convenience) in_len[0] = 16; // Inquiry data length (fixed string for convenience) out_len[0] = 16; // Response data area size (fixed for convenience) in_data = new byte[in_len[0]]; // Create inquiry data area in.getBytes(0, in.length(), in_data, 0); // Set inquiry data out_data = new byte[out_len[0]]; // Create response data area try { stock.rpcCall("group", "service", // Execute RPC (inquiry // response type) in_data, in_len, out_data, out_len, stock.DCNOFLAGS); } catch (ErrTimedOutException e) { // RPC request timeout System.out.println("RPC timedout"); } catch (TP1ClientException e) { // Occurrence of other error System.out.println("error occured"); }
There are three types of RPCs, as listed in the table below; specify the desired type in the flags argument:
RPC type | Function | Specification method | |
---|---|---|---|
Inquiry response | Without chain | A response is returned after a service request is issued to the server. The next time an inquiry is sent to the same server, the same server process as the previous one may not be used. | DCNOFLAGS |
With chain | A response is returned after a service request is issued to the server. The next time an inquiry is sent to the same server, the same server process as the previous one is used (the server process is locked). This is not applicable to RPCs that use the scheduler direct facility or name service. | DCRPC_CHAINED | |
No response | No response can be received after a service request is issued to the server. The client does not know whether the service executed successfully. Because the RPC does not wait for a response, the client's execution performance is high. | DCRPC_NOREPLY |
Once an online application with TP1/Server has been completed, call the closeConnection method to release the permanent connection from the RAP-processing listener and server. This method has no arguments.
If an error occurs during the call, the closeConnection method returns an exception. Execute exception processing, if necessary.
try { stock.closeConnection(); // Release permanent connection from RAP-processing listener and server } catch (TP1ClientException e) { // Occurrence of error System.out.println("error occured"); }
At the end of the CUP, call the rpcClose method to release the RPC environment of the CUP. This method has no arguments.
If an error occurs during the call, the rpcClose method returns an exception. Execute exception processing, if necessary.
try { stock.rpcClose(); // Release RPC environment } catch (TP1ClientException e) { // Occurrence of error System.out.println("error occured"); }
All Rights Reserved. Copyright (C) 2006, 2009, Hitachi, Ltd.