|Re: IBM i persistent connections [message #944579 is a reply to message #941736]
||Mon, 15 October 2012 02:56
| Joseph Vincens
Registered: December 2011
Location: Prospect CT
Very good question.
Yes it can be supported, but it's very different than RBD.
The EDT implementation is more open allowing you to supply an IBMiConnection to the call statement with the 'using' expression. There is a 1 to 1 association between the connection and the host Job. So you can write your own code to create, store, and retrieve IBMiConnections.
I have created a sample library that manages IBMiConnection and an example project showing how to use the library: http://git.eclipse.org/gitroot/edt/org.eclipse.edt.git/ibmi/org.eclipse.edt.jtopen.samples and http://git.eclipse.org/gitroot/edt/org.eclipse.edt.git/ibmi/org.eclipse.edt.ibmi.examples respectively.
These samples rely on J2EE functionality so they are only available to applications deployed on a application server. You could use some of the same concepts with a program in a batch environment.
In the example project server.GETREC.getCustomers gets fake customer information using a program on IBM I. The first request returns the first 10 records, the second request returns the second 10, etc. You would use the same 3 steps in your application replacing the application specific information. Here's what you need to do and it's shown in the example:
- use SessionConnectionsLib.getSessionConnection passing the system, userid, and password to get the IBMiConnection.
- use the IBMiConnection in the 'using' expression of a call statement that targets an IBMi proxy function (a function that has the IBMiProgram annotation).
- after the call returns use SessionConnectionsLib.returnConnectionToPool passing the IBMiConnection to return the connection to the pool. This is critical so the connection is available for the next use.
I think it will be useful if you understand the code that handles the persistent connection. Here is an overview of what happens in the SessionConnectionsLib.getSessionConnection:
- create a key that represents the system and userid.
- get the sessionid
- get the HttpServletRequest context created when the service was invoked
- get the HttpSession from the HttpServletRequest context.
- Return the sessionId from the HttpSession
- get the connections available for the specific sessionId
The connections for a session are stored in a Dictionary, which is stored on a Java class (org.eclipse.edt.jtopen.connection.persistent.SessionConnectionPool) using the sessionId. The Java class has a static method used for getting a static instance of the class thereby creating the storage so the connections are available from invocation to invocation.
- get the IBMiConnection
- If the key does not exist in the pool create and return a new IBMiConnection using the system, userid, and password.
- if the key exists there is a connection in the pool. That connection is returned and removed from the pool. This prevents it from another call trying to use the connection while it's already in use.
If the sample does not suite your needs you are free to use any part of it to implement your requirements.
I hope this helps.
Powered by FUDForum
. Page generated in 0.09525 seconds