[jboss-cvs] JBoss Messaging SVN: r4558 - in trunk: src/main/org/jboss/messaging/core/deployers/impl and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jun 23 10:38:38 EDT 2008


Author: timfox
Date: 2008-06-23 10:38:38 -0400 (Mon, 23 Jun 2008)
New Revision: 4558

Modified:
   trunk/src/main/org/jboss/messaging/core/deployers/DeploymentManager.java
   trunk/src/main/org/jboss/messaging/core/deployers/impl/FileDeploymentManager.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/ClientNetworkFailureTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMessageTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossSessionTest.java
Log:
More test stuff


Modified: trunk/src/main/org/jboss/messaging/core/deployers/DeploymentManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/deployers/DeploymentManager.java	2008-06-23 14:09:12 UTC (rev 4557)
+++ trunk/src/main/org/jboss/messaging/core/deployers/DeploymentManager.java	2008-06-23 14:38:38 UTC (rev 4558)
@@ -44,5 +44,5 @@
     * @param deployer The deployable object
     * @throws Exception .
     */
-   void unregisterDeployer(Deployer deployer);
+   void unregisterDeployer(Deployer deployer) throws Exception;
 }

Modified: trunk/src/main/org/jboss/messaging/core/deployers/impl/FileDeploymentManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/deployers/impl/FileDeploymentManager.java	2008-06-23 14:09:12 UTC (rev 4557)
+++ trunk/src/main/org/jboss/messaging/core/deployers/impl/FileDeploymentManager.java	2008-06-23 14:38:38 UTC (rev 4558)
@@ -22,106 +22,119 @@
 
 package org.jboss.messaging.core.deployers.impl;
 
-import org.jboss.messaging.core.deployers.Deployer;
-import org.jboss.messaging.core.deployers.DeploymentManager;
-import org.jboss.messaging.core.logging.Logger;
-
 import java.io.File;
-import java.io.IOException;
 import java.net.URL;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 
+import org.jboss.messaging.core.deployers.Deployer;
+import org.jboss.messaging.core.deployers.DeploymentManager;
+import org.jboss.messaging.core.logging.Logger;
+
 /**
  * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ * @author <a href="tim.fox at jboss.com">Tim Fox</a>
  */
 public class FileDeploymentManager implements Runnable, DeploymentManager
 {
    private static final Logger log = Logger.getLogger(FileDeploymentManager.class);
-   //these are the list of deployers, typically destination and connection factory.
-   private static List<Deployer> deployers = new ArrayList<Deployer>();
-   //any config files deployed and the time they were deployed
-   private static Map<URL, Long> deployed = new HashMap<URL, Long>();
-   // the list of URL's to deploy
-   private static List<URL> toDeploy = new ArrayList<URL>();
-   //the list of URL's to undeploy if removed
-   private static List<URL> toUndeploy = new ArrayList<URL>();
-   //the list of URL's to redeploy if changed
-   private static List<URL> toRedeploy = new ArrayList<URL>();
+     
+   private final List<Deployer> deployers = new ArrayList<Deployer>();
+   
+   private final Map<URL, DeployInfo> deployed = new HashMap<URL, DeployInfo>();
 
-   private static ScheduledExecutorService scheduler;
-
+   private ScheduledExecutorService scheduler;
+   
+   private boolean started;
+   
    public synchronized void start() throws Exception
    {
-      Collection<ConfigurationURL> configurations = getConfigurations();
-      for (ConfigurationURL configuration : configurations)
+      if (started)
       {
-         Iterator<URL> urls = configuration.getUrls();
-         while (urls.hasNext())
-         {
-            URL url = urls.next();
-            log.info(new StringBuilder("adding url ").append(url).append(" to be deployed"));
-            deployed.put(url, new File(url.getFile()).lastModified());
-         }
+         return;
       }
-      // Get the scheduler
+      
       scheduler = Executors.newSingleThreadScheduledExecutor();
 
-      scheduler.scheduleAtFixedRate(this, 10, 5, TimeUnit.SECONDS);
+      scheduler.scheduleWithFixedDelay(this, 10, 5, TimeUnit.SECONDS);
+      
+      started = true;
    }
 
    public synchronized void stop()
    {
-      deployers.clear();
-      if (scheduler != null)
+      if (!started)
       {
-         scheduler.shutdown();
-         scheduler = null;
+         return;
       }
+      
+      scheduler.shutdown();
+      scheduler = null;
+      deployers.clear();
+      deployed.clear();   
+      
+      started = false;
    }
 
    /**
     * registers a Deployer object which will handle the deployment of URL's
     *
-    * @param Deployer The Deployer object
+    * @param deployer The Deployer object
     * @throws Exception .
     */
-   public synchronized void registerDeployer(final Deployer Deployer) throws Exception
+   public synchronized void registerDeployer(final Deployer deployer) throws Exception
    {
-      deployers.add(Deployer);
-      Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(Deployer.getConfigFileName());
-      while (urls.hasMoreElements())
+      if (!started)
       {
-         URL url = urls.nextElement();
-         if (!deployed.keySet().contains(url))
+         throw new IllegalStateException("Service is not started");
+      }
+      
+      if (!deployers.contains(deployer))
+      {
+         deployers.add(deployer);
+         
+         Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(deployer.getConfigFileName());        
+         while (urls.hasMoreElements())
          {
-            deployed.put(url, new File(url.getFile()).lastModified());
+            URL url = urls.nextElement();
+                                 
+            try
+            {
+               log.info("Deploying " + deployer + " with url " + url);
+               deployer.deploy(url);
+            }
+            catch (Exception e)
+            {
+               log.error("Error deploying " + url, e);
+            }
+            
+            deployed.put(url, new DeployInfo(deployer, new File(url.getFile()).lastModified()));            
          }
-         try
-         {
-            log.info(new StringBuilder("Deploying ").append(Deployer).append(" with url").append(url));
-            Deployer.deploy(url);
-
-         }
-         catch (Exception e)
-         {
-            log.error(new StringBuilder("Error deploying ").append(url), e);
-         }
-      }
+      }            
    }
 
