protected boolean doRemove(ManagedConnectionInfo mci) { return pool.remove(mci.getManagedConnection()) == null; }
/** * 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(); }
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); } } }
public boolean securityMatches(ManagedConnectionInfo other) { return ( subject == null ? other.getSubject() == null : subject.equals(other.getSubject())) && (connectionRequestInfo == null ? other.getConnectionRequestInfo() == null : connectionRequestInfo.equals(other.getConnectionRequestInfo())); }
public FillTask(ConnectionInfo connectionInfo) { managedConnectionFactory = connectionInfo.getManagedConnectionInfo().getManagedConnectionFactory(); subject = connectionInfo.getManagedConnectionInfo().getSubject(); cri = connectionInfo.getManagedConnectionInfo().getConnectionRequestInfo(); }
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; } }
if (originalManagedConnectionInfo.getManagedConnection() == null) { originalManagedConnectionInfo.setSubject(currentSubject); next.getConnection(connectionInfo); } else { Subject oldSubject = originalManagedConnectionInfo.getSubject(); if (currentSubject == null ? oldSubject != null : !currentSubject.equals(oldSubject)) { if (connectionInfo.isUnshareable()) { new ManagedConnectionInfo( originalManagedConnectionInfo.getManagedConnectionFactory(), originalManagedConnectionInfo.getConnectionRequestInfo()); newManagedConnectionInfo.setSubject(currentSubject); connectionInfo.setManagedConnectionInfo(newManagedConnectionInfo); next.getConnection(connectionInfo);
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()); }
public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { next.getConnection(connectionInfo); ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); mci.setXAResource(new WrapperNamedXAResource(mci.getManagedConnection().getXAResource(), name)); }
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) { try { ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); 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"));
Collection<ConnectionInfo> toRemove = mci.getConnectionInfos(); infos.removeAll(toRemove); } else { log.trace("No infos found for handle " + connectionInfo.getConnectionHandle() + " for MCI: " + connectionInfo.getManagedConnectionInfo() + " for MC: " + connectionInfo.getManagedConnectionInfo().getManagedConnection() + " for CTI: " + connectionTrackingInterceptor, new Exception("Stack Trace"));
ManagedConnection mc = mci.getManagedConnection(); try { mc.cleanup(); releasePermit = false; } else if (connectionReturnAction == ConnectionReturnAction.RETURN_HANDLE) { mci.setLastUsed(System.currentTimeMillis()); doAdd(mci); return true;
public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); SubjectCRIKey key = new SubjectCRIKey( useSubject ? mci.getSubject() : null, useCRI ? mci.getConnectionRequestInfo() : null); ConnectionInterceptor poolInterceptor = null; synchronized (pools) { if (destroyed) { throw new ResourceException("ConnectionManaged has been destroyed"); } poolInterceptor = (ConnectionInterceptor) pools.get(key); if (poolInterceptor == null) { poolInterceptor = singlePoolFactory.addPoolingInterceptors(next); pools.put(key, (PoolingAttributes) poolInterceptor); } } poolInterceptor.getConnection(connectionInfo); connectionInfo.getManagedConnectionInfo().setPoolInterceptor(poolInterceptor); }
public void run() { resizeLock.readLock().lock(); try { while (connectionCount < minSize) { ManagedConnectionInfo mci = new ManagedConnectionInfo(managedConnectionFactory, cri); mci.setSubject(subject); ConnectionInfo ci = new ConnectionInfo(mci); try { next.getConnection(ci); } catch (ResourceException e) { return; } boolean added = addToPool(mci); if (!added) { internalReturn(ci, ConnectionReturnAction.DESTROY); return; } } } catch (Throwable t) { log.error("FillTask encountered error in run method", t); } finally { resizeLock.readLock().unlock(); } }
public NamedXAResource getNamedXAResource() throws SystemException { try { ManagedConnectionInfo mci = new ManagedConnectionInfo(managedConnectionFactory, null); ConnectionInfo recoveryConnectionInfo = new ConnectionInfo(mci); recoveryStack.getConnection(recoveryConnectionInfo); // For pooled resources, we may now have a new MCI (not the one constructed above). Make sure we use the correct MCI return new NamedXAResourceWithConnectioninfo((NamedXAResource) recoveryConnectionInfo.getManagedConnectionInfo().getXAResource(), recoveryConnectionInfo); } catch (ResourceException e) { throw (SystemException) new SystemException("Could not get XAResource for recovery for mcf: " + name).initCause(e); } }
protected void getExpiredManagedConnectionInfos(long threshold, List<ManagedConnectionInfo> killList) { synchronized (pool) { for (Iterator<ManagedConnectionInfo> mcis = pool.iterator(); mcis.hasNext(); ) { ManagedConnectionInfo mci = mcis.next(); if (mci.getLastUsed() < threshold) { mcis.remove(); killList.add(mci); connectionCount--; } } } }
/** * in: non-null connection object, from non-null mcf. * connection object is not associated with a managed connection * out: supplied connection object is assiciated with a non-null ManagedConnection from mcf. */ public void associateConnection(Object connection, ManagedConnectionFactory managedConnectionFactory, ConnectionRequestInfo connectionRequestInfo) throws ResourceException { ManagedConnectionInfo mci = new ManagedConnectionInfo(managedConnectionFactory, connectionRequestInfo); ConnectionInfo ci = new ConnectionInfo(mci); ci.setConnectionHandle(connection); getStack().getConnection(ci); }
connectionCount++; if (log.isTraceEnabled()) { log.trace("Supplying new connection MCI: " + connectionInfo.getManagedConnectionInfo() + " MC: " + connectionInfo.getManagedConnectionInfo().getManagedConnection() + " from pool: " + this); connectionInfo.setManagedConnectionInfo(newMCI); if (log.isTraceEnabled()) { log.trace("Supplying pooled connection without checking matching MCI: " + connectionInfo.getManagedConnectionInfo() + " MC: " + connectionInfo.getManagedConnectionInfo().getManagedConnection() + " from pool: " + this); try { ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); matchedMC = newMCI.getManagedConnectionFactory().matchManagedConnections(Collections.singleton(newMCI.getManagedConnection()), mci.getSubject(), mci.getConnectionRequestInfo()); } catch (ResourceException e) {
public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { next.getConnection(connectionInfo); ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); mci.setXAResource( new LogXAResource( mci.getManagedConnection().getLocalTransaction(), name)); }
ManagedConnectionFactory managedConnectionFactory = mci.getManagedConnectionFactory(); ManagedConnection matchedMC = managedConnectionFactory .matchManagedConnections(pool.keySet(), mci.getSubject(), mci.getConnectionRequestInfo()); if (matchedMC != null) { connectionInfo.setManagedConnectionInfo(pool.get(matchedMC));