/** * in: mcf != null, is a deployed mcf * out: useable connection object. */ public Object allocateConnection(ManagedConnectionFactory managedConnectionFactory, ConnectionRequestInfo connectionRequestInfo) throws ResourceException { ManagedConnectionInfo mci = new ManagedConnectionInfo(managedConnectionFactory, connectionRequestInfo); ConnectionInfo ci = new ConnectionInfo(mci); getStack().getConnection(ci); Object connection = ci.getConnectionProxy(); if (connection == null) { connection = ci.getConnectionHandle(); } else { // connection proxy is used only once so we can be notified // by the garbage collector when a connection is abandoned ci.setConnectionProxy(null); } return connection; }
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); } }
public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) { if (connectionReturnAction == ConnectionReturnAction.DESTROY || connectionInfo.isUnshareable() || !connectionInfo.getManagedConnectionInfo().hasConnectionHandles()) { if (connections.get() == connectionInfo.getManagedConnectionInfo()) { connections.remove(); } next.returnConnection(connectionInfo, connectionReturnAction); } }
private void returnHandle(ManagedConnectionInfo managedConnectionInfo) { ConnectionInfo connectionInfo = new ConnectionInfo(); connectionInfo.setManagedConnectionInfo(managedConnectionInfo); internalReturn(connectionInfo, ConnectionReturnAction.RETURN_HANDLE); }
public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { Subject currentSubject = null; if (!connectionInfo.isApplicationManagedSecurity()) { try { currentSubject = subjectSource.getSubject(); ManagedConnectionInfo originalManagedConnectionInfo = connectionInfo.getManagedConnectionInfo(); Subject oldSubject = originalManagedConnectionInfo.getSubject(); if (currentSubject == null ? oldSubject != null : !currentSubject.equals(oldSubject)) { if (connectionInfo.isUnshareable()) { throw new ApplicationServerInternalException("Unshareable resource is attempting to change security context: expected request under: " + oldSubject + ", received request under: " + currentSubject); } else { ConnectionInfo returningConnectionInfo = new ConnectionInfo(); returningConnectionInfo.setManagedConnectionInfo(originalManagedConnectionInfo); returningConnectionInfo.setConnectionHandle(connectionInfo.getConnectionHandle()); originalManagedConnectionInfo.getConnectionRequestInfo()); newManagedConnectionInfo.setSubject(currentSubject); connectionInfo.setManagedConnectionInfo(newManagedConnectionInfo); next.getConnection(connectionInfo);
public FillTask(ConnectionInfo connectionInfo) { managedConnectionFactory = connectionInfo.getManagedConnectionInfo().getManagedConnectionFactory(); subject = connectionInfo.getManagedConnectionInfo().getSubject(); cri = connectionInfo.getManagedConnectionInfo().getConnectionRequestInfo(); }
/** * in: connectionInfo not null, managedConnectionInfo not null, managedConnection not null. Handle can be null if mc is being destroyed from pool. * out: managedCOnnectionInfo null, handle not in mci.handles. * @param connectionInfo * @param connectionReturnAction */ public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) { if (connectionInfo.getConnectionHandle() != null) { connectionInfo.getManagedConnectionInfo().removeConnectionHandle( connectionInfo); } next.returnConnection(connectionInfo, connectionReturnAction); }
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); ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); matchedMC = newMCI.getManagedConnectionFactory().matchManagedConnections(Collections.singleton(newMCI.getManagedConnection()), mci.getSubject(), } catch (ResourceException e) { ConnectionInfo returnCI = new ConnectionInfo(); returnCI.setManagedConnectionInfo(newMCI); returnConnection(returnCI, ConnectionReturnAction.DESTROY); throw e; connectionInfo.setManagedConnectionInfo(newMCI); if (log.isTraceEnabled()) { log.trace("Supplying pooled connection MCI: " + connectionInfo.getManagedConnectionInfo() + " from pool: " + this); ConnectionInfo returnCI = new ConnectionInfo(); returnCI.setManagedConnectionInfo(newMCI); returnConnection(returnCI, ConnectionReturnAction.RETURN_HANDLE); throw new ResourceException("The pooling strategy does not match the MatchManagedConnections implementation. Please investigate and reconfigure this pool");
protected void transferConnections(int maxSize, int shrinkNow) { for (int i = 0; i < shrinkNow; i++) { ConnectionInfo killInfo = new ConnectionInfo(pool.get(0)); internalReturn(killInfo, ConnectionReturnAction.DESTROY); } }
/** * 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(); }
if (transaction != null) { ManagedConnectionInfos managedConnectionInfos = ConnectorTransactionContext.get(transaction, this); if (connectionInfo.isUnshareable()) { if (!managedConnectionInfos.containsUnshared(connectionInfo.getManagedConnectionInfo())) { next.getConnection(connectionInfo); managedConnectionInfos.addUnshared(connectionInfo.getManagedConnectionInfo()); if (log.isTraceEnabled()) { log.trace("Enlisting connection already associated with handle " + infoString(connectionInfo)); ManagedConnectionInfo managedConnectionInfo = managedConnectionInfos.getShared(); if (managedConnectionInfo != null) { ManagedConnectionInfo previousMci = connectionInfo.getManagedConnectionInfo(); if (previousMci != null && previousMci != managedConnectionInfo && previousMci.getManagedConnection() != null) { connectionInfo.setManagedConnectionInfo(managedConnectionInfo); 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);
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); } }
/** * 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); }
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 addConnectionInfo(ConnectionInfo connectionInfo) { assert connectionInfo.getConnectionHandle() != null; connectionInfos.add(connectionInfo); }
private ConnectionInvocationHandler getConnectionInvocationHandler(ConnectionInfo connectionInfo) { Object proxy = connectionInfo.getConnectionProxy(); if (proxy == null) { proxy = proxiesByConnectionInfo.get(connectionInfo); } // no proxy or proxy already destroyed if (proxy == null) return null; if (Proxy.isProxyClass(proxy.getClass())) { InvocationHandler invocationHandler = Proxy.getInvocationHandler(proxy); if (invocationHandler instanceof ConnectionInvocationHandler) { return (ConnectionInvocationHandler) invocationHandler; } } return null; }
private void closeProxyConnection(ConnectionInfo connectionInfo) { ConnectionInvocationHandler invocationHandler = getConnectionInvocationHandler(connectionInfo); if (invocationHandler != null) { invocationHandler.close(); proxiesByConnectionInfo.remove(connectionInfo); connectionInfo.setConnectionProxy(null); } }
/** * Removes the released collection from the garbage collection reference tracker, since this * connection is being release via a normal close method. * * @param interceptor ignored * @param connectionInfo the connection that was released * @param action ignored */ public void handleReleased(final ConnectionTrackingInterceptor interceptor, final ConnectionInfo connectionInfo, final ConnectionReturnAction action) { final PhantomReference phantomReference = references.remove(connectionInfo.getManagedConnectionInfo()); if (phantomReference != null) { phantomReference.clear(); } }
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) { 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"));
ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); ManagedConnectionFactory managedConnectionFactory = mci.getManagedConnectionFactory(); ManagedConnection matchedMC = mci.getConnectionRequestInfo()); if (matchedMC != null) { connectionInfo.setManagedConnectionInfo(pool.get(matchedMC)); pool.remove(matchedMC); if (log.isTraceEnabled()) { ManagedConnectionInfo kill = (ManagedConnectionInfo) ((Map.Entry) iterator.next()).getValue(); iterator.remove(); ConnectionInfo killInfo = new ConnectionInfo(kill); internalReturn(killInfo, ConnectionReturnAction.DESTROY);