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

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


   public ConnectionListener getConnection(Subject subject, ConnectionRequestInfo cri) throws ResourceException
   {
      subject = (subject == null) ? defaultSubject : subject;
      cri = (cri == null) ? defaultCri : cri;

      ConnectionListener cl = null;
      boolean verifyConnectionListener = true;

      long startWait = System.currentTimeMillis();
      if (getAvailableConnections() > 0)
      {
         if (shutdown.get())
            throw new RetryableUnavailableException("The pool has been shutdown");
        
         cl = cls.peek();
         if (cl != null)
         {
            try
            {
               cl = cls.poll(poolConfiguration.getBlockingTimeout(), TimeUnit.MILLISECONDS);
            }
            catch (InterruptedException ie)
            {
               long end = System.currentTimeMillis() - startWait;
               throw new ResourceException("Interrupted while requesting connection! Waited " + end + " ms");
            }
         }
         else
         {
            try
            {
               // No, the pool was empty, so we have to make a new one.
               cl = createConnectionEventListener(subject, cri);

               // Started is atomic, so pool filler won't be scheduled twice
               if (!started.getAndSet(true))
               {
                  if (poolConfiguration.getMinSize() > 0)
                     PoolFiller.fillPool(this);
               }
              
               if (trace)
                  log.trace("supplying new ManagedConnection: " + cl);
              
               verifyConnectionListener = false;
            }
            catch (Throwable t)
            {
               log.warn("Throwable while attempting to get a new connection: " + cl, t);

               JBossResourceException.rethrowAsResourceException("Unexpected throwable while trying " +
                                                                 "to create a connection: " + cl, t);
            }
         }
      }
      else
      {
         try
         {
            cl = cls.poll(poolConfiguration.getBlockingTimeout(), TimeUnit.MILLISECONDS);

            if (shutdown.get())
               throw new RetryableUnavailableException("The pool has been shutdown");
         }
         catch (InterruptedException ie)
         {
            if (!poolConfiguration.isUseFastFail())
            {
               throw new ResourceException("No ManagedConnections available within configured blocking timeout ( "
                                           + poolConfiguration.getBlockingTimeout() + " [ms] )");
            }
            else
            {
               if (trace)
                  log.trace("Fast failing for connection attempt. No more attempts will be made to " +
                            "acquire connection from pool and a new connection will be created immeadiately");

               try
               {
                  cl = createConnectionEventListener(subject, cri);
              
                  // Started is atomic, so pool filler won't be scheduled twice
                  if (!started.getAndSet(true))
                  {
                     if (poolConfiguration.getMinSize() > 0)
                        PoolFiller.fillPool(this);
                  }
              
                  if (trace)
                     log.trace("supplying new ManagedConnection: " + cl);
              
                  verifyConnectionListener = false;
               }
               catch (Throwable t)
               {
                  log.warn("Throwable while attempting to get a new connection: " + cl, t);

                  JBossResourceException.rethrowAsResourceException("Unexpected throwable while trying to " +
                                                                    "create a connection: " + cl, t);
               }
            }
         }
      }

      // Register the connection listener
      checkedOut.add(cl);

      // Update max used connections
      int size = maxSize - permits.size();
      if (size > maxUsedConnections.get())
         maxUsedConnections.set(size);
     
      if (!verifyConnectionListener)
      {
         // Register the connection listener with permits
         permits.put(cl, cl);

         // Return connection listener
         return cl;
      }
      else
      {
         try
         {
            Object matchedMC =
               mcf.matchManagedConnections(Collections.singleton(cl.getManagedConnection()), subject, cri);

            if (matchedMC != null)
            {
               if (trace)
                  log.trace("supplying ManagedConnection from pool: " + cl);
View Full Code Here


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

      // Mark checked out connections as requiring destruction
      for (Iterator<ConnectionListener> i = checkedOut.iterator(); i.hasNext();)
      {
         ConnectionListener cl = i.next();

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

         cl.setState(ConnectionState.DESTROY);
      }

      // Destroy connections in the pool
      ConnectionListener cl = cls.poll();
      while (cl != null)
      {
         if (destroy == null)
            destroy = new ArrayList<ConnectionListener>();

         destroy.add(cl);
         cl = cls.poll();
      }

      // We need to destroy some connections
      if (destroy != null)
      {
         for (int i = 0; i < destroy.size(); ++i)
         {
            ConnectionListener l = destroy.get(i);
            if (trace)
               log.trace("Destroying flushed connection " + l);

            doDestroy(l);
         }
View Full Code Here

     
      boolean cont = true;
      while (cont)
      {
         // Check the first in the list
         ConnectionListener cl = cls.peek();
         if (cl != null && cl.isTimedOut(timeout) && shouldRemove())
         {
            // We need to destroy this one
            if (destroy == null)
               destroy = new ArrayList<ConnectionListener>(1);

            cl = cls.poll();

            if (cl != null)
            {
               destroy.add(cl);
            }
            else
            {
               // The connection list were empty
               cont = false;
            }
         }
         else
         {
            // They were inserted chronologically, so if this one
            // isn't timed out, following ones won't be either.
            cont = false;
         }
      }

      // We found some connections to destroy
      if (destroy != null)
      {
         for (int i = 0; i < destroy.size(); ++i)
         {
            ConnectionListener cl = destroy.get(i);

            if (trace)
               log.trace("Destroying timedout connection " + cl);

            doDestroy(cl);
View Full Code Here

      {
         if (shutdown.get())
            return;

         // Create a connection to fill the pool
         ConnectionListener cl = null;
         boolean destroy = false;
         try
         {
            cl = createConnectionEventListener(defaultSubject, defaultCri);
              
View Full Code Here

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

            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);
                        destroyed = true;
                        anyDestroyed = true;
                     }
View Full Code Here

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

      ConnectionListener result = null;
      Iterator<ConnectionListener> iter = cls.iterator();

      while (result == null && iter.hasNext())
      {
         ConnectionListener cl = iter.next();
         long lastCheck = cl.getLastValidatedTime();

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

      try
      {
         if (permits.tryAcquire(poolConfiguration.getBlockingTimeout(), TimeUnit.MILLISECONDS))
         {
            //We have a permit to get a connection. Is there one in the pool already?
            ConnectionListener cl = null;
            do
            {
               synchronized (cls)
               {
                  if (shutdown.get())
                  {
                     permits.release();
                     throw new RetryableUnavailableException("The pool has been shutdown");
                  }

                  int clsSize = cls.size();
                  if (clsSize > 0)
                  {
                     cl = cls.remove(clsSize - 1);
                     checkedOut.add(cl);
                     int size = maxSize - permits.availablePermits();
                     if (size > maxUsedConnections)
                        maxUsedConnections = size;
                  }
               }
               if (cl != null)
               {
                  //Yes, we retrieved a ManagedConnection from the pool. Does it match?
                  try
                  {
                     Object matchedMC = mcf.matchManagedConnections(Collections.singleton(cl.getManagedConnection()),
                                                                    subject, cri);

                     if (matchedMC != null)
                     {
                        if (trace)
View Full Code Here

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

         // Mark checked out connections as requiring destruction
         for (Iterator<ConnectionListener> i = checkedOut.iterator(); i.hasNext();)
         {
            ConnectionListener cl = i.next();

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

            cl.setState(ConnectionState.DESTROY);
         }

         // 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);
         }
      }

      // We need to destroy some connections
      if (destroy != null)
      {
         for (int i = 0; i < destroy.size(); ++i)
         {
            ConnectionListener cl = destroy.get(i);

            if (trace)
               log.trace("Destroying flushed connection " + cl);

            doDestroy(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())
            {
               // We need to destroy this one
               cls.remove(0);

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

               destroy.add(cl);
            }
            else
            {
               // They were inserted chronologically, so if this one isn't timed out, following ones won't be either.
               break;
            }
         }
      }

      // We found some connections to destroy
      if (destroy != null)
      {
         for (int i = 0; i < destroy.size(); ++i)
         {
            ConnectionListener cl = destroy.get(i);

            if (trace)
               log.trace("Destroying timedout connection " + cl);

            doDestroy(cl);
View Full Code Here

                     return;

                  // 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

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.