in client/src/main/java/org/apache/qpid/client/PooledConnectionFactory.java [455:543]
public synchronized Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable
{
if(_closed)
{
throw new IllegalStateException("Connection is closed");
}
Method underlyingMethod = _underlyingConnection.getClass().getMethod(method.getName(), method.getParameterTypes());
if(method.getName().equals("getExceptionListener"))
{
return _exceptionListener;
}
else if(method.getName().equals("setExceptionListener") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(ExceptionListener.class))
{
_exceptionListener = (ExceptionListener) args[0];
return null;
}
else if(method.getName().equals("close") && method.getParameterTypes().length == 0)
{
_closed = true;
_exceptionListener = null;
List<Session> openSessions = new ArrayList<>(_openSessions);
for(Session session : openSessions)
{
try
{
session.close();
}
catch(JMSException | RuntimeException | Error e)
{
_exceptionThrown = true;
try
{
_underlyingConnection.close();
}
finally
{
throw e;
}
}
}
_openSessions.clear();
if(!_exceptionThrown)
{
returnToPool(_underlyingConnection, _identityHash);
}
else
{
_underlyingConnection.close();
}
return null;
}
else if(method.getName().equals("toString") && method.getParameterTypes().length == 0)
{
try
{
Object returnVal = underlyingMethod.invoke(_underlyingConnection, args);
return "[Pool:"+_poolId+"][conn:"+_instanceId+"]: " + String.valueOf(returnVal);
}
catch (InvocationTargetException e)
{
_exceptionThrown = true;
Throwable thrown = e.getCause();
throw thrown == null ? e : thrown;
}
}
else
{
try
{
Object returnVal = underlyingMethod.invoke(_underlyingConnection, args);
if(returnVal instanceof Session)
{
returnVal = proxySession((Session)returnVal, this);
_openSessions.add((Session)returnVal);
}
return returnVal;
}
catch (InvocationTargetException e)
{
_exceptionThrown = true;
Throwable thrown = e.getCause();
throw thrown == null ? e : thrown;
}
}
}