FileDocCategorySizeDatePackage
ConnectionValidator.javaAPI DocJBoss 4.2.16046Fri Jul 13 21:01:18 BST 2007org.jboss.resource.connectionmanager

ConnectionValidator

public class ConnectionValidator extends Object
A ConnectionValidator that performs background validation of managed connections for an InternalManagedConnectionPool.
author
Weston Price
version
$Revision: 57189 $

Fields Summary
private static final Logger
log
The log
private Collection
pools
The pools
private long
interval
The interval
private long
next
The next
private static final ConnectionValidator
validator
The validator
Constructors Summary
private ConnectionValidator()

   
   
    
      
      AccessController.doPrivileged(new PrivilegedAction()
      {
         public Object run()
         {
            Runnable runnable = new ConnectionValidatorRunnable();
            Thread removerThread = new Thread(runnable, "ConnectionValidator");
            removerThread.setDaemon(true);
            removerThread.start();
            return null;
         }
      });
      
   
Methods Summary
private voidinternalRegisterPool(InternalManagedConnectionPool mcp, long interval)

      
      synchronized (pools)
      {
         pools.add(mcp);
         
         if (interval > 1 && interval/2 < this.interval) 
         {
            this.interval = interval/2;
            long maybeNext = System.currentTimeMillis() + this.interval;
            if (next > maybeNext && maybeNext > 0) 
            {
               next = maybeNext;
               log.debug("internalRegisterPool: about to notify thread: old next: " + next + ", new next: " + maybeNext);
               pools.notify();
            }
         }
      }
      
   
private voidinternalUnregisterPool(InternalManagedConnectionPool mcp)

      
      synchronized (pools)
      {
         pools.remove(mcp);
         if (pools.size() == 0) 
         {
            log.debug("internalUnregisterPool: setting interval to Long.MAX_VALUE");
            interval = Long.MAX_VALUE;
         }
      
      }
      
   
public static voidregisterPool(InternalManagedConnectionPool mcp, long interval)

      validator.internalRegisterPool(mcp, interval);
      
      
   
private voidsetupContextClassLoader()

      // Could be null if loaded from system classloader
      final ClassLoader cl = IdleRemover.class.getClassLoader();
      if (cl == null)
         return;
      
      SecurityManager sm = System.getSecurityManager();
      if (sm == null)
         Thread.currentThread().setContextClassLoader(cl);
      
      AccessController.doPrivileged(new PrivilegedAction()
      {
         public Object run()
         {
            Thread.currentThread().setContextClassLoader(cl);
            return null;
         }
      });
   
public static voidunRegisterPool(InternalManagedConnectionPool mcp)

      validator.internalUnregisterPool(mcp);
      
   
public static voidwaitForBackgroundThread()

      synchronized (validator.pools)
      {
         return;
      }