Java源码示例:javax.resource.spi.DissociatableManagedConnection

示例1
private void proxyConnection(final ConnectionTrackingInterceptor interceptor, final ConnectionInfo connectionInfo) throws ResourceException {
    // no-op if we have opted to not use proxies
    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);
    }
}
 
示例2
/**
 * Detach connection listener
 * @return The outcome
 */
private boolean detachConnectionListener()
{
   synchronized (cls)
   {
      ConnectionListener cl = null;
      try
      {
         Iterator<ConnectionListener> it = checkedOut.iterator();
         while (it.hasNext())
         {
            cl = it.next();
            if (!cl.isEnlisted() && cl.getManagedConnection() instanceof DissociatableManagedConnection)
            {
               log.tracef("Detach: %s", cl);

               DissociatableManagedConnection dmc = (DissociatableManagedConnection)cl.getManagedConnection();
               dmc.dissociateConnections();

               cl.unregisterConnections();

               if (Tracer.isEnabled())
                  Tracer.returnConnectionListener(pool.getName(), this, cl, false, pool.isInterleaving(),
                                                  Tracer.isRecordCallstacks() ?
                                                  new Throwable("CALLSTACK") : null);

               returnConnection(cl, false, false);

               return true;
            }
         }
      }
      catch (Throwable t)
      {
         // Ok - didn't work; nuke it and disable
         if (debug)
            log.debug("Exception during detach for: " + pool.getName(), t);

         supportsLazyAssociation = Boolean.FALSE;

         if (cl != null)
         {
            if (Tracer.isEnabled())
               Tracer.returnConnectionListener(pool.getName(), this, cl, true, pool.isInterleaving(),
                                               Tracer.isRecordCallstacks() ?
                                               new Throwable("CALLSTACK") : null);

            returnConnection(cl, true, true);
         }
      }
   }

   return false;
}
 
示例3
/**
 * Detach connection listener
 * 
 * @return The outcome
 */
private boolean detachConnectionListener() 
{
   synchronized (cls) 
   {
      ConnectionListener cl = null;
      try 
      {
         for (Entry<ConnectionListener, ConnectionListenerWrapper> entry : cls.entrySet()) 
         {
            cl = entry.getKey();
            
            if (entry.getValue().isCheckedOut()) 
            {
               if (!cl.isEnlisted() && cl.getManagedConnection() instanceof DissociatableManagedConnection) 
               {
                  log.tracef("Detach: %s", cl);

                  DissociatableManagedConnection dmc = (DissociatableManagedConnection) cl.getManagedConnection();
                  dmc.dissociateConnections();

                  cl.unregisterConnections();

                  if (Tracer.isEnabled())
                     Tracer.returnConnectionListener(pool.getName(), this, cl, false, pool.isInterleaving(),
                                                     Tracer.isRecordCallstacks() ?
                                                     new Throwable("CALLSTACK") : null);

                  returnConnection(cl, false, false);

                  return true;
               }
            }
         }
      } 
      catch (Throwable t) 
      {
         // Ok - didn't work; nuke it and disable
         if (debug)
            log.debug("Exception during detach for: " + pool.getName(),
                  t);

         supportsLazyAssociation = Boolean.FALSE;

         if (cl != null) 
         {
            if (Tracer.isEnabled())
               Tracer.returnConnectionListener(pool.getName(), this, cl, true, pool.isInterleaving(),
                                               Tracer.isRecordCallstacks() ?
                                               new Throwable("CALLSTACK") : null);

            returnConnection(cl, true, true);
         }
      }
   }

   return false;
}