[jboss-cvs] system2/src/main/org/jboss/deployers/plugins/scanner ...

Scott Stark scott.stark at jboss.com
Sat Jul 15 01:37:56 EDT 2006


  User: starksm 
  Date: 06/07/15 01:37:56

  Modified:    src/main/org/jboss/deployers/plugins/scanner 
                        VFSDeploymentScannerImpl.java
  Log:
  Add scanCount
  
  Revision  Changes    Path
  1.2       +133 -40   system2/src/main/org/jboss/deployers/plugins/scanner/VFSDeploymentScannerImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: VFSDeploymentScannerImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/system2/src/main/org/jboss/deployers/plugins/scanner/VFSDeploymentScannerImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- VFSDeploymentScannerImpl.java	14 Jul 2006 02:32:32 -0000	1.1
  +++ VFSDeploymentScannerImpl.java	15 Jul 2006 05:37:56 -0000	1.2
  @@ -34,6 +34,11 @@
   import java.util.List;
   import java.util.Map;
   import java.util.StringTokenizer;
  +import java.util.concurrent.Executors;
  +import java.util.concurrent.ScheduledExecutorService;
  +import java.util.concurrent.ScheduledFuture;
  +import java.util.concurrent.ThreadFactory;
  +import java.util.concurrent.TimeUnit;
   
   import org.jboss.deployers.spi.Deployment;
   import org.jboss.deployers.spi.MainDeployer;
  @@ -57,14 +62,17 @@
    */
   public class VFSDeploymentScannerImpl
      extends JBossObject
  -   implements VFSDeploymentScanner
  +   implements VFSDeploymentScanner, Runnable
   {
      // Private Data --------------------------------------------------
      private MainDeployer mainDeployer;
      /** The VFSFactory used to obtain deployment VFS */
      private VFSFactory factory;
  -
  +   /** */
      private VirtualFileFilter filter;
  +   /** The ExecutorService/ThreadPool for performing scans */
  +   private ScheduledExecutorService scanExecutor;
  +   private ScheduledFuture activeScan;
   
      /** The URIfied ServerHomeURL */
      private URI serverHomeURI;
  @@ -77,6 +85,9 @@
      
      /** Whether to search for files inside directories whose names containing no dots */
      private boolean doRecursiveSearch = true;
  +   /** Period in ms between deployment scans */
  +   private long scanPeriod = 5000;
  +   private int scanCount;
      
      /** A set of scanned VirtualFiles which have been deployed */
      private Map<VirtualFile, Deployment> deployedMap = Collections.synchronizedMap(new HashMap());
  @@ -96,7 +107,6 @@
      public void setMainDeployer(MainDeployer deployer)
      {
         this.mainDeployer = deployer;
  -      this.factory = mainDeployer.getVFSFactory();
      }
   
      /**
  @@ -124,40 +134,69 @@
         this.factory = factory;
      }
   
  -   /* (non-Javadoc)
  -    * @see org.jboss.deployment.scanner.VFSDeploymentScanner#getScanPeriod()
  +   /**
  +    * @return Returns the scanExecutor.
       */
  -   public long getScanPeriod()
  +   public ScheduledExecutorService getScanExecutor()
      {
  -      // TODO Auto-generated method stub
  -      return 0;
  +      return this.scanExecutor;
      }
   
  -   /* (non-Javadoc)
  -    * @see org.jboss.deployment.scanner.VFSDeploymentScanner#isScanEnabled()
  +   /**
  +    * @param scanExecutor The scanExecutor to set.
       */
  -   public boolean isScanEnabled()
  +   public void setScanExecutor(ScheduledExecutorService scanExecutor)
      {
  -      // TODO Auto-generated method stub
  -      return false;
  +      this.scanExecutor = scanExecutor;
      }
   
      /* (non-Javadoc)
  -    * @see org.jboss.deployment.scanner.VFSDeploymentScanner#setScanEnabled(boolean)
  +    * @see org.jboss.deployment.scanner.VFSDeploymentScanner#getScanPeriod()
       */
  -   public void setScanEnabled(boolean flag)
  +   public long getScanPeriod()
      {
  -      // TODO Auto-generated method stub
  -      
  +      return scanPeriod;
      }
  -
      /* (non-Javadoc)
       * @see org.jboss.deployment.scanner.VFSDeploymentScanner#setScanPeriod(long)
       */
      public void setScanPeriod(long period)
      {
  -      // TODO Auto-generated method stub
  +      this.scanPeriod = period;
  +   }
  +
  +   /** Are deployment scans enabled.
  +    */
  +   public boolean isScanEnabled()
  +   {
  +      return activeScan != null;
  +   }
         
  +   public synchronized int getScanCount()
  +   {
  +      return scanCount;
  +   }
  +   public synchronized void resetScanCount()
  +   {
  +      this.scanCount = 0;
  +   }
  +
  +   /**
  +    * Enable/disable deployment scans.
  +    * @param scanEnabled true to enable scans, false to disable.
  +    */
  +   public synchronized void setScanEnabled(boolean scanEnabled)
  +   {
  +      if( scanEnabled == true && activeScan == null )
  +      {
  +         activeScan = this.scanExecutor.scheduleWithFixedDelay(this, 0,
  +               scanPeriod, TimeUnit.MILLISECONDS);
  +      }
  +      else if( scanEnabled == false && activeScan != null )
  +      {
  +         activeScan.cancel(true);
  +         activeScan = null;
  +      }
      }
   
       /**
  @@ -168,7 +207,8 @@
      {
         if (listspec == null)
         {
  -         throw new NullPointerException("listspec argument cannot be null");
  +         this.uriList.clear();
  +         return;
         }
         List<URI> list = new LinkedList<URI>();
      
  @@ -196,7 +236,7 @@
      {
         if (list == null)
         {
  -         throw new NullPointerException("list argument cannot be null");
  +         return;
         }
      
         // start out with a fresh list
  @@ -311,9 +351,52 @@
               vdfList.add(vf);
            }
         }
  +
  +      // Default to a single thread executor
  +      if( scanExecutor == null )
  +      {
  +         scanExecutor = Executors.newSingleThreadScheduledExecutor(
  +            new ThreadFactory()
  +            {
  +               public Thread newThread(Runnable r)
  +               {
  +                  return new Thread(r, "VFSDeploymentScanner");
  +               }
  +            }
  +        );
  +      }
  +      activeScan = scanExecutor.scheduleWithFixedDelay(this, 0,
  +            scanPeriod, TimeUnit.MILLISECONDS);
      }
   
  -   // AbstractDeploymentScanner overrides ---------------------------
  +   /**
  +    * Executes scan 
  +    *
  +    */
  +   public void run()
  +   {
  +      try
  +      {
  +         scan();
  +      }
  +      catch(Throwable e)
  +      {
  +         log.warn("Scan failed", e);
  +      }
  +      finally
  +      {
  +         incScanCount();
  +      }
  +   }
  +
  +   public void stop()
  +   {
  +      if( activeScan != null )
  +      {
  +         activeScan.cancel(true);
  +         activeScan = null;
  +      }
  +   }
      
      public synchronized void scan() throws Exception
      {
  @@ -321,7 +404,6 @@
         {
            throw new IllegalStateException("not initialized");
         }
  -   
         boolean trace = log.isTraceEnabled();
         lastIncompleteDeploymentException = null;
       
  @@ -337,17 +419,18 @@
         {
            for (Iterator i = vdfList.iterator(); i.hasNext();)
            {
  -            VirtualFile component = (VirtualFile)i.next();
  -            
  -            if (component.isFile())
  +            VirtualFile vf = (VirtualFile)i.next();
  +            if( true )
  +               log.debug("Checking file: "+vf);
  +            if (vf.isFile())
               {
                  // treat this as a deployable unit
  -               toDeployList.add(component);
  +               toDeployList.add(vf);
               }
  -            else if (component.isDirectory())
  +            else if (vf.isDirectory())
               {
                  // process (possibly recursively) the dir
  -               addDeployments(toDeployList, component);
  +               addDeployments(toDeployList, vf);
               }
            }
         }
  @@ -436,13 +519,13 @@
         {
            VirtualFile vf = (VirtualFile)i.next();
            
  -         // if component is not deployed already, deploy it
  +         // if vf is not deployed already, deploy it
            if (!deployedMap.containsKey(vf))
            {
               deploy(vf);
            }
   
  -         // component must have been deployed by now, so remove it from list 
  +         // vf must have been deployed by now, so remove it from list 
            i.remove();
            
            /* Check to see if mainDeployer suffix list has changed, if so, then resort
  @@ -472,6 +555,16 @@
         */
      }
         
  +   /**
  +    * Inc the scanCount and to a notifyAll.
  +    *
  +    */
  +   protected synchronized void incScanCount()
  +   {
  +      scanCount ++;
  +      notifyAll();
  +   }
  +
      // Private -------------------------------------------------------
      
       /**
  @@ -485,7 +578,7 @@
      }
      
      /**
  -    * A helper to find all deployments under a directory component
  +    * A helper to find all deployments under a directory vf
       * and add them to the supplied list.
       * 
       * We may recurse.
  
  
  



More information about the jboss-cvs-commits mailing list