protected boolean doRemove(ManagedConnectionInfo mci) { return pool.remove(mci.getManagedConnection()) == null; }
public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); if (mci.getManagedConnection() != null) { return; } try { ManagedConnection mc = mci.getManagedConnectionFactory().createManagedConnection( mci.getSubject(), mci.getConnectionRequestInfo()); mci.setManagedConnection(mc); GeronimoConnectionEventListener listener = new GeronimoConnectionEventListener(stack, mci); mci.setConnectionEventListener(listener); mc.addConnectionEventListener(listener); } catch (ResourceException re) { log.error("Error occurred creating ManagedConnection for " + connectionInfo, re); throw re; } }
protected void doAdd(ManagedConnectionInfo mci) { pool.put(mci.getManagedConnection(), mci); }
public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { if (connectionInfo.isUnshareable()) { next.getConnection(connectionInfo); return; } ManagedConnectionInfo managedConnectionInfo = connections.get(); if (managedConnectionInfo != null) { if (matchConnections) { ManagedConnectionInfo mciRequest = connectionInfo.getManagedConnectionInfo(); if (null != managedConnectionInfo.getManagedConnectionFactory().matchManagedConnections( Collections.singleton(managedConnectionInfo.getManagedConnection()), mciRequest.getSubject(), mciRequest.getConnectionRequestInfo() )) { connectionInfo.setManagedConnectionInfo(managedConnectionInfo); return; } else { //match failed, get a new cx after returning this one connections.set(null); next.returnConnection(connectionInfo, ConnectionReturnAction.RETURN_HANDLE); } } else { connectionInfo.setManagedConnectionInfo(managedConnectionInfo); return; } } //nothing for this thread or match failed next.getConnection(connectionInfo); connections.set(connectionInfo.getManagedConnectionInfo()); }
protected void internalDestroy() { synchronized (pool) { while (!pool.isEmpty()) { ManagedConnection mc = pool.remove(pool.size() - 1).getManagedConnection(); if (mc != null) { try { mc.destroy(); } catch (ResourceException re) { //ignore } } } } }
public void returnConnection( ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) { ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); ManagedConnection mc = mci.getManagedConnection(); try { mc.destroy(); } catch (ResourceException e) { //log and forget } catch (Error e) { throw e; } catch (Throwable t) { //log and forget } }
public void connectionClosed(ConnectionEvent connectionEvent) { if (connectionEvent.getSource() != managedConnectionInfo.getManagedConnection()) { throw new IllegalArgumentException( "ConnectionClosed event received from wrong ManagedConnection. Expected " + managedConnectionInfo.getManagedConnection() + ", actual " + connectionEvent.getSource()); } if (log.isTraceEnabled()) { log.trace("connectionClosed called with " + connectionEvent.getConnectionHandle() + " for MCI: " + managedConnectionInfo + " and MC: " + managedConnectionInfo.getManagedConnection()); } ConnectionInfo ci = new ConnectionInfo(managedConnectionInfo); ci.setConnectionHandle(connectionEvent.getConnectionHandle()); try { stack.returnConnection(ci, ConnectionReturnAction.RETURN_HANDLE); } catch (Throwable e) { if (log.isTraceEnabled()) { log.trace("connectionClosed failed with " + connectionEvent.getConnectionHandle() + " for MCI: " + managedConnectionInfo + " and MC: " + managedConnectionInfo.getManagedConnection(), e); } if (e instanceof Error) { throw (Error)e; } } }
public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { if (connectionInfo.getManagedConnectionInfo().getManagedConnection() != null) { if (log.isTraceEnabled()) { log.trace("supplying already assigned connection from pool " + this + " " + connectionInfo); } return; } try { resizeLock.readLock().lock(); try { if (permits.tryAcquire(blockingTimeoutMilliseconds, TimeUnit.MILLISECONDS)) { try { internalGetConnection(connectionInfo); } catch (ResourceException e) { permits.release(); throw e; } } else { throw new ResourceException("No ManagedConnections available " + "within configured blocking timeout ( " + blockingTimeoutMilliseconds + " [ms] ) for pool " + this); } } finally { resizeLock.readLock().unlock(); } } catch (InterruptedException ie) { throw new ResourceException("Interrupted while requesting permit.", ie); } // end of try-catch }
public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) { if (log.isTraceEnabled()) { log.trace("returning connection " + connectionInfo.getConnectionHandle() + " for MCI " + connectionInfo.getManagedConnectionInfo() + " and MC " + connectionInfo.getManagedConnectionInfo().getManagedConnection() + " to pool " + this); connectionInfo.getManagedConnectionInfo().getManagedConnection().destroy(); } catch (ResourceException re) { if (connectionReturnAction == ConnectionReturnAction.RETURN_HANDLE && mci.hasConnectionHandles()) { if (log.isTraceEnabled()) { log.trace("Return request at pool with connection handles! " + connectionInfo.getConnectionHandle() + " for MCI " + connectionInfo.getManagedConnectionInfo() + " and MC " + connectionInfo.getManagedConnectionInfo().getManagedConnection() + " to pool " + this, new Exception("Stack trace"));
public void connectionErrorOccurred(ConnectionEvent connectionEvent) { if (connectionEvent.getSource() != managedConnectionInfo.getManagedConnection()) { throw new IllegalArgumentException( "ConnectionError event received from wrong ManagedConnection. Expected " + managedConnectionInfo.getManagedConnection() + ", actual " + connectionEvent.getSource()); } log.warn("connectionErrorOccurred called with " + connectionEvent.getConnectionHandle(), connectionEvent.getException()); boolean errorOccurred = this.errorOccurred; this.errorOccurred = true; if (!errorOccurred) { ConnectionInfo ci = new ConnectionInfo(managedConnectionInfo); ci.setConnectionHandle(connectionEvent.getConnectionHandle()); stack.returnConnection(ci, ConnectionReturnAction.DESTROY); } }
public void exit(Collection<ConnectionInfo> connectionInfos) throws ResourceException { for (Iterator<ConnectionInfo> iterator = connectionInfos.iterator(); iterator.hasNext();) { ConnectionInfo connectionInfo = iterator.next(); if (connectionInfo.isUnshareable()) { //if one is, they all are return; } ManagedConnectionInfo managedConnectionInfo = connectionInfo.getManagedConnectionInfo(); ManagedConnection managedConnection = managedConnectionInfo.getManagedConnection(); if (managedConnection instanceof DissociatableManagedConnection && managedConnectionInfo.isFirstConnectionInfo(connectionInfo)) { iterator.remove(); ((DissociatableManagedConnection) managedConnection).dissociateConnections(); managedConnectionInfo.clearConnectionHandles(); //todo this needs some kind of check so cx isn't returned more than once //in case dissociate calls connection closed event and returns cx to pool. returnConnection(connectionInfo, ConnectionReturnAction.RETURN_HANDLE); } } }
private void proxyConnection(ConnectionTrackingInterceptor interceptor, ConnectionInfo connectionInfo) throws ResourceException { // if this connection already has a proxy no need to create another if (connectionInfo.getConnectionProxy() != null) return; // DissociatableManagedConnection do not need to be proxied if (connectionInfo.getManagedConnectionInfo().getManagedConnection() instanceof DissociatableManagedConnection) { return; } try { Object handle = connectionInfo.getConnectionHandle(); ConnectionInvocationHandler invocationHandler = new ConnectionInvocationHandler(handle); Object proxy = Proxy.newProxyInstance(handle.getClass().getClassLoader(), handle.getClass().getInterfaces(), invocationHandler); connectionInfo.setConnectionProxy(proxy); ProxyPhantomReference reference = new ProxyPhantomReference(interceptor, connectionInfo.getManagedConnectionInfo(), invocationHandler, referenceQueue); references.put(connectionInfo.getManagedConnectionInfo(), reference); } catch (Throwable e) { throw new ResourceException("Unable to construct connection proxy", e); } }
private void proxyConnection(ConnectionTrackingInterceptor connectionTrackingInterceptor, ConnectionInfo connectionInfo) throws ResourceException { // if this connection already has a proxy no need to create another if (connectionInfo.getConnectionProxy() != null) return; // DissociatableManagedConnection do not need to be proxied if (connectionInfo.getManagedConnectionInfo().getManagedConnection() instanceof DissociatableManagedConnection) { return; } try { Object handle = connectionInfo.getConnectionHandle(); ConnectionInvocationHandler invocationHandler = new ConnectionInvocationHandler(connectionTrackingInterceptor, connectionInfo, handle); Object proxy = Proxy.newProxyInstance(getClassLoader(handle), handle.getClass().getInterfaces(), invocationHandler); // add it to our map... if the map already has a proxy for this connection, use the existing one Object existingProxy = proxiesByConnectionInfo.putIfAbsent(connectionInfo, proxy); if (existingProxy != null) proxy = existingProxy; connectionInfo.setConnectionProxy(proxy); } catch (Throwable e) { throw new ResourceException("Unable to construct connection proxy", e); } }
public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { next.getConnection(connectionInfo); ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); mci.setXAResource( new LogXAResource( mci.getManagedConnection().getLocalTransaction(), name)); }
public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { next.getConnection(connectionInfo); ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); mci.setXAResource(new WrapperNamedXAResource(mci.getManagedConnection().getXAResource(), name)); }
public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { next.getConnection(connectionInfo); ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); mci.setXAResource( new LocalXAResource(mci.getManagedConnection().getLocalTransaction(), name)); }
if (managedConnectionInfo != null) { ManagedConnectionInfo previousMci = connectionInfo.getManagedConnectionInfo(); if (previousMci != null && previousMci != managedConnectionInfo && previousMci.getManagedConnection() != null) { managedConnectionInfos.setShared(connectionInfo.getManagedConnectionInfo()); if (log.isTraceEnabled()) { log.trace("supplying connection from pool " + connectionInfo.getConnectionHandle() + " for managed connection " + connectionInfo.getManagedConnectionInfo().getManagedConnection() + " to tx caching interceptor " + this);
private void proxyConnection(final ConnectionTrackingInterceptor interceptor, final ConnectionInfo connectionInfo) throws ResourceException { // if this connection already has a proxy no need to create another if (connectionInfo.getConnectionProxy() != null) { return; } // DissociatableManagedConnection do not need to be proxied if (connectionInfo.getManagedConnectionInfo().getManagedConnection() instanceof DissociatableManagedConnection) { return; } try { final Object handle = connectionInfo.getConnectionHandle(); final ConnectionInvocationHandler invocationHandler = new ConnectionInvocationHandler(handle); final Object proxy = newProxy(handle, invocationHandler); connectionInfo.setConnectionProxy(proxy); final ProxyPhantomReference reference = new ProxyPhantomReference(interceptor, connectionInfo.getManagedConnectionInfo(), invocationHandler, referenceQueue); references.put(connectionInfo.getManagedConnectionInfo(), reference); } catch (final Throwable e) { throw new ResourceException("Unable to construct connection proxy", e); } }
/** * in: connectionInfo not null, managedConnectionInfo not null. ManagedConnection may or may not be null. ConnectionHandle may or may not be null * out: managedConnection not null. connection handle not null. managedConnectionInfo has connection handle registered. Connection handle is associated with ManagedConnection. * @param connectionInfo * @throws ResourceException */ public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { next.getConnection(connectionInfo); ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); if (connectionInfo.getConnectionHandle() == null) { connectionInfo.setConnectionHandle( mci.getManagedConnection().getConnection( mci.getSubject(), mci.getConnectionRequestInfo())); mci.addConnectionHandle(connectionInfo); } else if (!mci.hasConnectionInfo(connectionInfo)) { mci.getManagedConnection().associateConnection( connectionInfo.getConnectionHandle()); mci.addConnectionHandle(connectionInfo); } connectionInfo.setTrace(); }
private void proxyConnection(final ConnectionTrackingInterceptor interceptor, final ConnectionInfo connectionInfo) throws ResourceException { // if this connection already has a proxy no need to create another if (connectionInfo.getConnectionProxy() != null) { return; } // DissociatableManagedConnection do not need to be proxied if (connectionInfo.getManagedConnectionInfo().getManagedConnection() instanceof DissociatableManagedConnection) { return; } try { final Object handle = connectionInfo.getConnectionHandle(); final ConnectionInvocationHandler invocationHandler = new ConnectionInvocationHandler(handle); final Object proxy = newProxy(handle, invocationHandler); connectionInfo.setConnectionProxy(proxy); final ProxyPhantomReference reference = new ProxyPhantomReference(interceptor, connectionInfo.getManagedConnectionInfo(), invocationHandler, referenceQueue); references.put(connectionInfo.getManagedConnectionInfo(), reference); } catch (final Throwable e) { throw new ResourceException("Unable to construct connection proxy", e); } }