-   public synchronized void unregisterDeployer(final Deployer Deployer)
+   public synchronized void unregisterDeployer(final Deployer deployer) throws Exception
    {
-      deployers.remove(Deployer);
-      if (deployers.size() == 0)
+      if (!started)
       {
-         if (scheduler != null)
+         throw new IllegalStateException("Service is not started");
+      }
+      
+      if (deployers.remove(deployer))
+      {
+         Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(deployer.getConfigFileName());
+         while (urls.hasMoreElements())
          {
-            scheduler.shutdown();
-            scheduler = null;
-         }
+            URL url = urls.nextElement();
+            
+            deployed.remove(url);
+         }         
       }
    }
 
@@ -130,6 +143,11 @@
     */
    public synchronized void run()
    {
+      if (!started)
+      {
+         throw new IllegalStateException("Service is not started");
+      }
+      
       try
       {
          scan();
@@ -141,185 +159,90 @@
    }
 
    /**
-    * will return any resources available
+    * scans for changes to any of the configuration files registered
     *
-    * @return a set of configurationUrls
-    * @throws java.io.IOException .
+    * @throws Exception .
     */
-   private Collection<ConfigurationURL> getConfigurations() throws IOException
-   {
-      Map<String, ConfigurationURL> configurations = new HashMap<String, ConfigurationURL>();
+   public void scan() throws Exception
+   {    
+      if (!started)
+      {
+         throw new IllegalStateException("Service is not started");
+      }
+      
       for (Deployer deployer : deployers)
       {
          Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(deployer.getConfigFileName());
 
-         if (!configurations.keySet().contains(deployer.getConfigFileName()))
+         while (urls.hasMoreElements())
          {
-            ConfigurationURL conf = new ConfigurationURL(urls, deployer.getConfigFileName());
-            configurations.put(deployer.getConfigFileName(), conf);
-         }
-         else
-         {
-            configurations.get(deployer.getConfigFileName()).add(urls);
-         }
+            URL url = urls.nextElement();
+            
+            DeployInfo info = deployed.get(url);
+            
+            if (info == null)
+            {                              
+               try
+               {
+                  log.info("Deploying " + deployer + " with url " + url);
+                  
+                  deployer.deploy(url);
+                  
+                  deployed.put(url, new DeployInfo(deployer, new File(url.getFile()).lastModified()));
+               }
+               catch (Exception e)
+               {
+                  log.error("Error deploying " + url, e);
+               }
+            }
+            else if (new File(url.getFile()).lastModified() > info.lastModified)
+            {                              
+               try
+               {
+                  log.info("Redeploying " + deployer + " with url " + url);
+                  
+                  deployer.redeploy(url);
+                  
+                  deployed.put(url, new DeployInfo(deployer, new File(url.getFile()).lastModified()));
+               }
+               catch (Exception e)
+               {
+                  log.error("Error redeploying " + url, e);
+               }
+            }
+         }         
       }
-      return configurations.values();
-   }
-
-
-   /**
-    * scans for changes to any of the configuration files registered
-    *
-    * @throws Exception .
-    */
-   private void scan() throws Exception
-   {
-      Collection<ConfigurationURL> configurations = getConfigurations();
-      for (ConfigurationURL configuration : configurations)
+      
+      for (Map.Entry<URL, DeployInfo> entry : deployed.entrySet())
       {
-         Iterator<URL> urls = configuration.getUrls();
-         while (urls.hasNext())
+         if (!new File(entry.getKey().getFile()).exists())
          {
-            URL url = urls.next();
-            if (!deployed.keySet().contains(url))
+            try
             {
-               log.info(new StringBuilder("adding url ").append(url).append(" to be deployed"));
-               toDeploy.add(url);
+               Deployer deployer = entry.getValue().deployer;
+               log.info("Undeploying " + deployer + " with url" + entry.getKey());
+               deployer.undeploy(entry.getKey());
             }
-            else if (new File(url.getFile()).lastModified() > deployed.get(url))
+            catch (Exception e)
             {
-               log.info(new StringBuilder("adding url ").append(url).append(" to be redeployed"));
-               toRedeploy.add(url);
+               log.error("Error undeploying " + entry.getKey(), e);
             }
          }
-         for (URL url : deployed.keySet())
-         {
-            if (!new File(url.getFile()).exists())
-            {
-               log.info(new StringBuilder("adding url ").append(url).append(" to be undeployed"));
-               toUndeploy.add(url);
-            }
-         }
       }
-
-      for (URL url : toDeploy)
-      {
-         deploy(url);
-      }
-      for (URL url : toRedeploy)
-      {
-         redeploy(url);
-      }
-      for (URL url : toUndeploy)
-      {
-         undeploy(url);
-      }
-      toRedeploy.clear();
-      toUndeploy.clear();
-      toDeploy.clear();
    }
-
-   /**
-    * undeploys a url, delegates to appropiate registered Deployers
-    *
-    * @param url the url to undeploy
-    */
-   private void undeploy(final URL url)
+   
+   // Inner classes -------------------------------------------------------------------------------------------
+   
+   private static class DeployInfo
    {
-      deployed.remove(url);
-
-      for (Deployer Deployer : deployers)
+      Deployer deployer;
+      long lastModified;
+      
+      DeployInfo(final Deployer deployer, final long lastModified)
       {
-         try
-         {
-            log.info(new StringBuilder("Undeploying ").append(Deployer).append(" with url").append(url));
-            Deployer.undeploy(url);
-         }
-         catch (Exception e)
-         {
-            log.error(new StringBuilder("Error undeploying ").append(url), e);
-         }
+         this.deployer = deployer;
+         this.lastModified = lastModified;
       }
    }
-
-   /**
-    * redeploys a url, delegates to appropiate registered Deployers
-    *
-    * @param url the url to redeploy
-    */
-   private void redeploy(final URL url)
-   {
-      deployed.put(url, new File(url.getFile()).lastModified());
-      for (Deployer Deployer : deployers)
-      {
-         try
-         {
-            log.info(new StringBuilder("Redeploying ").append(Deployer).append(" with url").append(url));
-            Deployer.redeploy(url);
-         }
-         catch (Exception e)
-         {
-            log.error(new StringBuilder("Error redeploying ").append(url), e);
-         }
-      }
-   }
-
-   /**
-    * deploys a url, delegates to appropiate registered Deployers
-    *
-    * @param url the url to deploy
-    * @throws Exception .
-    */
-   private void deploy(final URL url) throws Exception
-   {
-      deployed.put(url, new File(url.getFile()).lastModified());
-      for (Deployer Deployer : deployers)
-      {
-         try
-         {
-            log.info(new StringBuilder("Deploying ").append(Deployer).append(" with url").append(url));
-            Deployer.deploy(url);
-         }
-         catch (Exception e)
-         {
-            log.error(new StringBuilder("Error deploying ").append(url), e);
-         }
-      }
-   }
-
-   private static class ConfigurationURL
-   {
-      private List<URL> urls = new ArrayList<URL>();
-      private String configFileName;
-
-      public ConfigurationURL(final Enumeration<URL> urls, final String configFileName)
-      {
-         while (urls.hasMoreElements())
-         {
-            URL url = urls.nextElement();
-            this.urls.add(url);
-         }
-         this.configFileName = configFileName;
-      }
-
-      public Iterator<URL> getUrls()
-      {
-         return urls.iterator();
-      }
-
-      public String getConfigFileName()
-      {
-         return configFileName;
-      }
-
-      public void add(final Enumeration<URL> urls)
-      {
-         while (urls.hasMoreElements())
-         {
-            URL url = urls.nextElement();
-            this.urls.add(url);
-         }
-      }
-   }
 }
 

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/ClientNetworkFailureTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/ClientNetworkFailureTest.java	2008-06-23 14:09:12 UTC (rev 4557)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/ClientNetworkFailureTest.java	2008-06-23 14:38:38 UTC (rev 4558)
@@ -45,7 +45,6 @@
 import org.jboss.messaging.core.remoting.TransportType;
 import org.jboss.messaging.core.remoting.impl.RemotingServiceImpl;
 import org.jboss.messaging.core.remoting.impl.mina.MinaAcceptor;
