Hi Guys,
here is my code on how I have implemented connection pooling for a webservice stub.
package com.arcot.integrations.frontend.tasks.custom.utils;
import java.util.Stack;
import org.apache.axis2.client.Options; import org.apache.axis2.client.ServiceClient;
import com.tpf.mdm.tpf.service.TPFServiceStub;
//import com.arcot.ws.webfortauthapi._6_0.wsdl.RBSAuthServiceStub;
public class CIClientPool {
// private TPFServiceStub clientstub_; private String url_; private String uniqueid_;
private int timeout_ = 2; // timeout iprivate String url_; // WS URLn minutes
private Stack<TPFServiceStub> clientq_;
private int poolsize_ = 10; // default pool-size id 10
private TPFServiceStub initiateClient() {
System.out.println("inside CIClientPool.initiateClient()");
TPFServiceStub client = null;
try {
long soTimeout = timeout_ * 60 * 1000; // Two minutes
ServiceClient serviceClient = new ServiceClient();
Options options = new Options();
options.setTimeOutInMilliSeconds(soTimeout);
client = new TPFServiceStub(url_);
/* client._getServiceClient().setOptions(options);
client._getServiceClient().cleanup()*/
}
catch(Exception e) {
e.printStackTrace();
}
return client;
}
private void createQ() {
System.out.println("inside CIClientPool.createQ()");
clientq_ = new Stack<TPFServiceStub>();
for(int i = 0; i<poolsize_; i++) {
clientq_.push(initiateClient());
}
}
private CIClientPool(String url, int poolsize, int timeout) {
System.out.println("inside CIClientPool.CIClientPool()");
url_ = url;
poolsize = poolsize_;
timeout = timeout_;
createQ();
}
private TPFServiceStub popClient() {
System.out.println("inside CIClientPool.popClient()");
TPFServiceStub client = clientq_.pop();
Options options = new Options();
options.setTimeOutInMilliSeconds(timeout_ * 5 * 1000);
//client._getServiceClient().setOptions(options);
return client;
}
private void pushClient(TPFServiceStub clientstub) {
System.out.println("inside CIClientPool.pushClient()");
clientq_.push(clientstub);
}
private static CIClientPool cipool;
public static TPFServiceStub getCIClient(String url, int poolsize, int timeout) {
System.out.println("inside CIClientPool.getCIClient()");
if(cipool == null) {
System.out.println("url="+url+" poolsize="+poolsize+" timeout="+timeout);
cipool = new CIClientPool(url, poolsize, timeout);
}
return cipool.popClient();
}
public static void pushCIClient(TPFServiceStub clientstub) {
System.out.println("inside static CIClientPool.pushCIClient()");
try{
if(cipool==null){
System.out.println("cipool is null");
}
else{
cipool.pushClient(clientstub);
}
}catch(Exception e){
e.printStackTrace();
System.out.println("Exception at inside static CIClientPool.pushCIClient() :"+e.getMessage());
}
}
}
I would like to know if the is flush() functionality available for this and also when I do this Options options = new Options(); options.setTimeOutInMilliSeconds(soTimeout);
client = new TPFServiceStub(url_);
client._getServiceClient().setOptions(options);
i.e setting a time out for my stub I get an exception while calling the webservice using the stub.
Thanks in advance