commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Conrad CRAMPTON PSE 52704" <conrad.cramp...@kent.pnn.police.uk>
Subject [pool] testOnBorrow help - doesn't appear to do as expected
Date Tue, 03 Apr 2007 12:46:36 GMT
Hi,
I am trying to use the testOnBorrow method flag for my
GenericPoolableFactory implementation. I have implemented
validateObject(Object o) method thus...
 
 public boolean validateObject(Object o) {
  logger.debug("validating object");
  PNCConnection con = null;
  try {
   con = (PNCConnection) o;
   logger.debug("sessionId => " + con.getSessionId());
  } catch (ClassCastException cce) {
   logger.error(cce, cce);
   return false;
  } catch (Exception e) {
   logger.error(cce, cce);
   return false;
 }
  return (con != null) && (con.getPncService() != null) &&
(con.getScreen() != null);
 }
 
In my borrowObject(Object o) method if the creation of my object fails
for some reason (typically if the underlying connection can't be
created), then I return null from the borrowObject method. I expect that
when null is returned this is the object that gets passed into the
validate method and therefore return false (because of my validateObject
method code above). However, this isn't happening as I get a
nosuchelementException 'Could not create a validated object, cause:
null' being thrown by GenericObjectPool line 871. 
I am getting no debugging output from validateObject method so this
isn't even being hit even though testOnBorrow is set to true. 
 
Can this be explained for me please and how do I get this to work? The
scenario is that the connection may not be available in borrowObject and
therefore wish for the pool to attempt to create a different connection
on fail.
 
Does the validateObject method only work if the object returned from
borrowObject is not null???
 
Thanks
Conrad
 
Thanks
Conrad
 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message