-import org.jboss.messaging.core.server.ConnectionManager;
 import org.jboss.messaging.core.server.MessagingService;
 import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
 

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueTest.java	2008-06-23 14:09:12 UTC (rev 4557)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueTest.java	2008-06-23 14:38:38 UTC (rev 4558)
@@ -1201,12 +1201,6 @@
       assertEquals(4, queue.getDeliveringCount());
    }
    
-   
-   
-  
-   
-   
-   
    // Inner classes ---------------------------------------------------------------
         
    class DummyDistributionPolicy implements DistributionPolicy

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMessageTest.java	2008-06-23 14:09:12 UTC (rev 4557)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMessageTest.java	2008-06-23 14:38:38 UTC (rev 4558)
@@ -322,10 +322,12 @@
       int invalidPriority = 10;
       JBossMessage message = new JBossMessage();
 
-      try {
+      try
+      {
          message.setJMSPriority(invalidPriority);
          fail("0 <= priority <= 9");
-      } catch(JMSException e)
+      }
+      catch(JMSException e)
       {
       }
    }
@@ -389,7 +391,8 @@
       {
          message.setJMSMessageID(messageID);
          fail("messageID does not start with ID:");
-      } catch (JMSException e)
+      }
+      catch (JMSException e)
       {
 
       }
@@ -422,7 +425,8 @@
       {
          message.setBooleanProperty(null, true);
          fail("property name can not be null");
-      } catch (IllegalArgumentException e)
+      }
+      catch (IllegalArgumentException e)
       {
       }
    }
@@ -448,7 +452,8 @@
       {
          message.setBooleanProperty("", true);
          fail("property name can not be empty");
-      } catch (IllegalArgumentException e)
+      }
+      catch (IllegalArgumentException e)
       {
       }
    }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossSessionTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossSessionTest.java	2008-06-23 14:09:12 UTC (rev 4557)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossSessionTest.java	2008-06-23 14:38:38 UTC (rev 4558)
@@ -387,7 +387,8 @@
             JBossSession.TYPE_GENERIC_SESSION);
       assertNull(session.getMessageListener());
       session.setMessageListener(listener);
-      assertSame(listener, session.getMessageListener());
+      //Note we don't implement ASF so always return null
+      assertNull(session.getMessageListener());
 
       verify(listener);
    }




More information about the jboss-cvs-commits mailing list