Package org.jboss.jca.core.connectionmanager.listener

Examples of org.jboss.jca.core.connectionmanager.listener.ConnectionListener


      if (cl.getState() == ConnectionState.DESTROYED)
      {
         if (trace)
            log.trace("ManagedConnection is being returned after it was destroyed: " + cl);

         ConnectionListener present = clPermits.remove(cl);
         if (present != null)
         {
            permits.release();
         }

         return;
      }

      try
      {
         cl.getManagedConnection().cleanup();
      }
      catch (ResourceException re)
      {
         log.resourceExceptionCleaningUpManagedConnection(cl, re);
         kill = true;
      }

      // We need to destroy this one
      if (cl.getState() == ConnectionState.DESTROY || cl.getState() == ConnectionState.DESTROYED)
         kill = true;

      // This is really an error
      if (!kill && isSize(poolConfiguration.getMaxSize() + 1))
      {
         log.destroyingReturnedConnectionMaximumPoolSizeExceeded(cl);
         kill = true;
      }

      synchronized (cls)
      {
         checkedOut.remove(cl);

         // If we are destroying, check the connection is not in the pool
         if (kill)
         {
            // Adrian Brock: A resource adapter can asynchronously notify us that
            // a connection error occurred.
            // This could happen while the connection is not checked out.
            // e.g. JMS can do this via an ExceptionListener on the connection.
            // I have twice had to reinstate this line of code, PLEASE DO NOT REMOVE IT!
            cls.remove(cl);
         }
         // return to the pool
         else
         {
            cl.used();
            if (!cls.contains(cl))
            {
               cls.add(cl);
            }
            else
            {
               log.attemptReturnConnectionTwice(cl, new Throwable("STACKTRACE"));
            }
         }

         ConnectionListener present = clPermits.remove(cl);
         if (present != null)
         {
            permits.release();
         }
      }
View Full Code Here


               log.trace("Flushing pool checkedOut=" + checkedOut + " inPool=" + cls);

            // Mark checked out connections as requiring destruction
            while (checkedOut.size() > 0)
            {
               ConnectionListener cl = checkedOut.remove(0);

               if (trace)
                  log.trace("Flush marking checked out connection for destruction " + cl);

               cl.setState(ConnectionState.DESTROY);

               if (destroy == null)
                  destroy = new ArrayList<ConnectionListener>(1);

               destroy.add(cl);

               ConnectionListener present = clPermits.remove(cl);
               if (present != null)
               {
                  permits.release();
               }
            }

            if (statistics.isEnabled())
               statistics.setInUsedCount(checkedOut.size());
         }

         // Destroy connections in the pool
         while (cls.size() > 0)
         {
            ConnectionListener cl = cls.remove(0);

            if (destroy == null)
               destroy = new ArrayList<ConnectionListener>(1);

            destroy.add(cl);
View Full Code Here

            // Nothing left to destroy
            if (cls.size() == 0)
               break;

            // Check the first in the list
            ConnectionListener cl = cls.get(0);
            if (cl.isTimedOut(timeout) && shouldRemove())
            {
               if (statistics.isEnabled())
                  statistics.deltaTimedOut();

               // We need to destroy this one
View Full Code Here

                  }

                  // Create a connection to fill the pool
                  try
                  {
                     ConnectionListener cl = createConnectionEventListener(defaultSubject, defaultCri);

                     synchronized (cls)
                     {
                        if (trace)
                           log.trace("Filling pool cl=" + cl);
View Full Code Here

         try
         {
            while (true)
            {
               ConnectionListener cl = null;
               boolean destroyed = false;

               synchronized (cls)
               {
                  if (cls.size() == 0)
                  {
                     break;
                  }

                  cl = removeForFrequencyCheck();
               }

               if (cl == null)
               {
                  break;
               }

               try
               {
                  Set candidateSet = Collections.singleton(cl.getManagedConnection());

                  if (mcf instanceof ValidatingManagedConnectionFactory)
                  {
                     ValidatingManagedConnectionFactory vcf = (ValidatingManagedConnectionFactory) mcf;
                     candidateSet = vcf.getInvalidConnections(candidateSet);

                     if (candidateSet != null && candidateSet.size() > 0)
                     {
                        if (cl.getState() != ConnectionState.DESTROY)
                        {
                           doDestroy(cl);
                           cl = null;
                           destroyed = true;
                           anyDestroyed = true;
View Full Code Here

    */
   private ConnectionListener removeForFrequencyCheck()
   {
      log.debug("Checking for connection within frequency");

      ConnectionListener cl = null;

      for (Iterator<ConnectionListener> iter = cls.iterator(); iter.hasNext();)
      {
         cl = iter.next();
         long lastCheck = cl.getLastValidatedTime();

         if ((System.currentTimeMillis() - lastCheck) >= poolConfiguration.getBackgroundValidationMillis())
         {
            cls.remove(cl);
            break;
View Full Code Here

    * {@inheritDoc}
    */  
   public ConnectionListener getConnection(Transaction trackByTransaction, Subject subject, ConnectionRequestInfo cri)
      throws ResourceException
   {
      ConnectionListener cl = null;
     
      boolean separateNoTx = false;
     
      if (noTxSeparatePools)
      {
View Full Code Here

    */
   private ConnectionListener getSimpleConnection(final Subject subject, final ConnectionRequestInfo cri,
         final SubPoolContext subPoolContext)
      throws ResourceException
   {
      ConnectionListener cl = null;
      ManagedConnectionPool imcp = null;
     
      try
     
         //Find internal managed pool
View Full Code Here

    * @throws ResourceException
    */
   private ConnectionListener getTransactionOldConnection(TransactionLocal trackByTx, Transaction trackByTransaction)
      throws ResourceException
   {
      ConnectionListener cl = null;
     
      // Track by transaction
      try
      {
         trackByTx.lock(trackByTransaction);
View Full Code Here

    */
   private ConnectionListener getTransactionNewConnection(TransactionLocal trackByTx, Transaction trackByTransaction,
         ManagedConnectionPool mcp, Subject subject, ConnectionRequestInfo cri)
      throws ResourceException
   {
      ConnectionListener cl = null;
     
      // Need a new one for this transaction
      // This must be done outside the tx local lock, otherwise
      // the tx timeout won't work and get connection can do a lot of other work
      // with many opportunities for deadlocks.
      // Instead we do a double check after we got the transaction to see
      // whether another thread beat us to the punch.
      cl = mcp.getConnection(subject, cri);
      if (trace)
      {
         dump("Got connection from pool tracked by transaction " + cl + " tx=" + trackByTransaction)
      }
     
      // Relock and check/set status
      try
      {
         trackByTx.lock(trackByTransaction);
      }
      catch (Throwable t)
      {
         mcp.returnConnection(cl, false);
         if (trace)
         {
            dump("Had to return connection tracked by transaction " + cl + " tx=" +
                  trackByTransaction + " error=" + t.getMessage())
         }
        
         JBossResourceException.rethrowAsResourceException("Unable to get connection from the pool for tx="
               + trackByTransaction, t);
      }
      try
      {
         // Check we weren't racing with another transaction
         ConnectionListener other = (ConnectionListener) trackByTx.get(trackByTransaction);
         if (other != null)
         {
            mcp.returnConnection(cl, false);
            if (trace)
            {
View Full Code Here

TOP

Related Classes of org.jboss.jca.core.connectionmanager.listener.ConnectionListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.