geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner DeploymentScanner.java DeploymentScannerMBean.java
Date Wed, 13 Aug 2003 01:56:06 GMT
dain        2003/08/12 18:56:06

  Modified:    modules/core/src/java/org/apache/geronimo/deployment/scanner
                        DeploymentScanner.java DeploymentScannerMBean.java
  Log:
  Fixed synchronization -- scanner thread was holding a lock on the entire DeploymentScanner
object which stopped anyone from interacting with the service.
  
  Revision  Changes    Path
  1.6       +22 -11    incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/DeploymentScanner.java
  
  Index: DeploymentScanner.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/DeploymentScanner.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DeploymentScanner.java	12 Aug 2003 23:14:45 -0000	1.5
  +++ DeploymentScanner.java	13 Aug 2003 01:56:06 -0000	1.6
  @@ -64,6 +64,7 @@
   import java.util.Iterator;
   import java.util.Map;
   import java.util.Set;
  +import java.util.Collections;
   import javax.management.MBeanRegistration;
   import javax.management.MBeanServer;
   import javax.management.ObjectName;
  @@ -115,6 +116,10 @@
           this.scanInterval = scanInterval;
       }
   
  +    public synchronized Set getWatchedURLs() {
  +        return Collections.unmodifiableSet(new HashSet(scanners.keySet()));
  +    }
  +
       public void addURL(String url, boolean recurse) throws MalformedURLException {
           addURL(new URL(url), recurse);
       }
  @@ -145,18 +150,20 @@
           scanners.remove(url);
       }
   
  +    private synchronized boolean shouldScannerThreadRun() {
  +        return run;
  +    }
  +
       public synchronized void start() {
           if (scanThread == null) {
               run = true;
  -            scanThread = new Thread() {
  +            scanThread = new Thread("DeploymentScanner: ObjectName=" + objectName) {
                   public void run() {
  -                    synchronized (DeploymentScanner.this) {
  -                        while (run) {
  -                            scanNow();
  -                            try {
  -                                DeploymentScanner.this.wait(scanInterval);
  -                            } catch (InterruptedException e) {
  -                            }
  +                    while (shouldScannerThreadRun()) {
  +                        scanNow();
  +                        try {
  +                            Thread.sleep(getScanInterval());
  +                        } catch (InterruptedException e) {
                           }
                       }
                   }
  @@ -173,11 +180,15 @@
           }
       }
   
  -    public synchronized void scanNow() {
  +    public void scanNow() {
           boolean logTrace = log.isTraceEnabled();
   
           Set results = new HashSet();
  -        for (Iterator i = scanners.entrySet().iterator(); i.hasNext();) {
  +        Set scannersCopy;
  +        synchronized(this) {
  +            scannersCopy = new HashSet(scanners.entrySet());
  +        }
  +        for (Iterator i = scannersCopy.iterator(); i.hasNext();) {
               Map.Entry entry = (Map.Entry) i.next();
               URL url = (URL) entry.getKey();
               if (logTrace) {
  
  
  
  1.4       +14 -11    incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/DeploymentScannerMBean.java
  
  Index: DeploymentScannerMBean.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/DeploymentScannerMBean.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DeploymentScannerMBean.java	11 Aug 2003 17:59:11 -0000	1.3
  +++ DeploymentScannerMBean.java	13 Aug 2003 01:56:06 -0000	1.4
  @@ -57,6 +57,7 @@
   
   import java.net.MalformedURLException;
   import java.net.URL;
  +import java.util.Set;
   
   /**
    *
  @@ -65,23 +66,25 @@
    * @version $Revision$ $Date$
    */
   public interface DeploymentScannerMBean {
  -    public static final String SCAN_COMPLETE = "org.apache.geronimo.deployment.SCAN_COMPLETE";
  +    static final String SCAN_COMPLETE = "org.apache.geronimo.deployment.SCAN_COMPLETE";
   
  -    public long getScanInterval();
  +    long getScanInterval();
   
  -    public void setScanInterval(long interval);
  +    void setScanInterval(long interval);
   
  -    public void addURL(URL url, boolean recurse);
  +    void addURL(URL url, boolean recurse);
   
  -    public void addURL(String url, boolean recurse) throws MalformedURLException;
  +    void addURL(String url, boolean recurse) throws MalformedURLException;
   
  -    public void removeURL(URL url);
  +    void removeURL(URL url);
   
  -    public void removeURL(String url) throws MalformedURLException;
  +    void removeURL(String url) throws MalformedURLException;
   
  -    public void scanNow();
  +    void scanNow();
   
  -    public void start();
  +    void start();
   
  -    public void stop();
  +    void stop();
  +
  +    Set getWatchedURLs();
   }
  
  
  

Mime
View raw message