Package nexj.core.util

Examples of nexj.core.util.HolderDeque


         new ConnectionKey(factory, (cri instanceof GenericConnectionRequestInfo) ?
         ((GenericConnectionRequestInfo)cri).getManagedConnectionPartition() : NULL_KEY),
         true); // assume connection pooling supported by factory
      Subject subject = getSubject();
      boolean bTxAssociated = false; // the connection is not associated with Tx
      HolderDeque deque = null;

      try
      {
         synchronized (this) // reserve one of the created connections
         {
            if (isTxAssociated(factory)) //if track by Tx check with connections used by current Tx
            {
               deque = (HolderDeque)m_txMap.get(assoc);

               if (deque != null) // connections in-use by TX
               {
                  try
                  {
                     connection = factory.matchManagedConnections(deque, subject, cri);
                  }
                  catch (NotSupportedException e)
                  {
                     assoc.m_bPool = false; // connection pooling not supported
                  }

                  if (connection != null) // reuse connection association from previous allocation
                  {
                     bTxAssociated = true; // assoc.m_handleSet can be empty if handles closed
                     assoc = (ConnectionAssoc)m_connectionMap.get(connection);//get full handle set
                  }
               }
            }

            if (connection == null && assoc.m_bPool) //no connection and pooling possibly supported
            {
               deque = (HolderDeque)m_poolMap.get(assoc.m_key);

               if (deque != null) // unallocated connections available in pool
               {
                  try
                  {
                     connection = factory.matchManagedConnections(deque, subject, cri);
                  }
                  catch (NotSupportedException e)
                  {
                     assoc.m_bPool = false; // connection pooling not supported
                  }

                  if (connection != null)
                  {
                     deque.remove(connection);
                  }
               }
            }
         }

         if (connection == null)
         {
            connection = factory.createManagedConnection(subject, cri); // new connection
            connection.addConnectionEventListener(this);
         }

         if (txn != null && !bTxAssociated) // do not re-enlist same connection
         {
            enlist(connection, txn);
         }

         try // get handle and if error then retry if this is a stale connection from pool
         {
            handle = connection.getConnection(subject, cri);
         }
         catch (ResourceException e)
         {
            destroyConnection(connection);

            if (deque == null || !assoc.m_bPool)
            {
               throw e; // new connection has error
            }

            return allocateConnection(factory, cri); // loop/retry
         }

         synchronized (this)
         {
            assoc.m_handleSet.add(handle);
            m_connectionMap.put(connection, assoc);

            if (!bTxAssociated) // If this is the first handle for this connection
            {
               deque = (HolderDeque)m_txMap.get(assoc); // get the Tx-specific deque

               if (deque == null)
               {
                  deque = new HashDeque();
                  m_txMap.put(assoc, deque);
               }

               deque.addFirst(connection); // add to deque tracking connections per transaction
            }
         }

         if (s_logger.isDebugEnabled())
         {
View Full Code Here


      synchronized (this)
      {
         ConnectionAssoc assoc = (ConnectionAssoc)m_connectionMap.remove(connection);
         assert assoc != null;

         HolderDeque deque = (HolderDeque)m_txMap.get(assoc);

         assert deque != null;
         deque.remove(connection);
         key = (assoc.m_bPool) ? assoc.m_key : null;

         if (deque.isEmpty())
         {
            m_txMap.remove(assoc); // remove empty Tx->deque association
         }
      }

      try
      {
         delist(connection); // delist just in case called from clear()
      }
      catch (Throwable e)
      {
         s_logger.error("Unable to delist connection " + connection, e);
         key = null;
      }

      if (key != null)
      {
         if (s_logger.isDebugEnabled())
         {
            s_logger.debug("Deactivating connection " + connection);
         }

         try
         {
            connection.cleanup();
         }
         catch (Throwable e)
         {
            s_logger.error("Unable to cleanup connection " + connection, e);
            key = null;
         }
      }

      /*
       * Destroy the managed connection to release resources if:
       * 1) RA does not support pooling (see assoc.m_bPool in allocateConnection)
       * 2) There was an error cleaning up the connection (above)
       */
      if (key == null)
      {
         destroyConnection(connection);
      }
      else
      {
         synchronized (this)
         {
            HolderDeque deque = (HolderDeque)m_poolMap.get(key);

            if (deque == null)
            {
               deque = new HashDeque();
               m_poolMap.put(key, deque);
            }

            deque.addFirst(connection);
         }
      }
   }
View Full Code Here

         if (assoc == null) // not one of the in-use connections or just got a failure on connection
         {
            // search for the connection in the free connection pool
            for (Lookup.Iterator/*<HolderDeque>*/ itr = m_poolMap.valueIterator(); itr.hasNext();)
            {
               HolderDeque deque = (HolderDeque)itr.next();

               deque.remove(connection);

               if (deque.isEmpty())
               {
                  m_poolMap.remove(itr.getKey()); // remove empty ConnectionKey->deque association
               }
            }
         }
         else // a ConnectionAssoc has all the information required to remove connection from pools
         {
            HolderDeque deque = (HolderDeque)m_txMap.get(assoc);

            if (deque != null) // can be null because removed by destroy()
            {
               deque.remove(connection); // remove connection from Tx Map

               if (deque.isEmpty())
               {
                  m_txMap.remove(assoc); // remove empty Tx->deque association
               }
            }

            if (assoc.m_bPool)
            {
               deque = (HolderDeque)m_poolMap.get(assoc.m_key);

               if (deque != null)
               {
                  deque.remove(connection);
               }
            }
         }
      }

View Full Code Here

    * @param handler The mixin handler.
    * @throws MetadataException if a mixin's .metadata file fails to parse.
    */
   public static void forEachReferencedMixin(Element rootElement, URL baseMetaFolderURL, MixinNamespaceHandler handler)
   {
      final HolderDeque mixinSet = new HashDeque(4);
      XMLUtil.ElementHandler mixinElementHandler = new XMLUtil.ElementHandler()
      {
         public void handleElement(Element element)
         {
            mixinSet.add(new Pair(XMLUtil.getStringAttr(element, "namespace", ""), new Pair(XMLUtil.getStringAttr(element,
               "version", ""), XMLUtil.getStringAttr(element, "checksum", ""))));
         }
      };

      forEachMixin(baseMetaFolderURL, mixinElementHandler);
      forEachMixin(rootElement, mixinElementHandler);

      Holder registeredList = new HashHolder(mixinSet.size());

      while (!mixinSet.isEmpty())
      {
         Pair p = (Pair)mixinSet.removeFirst();

         if (registeredList.add(p))
         {
            String sNamespace = (String)p.getHead();

View Full Code Here

TOP

Related Classes of nexj.core.util.HolderDeque

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.