[jboss-cvs] JBoss Messaging SVN: r3817 - in trunk: src/main/org/jboss/messaging/core/deployers and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 27 09:17:08 EST 2008
Author: ataylor
Date: 2008-02-27 09:17:07 -0500 (Wed, 27 Feb 2008)
New Revision: 3817
Added:
trunk/src/main/org/jboss/messaging/core/deployers/impl/FileDeploymentManager.java
trunk/src/main/org/jboss/messaging/core/deployers/impl/XmlDeployer.java
Removed:
trunk/src/main/org/jboss/messaging/core/deployers/Deployable.java
Modified:
trunk/src/etc/server/default/deploy/jbm-beans.xml
trunk/src/main/org/jboss/messaging/core/deployers/Deployer.java
trunk/src/main/org/jboss/messaging/core/deployers/DeploymentManager.java
trunk/src/main/org/jboss/messaging/core/deployers/impl/QueueSettingsDeployer.java
trunk/src/main/org/jboss/messaging/core/deployers/impl/SecurityDeployer.java
trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java
trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerDeployer.java
trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/DeployerTest.java
trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/SecurityDeployerTest.java
Log:
introduced interfaces for deployment classes
Modified: trunk/src/etc/server/default/deploy/jbm-beans.xml
===================================================================
--- trunk/src/etc/server/default/deploy/jbm-beans.xml 2008-02-27 13:25:11 UTC (rev 3816)
+++ trunk/src/etc/server/default/deploy/jbm-beans.xml 2008-02-27 14:17:07 UTC (rev 3817)
@@ -76,6 +76,9 @@
<property name="jmsServerManager">
<inject bean="JMSServerManager"/>
</property>
+ <property name="messagingServer">
+ <inject bean="MessagingServer"/>
+ </property>
</bean>
</deployment>
\ No newline at end of file
Deleted: trunk/src/main/org/jboss/messaging/core/deployers/Deployable.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/deployers/Deployable.java 2008-02-27 13:25:11 UTC (rev 3816)
+++ trunk/src/main/org/jboss/messaging/core/deployers/Deployable.java 2008-02-27 14:17:07 UTC (rev 3817)
@@ -1,41 +0,0 @@
-package org.jboss.messaging.core.deployers;
-
-import java.net.URL;
-
-/**
- * Extended to allow objects to be deployed via the Deploymwntmanager
- *
- * @author <a href="ataylor at redhat.com">Andy Taylor</a>
- */
-public interface Deployable
-{
- /**
- * The name of the configuration file name to look for for deployment
- *
- * @return The name of the config file
- */
- String getConfigFileName();
-
- /**
- * Deploy the URL for the first time
- *
- * @param url The resource todeploy
- * @throws Exception .
- */
- void deploy(URL url) throws Exception;
-
- /**
- * Redeploys a URL if changed
- *
- * @param url The resource to redeploy
- * @throws Exception .
- */
- void redeploy(URL url) throws Exception;
-
- /**
- * Undeploys a resource that has been removed
- * @param url The Resource that was deleted
- * @throws Exception .
- */
- void undeploy(URL url) throws Exception;
-}
Modified: trunk/src/main/org/jboss/messaging/core/deployers/Deployer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/deployers/Deployer.java 2008-02-27 13:25:11 UTC (rev 3816)
+++ trunk/src/main/org/jboss/messaging/core/deployers/Deployer.java 2008-02-27 14:17:07 UTC (rev 3817)
@@ -39,210 +39,35 @@
*
* @author <a href="ataylor at redhat.com">Andy Taylor</a>
*/
-public abstract class Deployer implements Deployable, MessagingComponent
+public interface Deployer extends MessagingComponent
{
- private static Logger log = Logger.getLogger(Deployer.class);
- protected static final String NAME_ATTR = "name";
-
- private HashMap<URL, HashMap<String, Node>> configuration = new HashMap<URL, HashMap<String, Node>>();
-
/**
- * adds a URL to the already configured set of url's this deployer is handling
- * @param url The URL to add
- * @param name the name of the element
- * @param e .
- */
- public void addToConfiguration(URL url, String name, Node e)
- {
- if (configuration.get(url) == null)
- {
- configuration.put(url, new HashMap<String, Node>());
- }
- configuration.get(url).put(name, e);
- }
-
- /**
- * Redeploys a URL if changed
+ * The name of the configuration file name to look for for deployment
*
- * @param url The resource to redeploy
- * @throws Exception .
+ * @return The name of the config file
*/
- public void redeploy(URL url) throws Exception
- {
- Element e = getRootElement(url);
- ArrayList<String> added = new ArrayList<String>();
- //pull out the elements that need deploying
- String elements[] = getElementTagName();
- for (String element : elements)
- {
- NodeList children = e.getElementsByTagName(element);
- for (int i = 0; i < children.getLength(); i++)
- {
- Node node = children.item(i);
- String name = node.getAttributes().getNamedItem(getKeyAttribute()).getNodeValue();
- added.add(name);
- //if this has never been deployed deploy
- if (configuration.get(url) == null || (configuration.get(url) != null && configuration.get(url).get(name) == null))
- {
- log.info(new StringBuilder(name).append(" doesn't exist deploying"));
- deploy(node);
- }
- //or if it has changed redeploy
- else if (hasNodeChanged(url, node, name))
- {
- log.info(new StringBuilder(name).append(" has changed redeploying"));
- undeploy(node);
- deploy(node);
- addToConfiguration(url, name, node);
- }
+ String getConfigFileName();
- }
- }
- //now check for anything thathas been removed and undeploy
- if (configuration.get(url) != null)
- {
- Set<String> keys = configuration.get(url).keySet();
- ArrayList<String> removed = new ArrayList<String>();
-
- for (String key : keys)
- {
- if(!added.contains(key))
- {
- undeploy(configuration.get(url).get(key));
- removed.add(key);
- }
- }
- for (String s : removed)
- {
- configuration.get(url).remove(s);
- }
- }
- }
-
- protected Element getRootElement(URL url)
- throws Exception
- {
- return XMLUtil.urlToElement(url);
- }
-
- private boolean hasNodeChanged(URL url, Node child, String name)
- {
- String newTextContent = child.getTextContent();
- String origTextContent = configuration.get(url).get(name).getTextContent();
- return !newTextContent.equals(origTextContent);
- }
-
/**
- * Undeploys a resource that has been removed
- * @param url The Resource that was deleted
- * @throws Exception .
- */
- public void undeploy(URL url) throws Exception
- {
- Set<String> keys = configuration.get(url).keySet();
- for (String key : keys)
- {
- undeploy(configuration.get(url).get(key));
- }
- configuration.remove(url);
- }
-
- /**
* Deploy the URL for the first time
*
* @param url The resource todeploy
* @throws Exception .
*/
- public void deploy(URL url) throws Exception
- {
- Element e = getRootElement(url);
- //find all thenodes to deploy
- String elements[] = getElementTagName();
- for (String element : elements)
- {
- NodeList children = e.getElementsByTagName(element);
- for (int i = 0; i < children.getLength(); i++)
- {
- Node node = children.item(i);
- Node keyNode = node.getAttributes().getNamedItem(getKeyAttribute());
- if(keyNode == null)
- {
- log.error("key attribuet missing for configuration " + node);
- continue;
- }
- String name = keyNode.getNodeValue();
- log.info(new StringBuilder("deploying ").append(name));
- try
- {
- deploy(node);
- }
- catch (Exception e1)
- {
- log.error(new StringBuilder("Unable to deploy node ").append(node), e1);
- continue;
- }
- addToConfiguration(url, name, node);
- }
- }
- }
+ void deploy(URL url) throws Exception;
/**
- * the key attribute for theelement, usually 'name' but can be overridden
- * @return the key attribute
- */
- public String getKeyAttribute()
- {
- return NAME_ATTR;
- }
-
- //register with the deploymenmt manager
- public void start() throws Exception
- {
- DeploymentManager.getInstance().registerDeployable(this);
- }
-
- //undeploy everything
- public void stop() throws Exception
- {
- Collection<HashMap<String, Node>> urls = configuration.values();
- for (HashMap<String, Node> hashMap : urls)
- {
- for (Node node : hashMap.values())
- {
- try
- {
- undeploy(node);
- }
- catch (Exception e)
- {
- log.warn("problem undeploying " + node, e);
- }
- }
- }
- DeploymentManager.getInstance().unregisterDeployable(this);
- }
-
- /**
- * the names of the elements to deploy
- * @return the names of the elements todeploy
- */
- public abstract String[] getElementTagName();
-
-
- /**
- * deploy an element
- * @param node the element to deploy
+ * Redeploys a URL if changed
+ *
+ * @param url The resource to redeploy
* @throws Exception .
*/
- public abstract void deploy(Node node)
- throws Exception;
+ void redeploy(URL url) throws Exception;
/**
- * undeploys an element
- * @param node the element to undeploy
+ * Undeploys a resource that has been removed
+ * @param url The Resource that was deleted
* @throws Exception .
*/
- public abstract void undeploy(Node node)
- throws Exception;
-
-}
+ void undeploy(URL url) throws Exception;
+}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/messaging/core/deployers/DeploymentManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/deployers/DeploymentManager.java 2008-02-27 13:25:11 UTC (rev 3816)
+++ trunk/src/main/org/jboss/messaging/core/deployers/DeploymentManager.java 2008-02-27 14:17:07 UTC (rev 3817)
@@ -21,314 +21,28 @@
*/
package org.jboss.messaging.core.deployers;
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
+import org.jboss.messaging.core.server.MessagingComponent;
-import org.jboss.logging.Logger;
-
/**
* This class manages any configuration files available. It will notify any deployers registered with it on changes.
*
* @author <a href="ataylor at redhat.com">Andy Taylor</a>
*/
-public class DeploymentManager implements Runnable
+public interface DeploymentManager extends MessagingComponent
{
- private static final Logger log = Logger.getLogger(DeploymentManager.class);
- //use the singleton pattern we only need one of these
- private static DeploymentManager singleton;
- //these are the list of deployers, typically destination and connection factory.
- private static ArrayList<Deployable> deployables = new ArrayList<Deployable>();
- //any config files deployed and the time they were deployed
- private static HashMap<URL, Long> deployed = new HashMap<URL, Long>();
- // the list of URL's to deploy
- private static ArrayList<URL> toDeploy = new ArrayList<URL>();
- //the list of URL's to undeploy if removed
- private static ArrayList<URL> toUndeploy = new ArrayList<URL>();
- //the list of URL's to redeploy if changed
- private static ArrayList<URL> toRedeploy = new ArrayList<URL>();
- private static ScheduledExecutorService scheduler;
-
- //we want to use a singleton
- private DeploymentManager()
- {
-
- }
-
- public static DeploymentManager getInstance() throws Exception
- {
- //if the first time initialise and get the URL's to deploy
- if (singleton == null)
- {
- singleton = new DeploymentManager();
- //get the URL's to deploy and add them to the list with the timestamp
- Collection<ConfigurationURL> configurations = getConfigurations();
- for (ConfigurationURL configuration : configurations)
- {
- 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());
- }
- }
-
- // Get the scheduler
- scheduler = Executors.newSingleThreadScheduledExecutor();
-
- scheduler.scheduleAtFixedRate(singleton, 10, 5, TimeUnit.SECONDS);
- }
- return singleton;
- }
-
/**
- * will return any resources available
- *
- * @return a set of configurationUrls
- * @throws IOException .
- */
- private static Collection<ConfigurationURL> getConfigurations() throws IOException
- {
- HashMap<String, ConfigurationURL> configurations = new HashMap<String, ConfigurationURL>();
- for (Deployable deployable : deployables)
- {
- Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(deployable.getConfigFileName());
-
- if(!configurations.keySet().contains(deployable.getConfigFileName()))
- {
- ConfigurationURL conf = new ConfigurationURL(urls, deployable.getConfigFileName());
- configurations.put(deployable.getConfigFileName(), conf);
- }
- else
- {
- configurations.get(deployable.getConfigFileName()).add(urls);
- }
- }
- return configurations.values();
- }
-
- /**
* registers a deployable object which will handle the deployment of URL's
*
* @param deployable The deployable object
* @throws Exception .
*/
- public void registerDeployable(Deployable deployable) throws Exception
- {
- synchronized (this)
- {
- deployables.add(deployable);
- Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(deployable.getConfigFileName());
- while (urls.hasMoreElements())
- {
- URL url = urls.nextElement();
- if (!deployed.keySet().contains(url))
- {
- deployed.put(url, new File(url.getFile()).lastModified());
- }
- try
- {
- log.info(new StringBuilder("Deploying ").append(deployable).append(" with url").append(url));
- deployable.deploy(url);
+ public void registerDeployer(Deployer deployer) throws Exception;
- }
- catch (Exception e)
- {
- log.error(new StringBuilder("Error deploying ").append(url), e);
- }
- }
- }
- }
-
- public void unregisterDeployable(Deployable deployable)
- {
- deployables.remove(deployable);
- if(deployables.size() == 0)
- {
- if (scheduler != null)
- {
- scheduler.shutdown();
- scheduler = null;
- }
- }
- }
/**
- * called by the ExecutorService every n seconds
- */
- public void run()
- {
- synchronized (this)
- {
- try
- {
- scan();
- }
- catch (Exception e)
- {
- log.warn("error scanning for URL's " + e);
- }
- }
- }
-
- /**
- * scans for changes to any of the configuration files registered
+ * unregisters a deployable object which will handle the deployment of URL's
*
+ * @param deployable The deployable object
* @throws Exception .
*/
- private void scan() throws Exception
- {
- Collection<ConfigurationURL> configurations = getConfigurations();
- for (ConfigurationURL configuration : configurations)
- {
- Iterator<URL> urls = configuration.getUrls();
- while (urls.hasNext())
- {
- URL url = urls.next();
- if (!deployed.keySet().contains(url))
- {
- log.info(new StringBuilder("adding url ").append(url).append(" to be deployed"));
- toDeploy.add(url);
- }
- else if (new File(url.getFile()).lastModified() > deployed.get(url))
- {
- log.info(new StringBuilder("adding url ").append(url).append(" to be redeployed"));
- toRedeploy.add(url);
- }
- }
- 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 deployables
- * @param url the url to undeploy
- */
- private void undeploy(URL url)
- {
- deployed.remove(url);
-
- for (Deployable deployable : deployables)
- {
- try
- {
- log.info(new StringBuilder("Undeploying ").append(deployable).append(" with url").append(url));
- deployable.undeploy(url);
- }
- catch (Exception e)
- {
- log.error(new StringBuilder("Error undeploying ").append(url), e);
- }
- }
- }
-
- /**
- * redeploys a url, delegates to appropiate registered deployables
- * @param url the url to redeploy
- */
- private void redeploy(URL url)
- {
- deployed.put(url, new File(url.getFile()).lastModified());
- for (Deployable deployable : deployables)
- {
- try
- {
- log.info(new StringBuilder("Redeploying ").append(deployable).append(" with url").append(url));
- deployable.redeploy(url);
- }
- catch (Exception e)
- {
- log.error(new StringBuilder("Error redeploying ").append(url), e);
- }
- }
- }
-
- /**
- * deploys a url, delegates to appropiate registered deployables
- * @param url the url to deploy
- * @throws Exception .
- */
- private void deploy(URL url)
- throws Exception
- {
- deployed.put(url, new File(url.getFile()).lastModified());
- for (Deployable deployable : deployables)
- {
- try
- {
- log.info(new StringBuilder("Deploying ").append(deployable).append(" with url").append(url));
- deployable.deploy(url);
- }
- catch (Exception e)
- {
- log.error(new StringBuilder("Error deploying ").append(url), e);
- }
- }
- }
-
- static class ConfigurationURL
- {
- private ArrayList<URL> urls = new ArrayList<URL>();
- private String configFileName;
-
- public ConfigurationURL(Enumeration<URL> urls, 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(Enumeration<URL> urls)
- {
- while (urls.hasMoreElements())
- {
- URL url = urls.nextElement();
- this.urls.add(url);
- }
- }
- }
+ public void unregisterDeployer(Deployer deployer);
}
Added: trunk/src/main/org/jboss/messaging/core/deployers/impl/FileDeploymentManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/deployers/impl/FileDeploymentManager.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/deployers/impl/FileDeploymentManager.java 2008-02-27 14:17:07 UTC (rev 3817)
@@ -0,0 +1,326 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.core.deployers.impl;
+
+import org.jboss.logging.Logger;
+import org.jboss.messaging.core.deployers.DeploymentManager;
+import org.jboss.messaging.core.deployers.Deployer;
+
+import java.util.*;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.net.URL;
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</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 ArrayList<Deployer> Deployers = new ArrayList<Deployer>();
+ //any config files deployed and the time they were deployed
+ private static HashMap<URL, Long> deployed = new HashMap<URL, Long>();
+ // the list of URL's to deploy
+ private static ArrayList<URL> toDeploy = new ArrayList<URL>();
+ //the list of URL's to undeploy if removed
+ private static ArrayList<URL> toUndeploy = new ArrayList<URL>();
+ //the list of URL's to redeploy if changed
+ private static ArrayList<URL> toRedeploy = new ArrayList<URL>();
+ private static ScheduledExecutorService scheduler;
+
+
+ public void start() throws Exception
+ {
+ Collection<ConfigurationURL> configurations = getConfigurations();
+ for (ConfigurationURL configuration : configurations)
+ {
+ 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());
+ }
+ }
+
+ // Get the scheduler
+ scheduler = Executors.newSingleThreadScheduledExecutor();
+
+ scheduler.scheduleAtFixedRate(this, 10, 5, TimeUnit.SECONDS);
+ }
+
+ public void stop()
+ {
+ if (scheduler != null)
+ {
+ scheduler.shutdown();
+ scheduler = null;
+ }
+ }
+ /**
+ * registers a Deployer object which will handle the deployment of URL's
+ *
+ * @param Deployer The Deployer object
+ * @throws Exception .
+ */
+ public void registerDeployer(Deployer Deployer) throws Exception
+ {
+ synchronized (this)
+ {
+ Deployers.add(Deployer);
+ Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(Deployer.getConfigFileName());
+ while (urls.hasMoreElements())
+ {
+ URL url = urls.nextElement();
+ if (!deployed.keySet().contains(url))
+ {
+ deployed.put(url, 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 void unregisterDeployer(Deployer Deployer)
+ {
+ Deployers.remove(Deployer);
+ if(Deployers.size() == 0)
+ {
+ if (scheduler != null)
+ {
+ scheduler.shutdown();
+ scheduler = null;
+ }
+ }
+ }
+ /**
+ * called by the ExecutorService every n seconds
+ */
+ public void run()
+ {
+ synchronized (this)
+ {
+ try
+ {
+ scan();
+ }
+ catch (Exception e)
+ {
+ log.warn("error scanning for URL's " + e);
+ }
+ }
+ }
+
+ /**
+ * will return any resources available
+ *
+ * @return a set of configurationUrls
+ * @throws java.io.IOException .
+ */
+ private static Collection<ConfigurationURL> getConfigurations() throws IOException
+ {
+ HashMap<String, ConfigurationURL> configurations = new HashMap<String, ConfigurationURL>();
+ for (Deployer Deployer : Deployers)
+ {
+ Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(Deployer.getConfigFileName());
+
+ if(!configurations.keySet().contains(Deployer.getConfigFileName()))
+ {
+ ConfigurationURL conf = new ConfigurationURL(urls, Deployer.getConfigFileName());
+ configurations.put(Deployer.getConfigFileName(), conf);
+ }
+ else
+ {
+ configurations.get(Deployer.getConfigFileName()).add(urls);
+ }
+ }
+ 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)
+ {
+ Iterator<URL> urls = configuration.getUrls();
+ while (urls.hasNext())
+ {
+ URL url = urls.next();
+ if (!deployed.keySet().contains(url))
+ {
+ log.info(new StringBuilder("adding url ").append(url).append(" to be deployed"));
+ toDeploy.add(url);
+ }
+ else if (new File(url.getFile()).lastModified() > deployed.get(url))
+ {
+ log.info(new StringBuilder("adding url ").append(url).append(" to be redeployed"));
+ toRedeploy.add(url);
+ }
+ }
+ 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(URL url)
+ {
+ deployed.remove(url);
+
+ for (Deployer Deployer : Deployers)
+ {
+ 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);
+ }
+ }
+ }
+
+ /**
+ * redeploys a url, delegates to appropiate registered Deployers
+ * @param url the url to redeploy
+ */
+ private void redeploy(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(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);
+ }
+ }
+ }
+
+ static class ConfigurationURL
+ {
+ private ArrayList<URL> urls = new ArrayList<URL>();
+ private String configFileName;
+
+ public ConfigurationURL(Enumeration<URL> urls, 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(Enumeration<URL> urls)
+ {
+ while (urls.hasMoreElements())
+ {
+ URL url = urls.nextElement();
+ this.urls.add(url);
+ }
+ }
+ }
+}
+
Modified: trunk/src/main/org/jboss/messaging/core/deployers/impl/QueueSettingsDeployer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/deployers/impl/QueueSettingsDeployer.java 2008-02-27 13:25:11 UTC (rev 3816)
+++ trunk/src/main/org/jboss/messaging/core/deployers/impl/QueueSettingsDeployer.java 2008-02-27 14:17:07 UTC (rev 3817)
@@ -32,7 +32,7 @@
* A deployer for creating a set of queue settings and adding them to a repository
* @author <a href="ataylor at redhat.com">Andy Taylor</a>
*/
-public class QueueSettingsDeployer extends Deployer
+public class QueueSettingsDeployer extends XmlDeployer
{
private static final String CLUSTERED_NODE_NAME = "clustered";
Modified: trunk/src/main/org/jboss/messaging/core/deployers/impl/SecurityDeployer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/deployers/impl/SecurityDeployer.java 2008-02-27 13:25:11 UTC (rev 3816)
+++ trunk/src/main/org/jboss/messaging/core/deployers/impl/SecurityDeployer.java 2008-02-27 14:17:07 UTC (rev 3817)
@@ -35,7 +35,7 @@
*
* @author <a href="ataylor at redhat.com">Andy Taylor</a>
*/
-public class SecurityDeployer extends Deployer
+public class SecurityDeployer extends XmlDeployer
{
private static final String PERMISSION_ELEMENT_NAME = "permission";
@@ -50,6 +50,10 @@
*/
private HierarchicalRepository<HashSet<Role>> securityRepository;
+ public SecurityDeployer(HierarchicalRepository<HashSet<Role>> securityRepository)
+ {
+ this.securityRepository = securityRepository;
+ }
/**
* the names of the elements to deploy
* @return the names of the elements todeploy
@@ -68,11 +72,6 @@
return MATCH;
}
- public void setSecurityRepository(HierarchicalRepository<HashSet<Role>> securityRepository)
- {
- this.securityRepository = securityRepository;
- }
-
/**
* deploy an element
* @param node the element to deploy
Added: trunk/src/main/org/jboss/messaging/core/deployers/impl/XmlDeployer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/deployers/impl/XmlDeployer.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/deployers/impl/XmlDeployer.java 2008-02-27 14:17:07 UTC (rev 3817)
@@ -0,0 +1,246 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.core.deployers.impl;
+
+import org.jboss.messaging.core.deployers.Deployer;
+import org.jboss.messaging.core.server.MessagingComponent;
+import org.jboss.messaging.util.XMLUtil;
+import org.jboss.logging.Logger;
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.Collection;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public abstract class XmlDeployer implements Deployer, MessagingComponent
+{
+ private static Logger log = Logger.getLogger(XmlDeployer.class);
+ protected static final String NAME_ATTR = "name";
+
+ private HashMap<URL, HashMap<String, Node>> configuration = new HashMap<URL, HashMap<String, Node>>();
+
+ /**
+ * adds a URL to the already configured set of url's this deployer is handling
+ * @param url The URL to add
+ * @param name the name of the element
+ * @param e .
+ */
+ public void addToConfiguration(URL url, String name, Node e)
+ {
+ if (configuration.get(url) == null)
+ {
+ configuration.put(url, new HashMap<String, Node>());
+ }
+ configuration.get(url).put(name, e);
+ }
+
+ /**
+ * Redeploys a URL if changed
+ *
+ * @param url The resource to redeploy
+ * @throws Exception .
+ */
+ public void redeploy(URL url) throws Exception
+ {
+ Element e = getRootElement(url);
+ ArrayList<String> added = new ArrayList<String>();
+ //pull out the elements that need deploying
+ String elements[] = getElementTagName();
+ for (String element : elements)
+ {
+ NodeList children = e.getElementsByTagName(element);
+ for (int i = 0; i < children.getLength(); i++)
+ {
+ Node node = children.item(i);
+ String name = node.getAttributes().getNamedItem(getKeyAttribute()).getNodeValue();
+ added.add(name);
+ //if this has never been deployed deploy
+ if (configuration.get(url) == null || (configuration.get(url) != null && configuration.get(url).get(name) == null))
+ {
+ log.info(new StringBuilder(name).append(" doesn't exist deploying"));
+ deploy(node);
+ }
+ //or if it has changed redeploy
+ else if (hasNodeChanged(url, node, name))
+ {
+ log.info(new StringBuilder(name).append(" has changed redeploying"));
+ undeploy(node);
+ deploy(node);
+ addToConfiguration(url, name, node);
+ }
+
+ }
+ }
+ //now check for anything thathas been removed and undeploy
+ if (configuration.get(url) != null)
+ {
+ Set<String> keys = configuration.get(url).keySet();
+ ArrayList<String> removed = new ArrayList<String>();
+
+ for (String key : keys)
+ {
+ if(!added.contains(key))
+ {
+ undeploy(configuration.get(url).get(key));
+ removed.add(key);
+ }
+ }
+ for (String s : removed)
+ {
+ configuration.get(url).remove(s);
+ }
+ }
+ }
+
+ protected Element getRootElement(URL url)
+ throws Exception
+ {
+ return XMLUtil.urlToElement(url);
+ }
+
+ private boolean hasNodeChanged(URL url, Node child, String name)
+ {
+ String newTextContent = child.getTextContent();
+ String origTextContent = configuration.get(url).get(name).getTextContent();
+ return !newTextContent.equals(origTextContent);
+ }
+
+ /**
+ * Undeploys a resource that has been removed
+ * @param url The Resource that was deleted
+ * @throws Exception .
+ */
+ public void undeploy(URL url) throws Exception
+ {
+ Set<String> keys = configuration.get(url).keySet();
+ for (String key : keys)
+ {
+ undeploy(configuration.get(url).get(key));
+ }
+ configuration.remove(url);
+ }
+
+ /**
+ * Deploy the URL for the first time
+ *
+ * @param url The resource todeploy
+ * @throws Exception .
+ */
+ public void deploy(URL url) throws Exception
+ {
+ Element e = getRootElement(url);
+ //find all thenodes to deploy
+ String elements[] = getElementTagName();
+ for (String element : elements)
+ {
+ NodeList children = e.getElementsByTagName(element);
+ for (int i = 0; i < children.getLength(); i++)
+ {
+ Node node = children.item(i);
+ Node keyNode = node.getAttributes().getNamedItem(getKeyAttribute());
+ if(keyNode == null)
+ {
+ log.error("key attribuet missing for configuration " + node);
+ continue;
+ }
+ String name = keyNode.getNodeValue();
+ log.info(new StringBuilder("deploying ").append(name));
+ try
+ {
+ deploy(node);
+ }
+ catch (Exception e1)
+ {
+ log.error(new StringBuilder("Unable to deploy node ").append(node), e1);
+ continue;
+ }
+ addToConfiguration(url, name, node);
+ }
+ }
+ }
+
+ /**
+ * the key attribute for theelement, usually 'name' but can be overridden
+ * @return the key attribute
+ */
+ public String getKeyAttribute()
+ {
+ return NAME_ATTR;
+ }
+
+ //register with the deploymenmt manager
+ public void start() throws Exception
+ {
+
+ }
+
+ //undeploy everything
+ public void stop() throws Exception
+ {
+ Collection<HashMap<String, Node>> urls = configuration.values();
+ for (HashMap<String, Node> hashMap : urls)
+ {
+ for (Node node : hashMap.values())
+ {
+ try
+ {
+ undeploy(node);
+ }
+ catch (Exception e)
+ {
+ log.warn("problem undeploying " + node, e);
+ }
+ }
+ }
+ }
+
+ /**
+ * the names of the elements to deploy
+ * @return the names of the elements todeploy
+ */
+ public abstract String[] getElementTagName();
+
+
+ /**
+ * deploy an element
+ * @param node the element to deploy
+ * @throws Exception .
+ */
+ public abstract void deploy(Node node)
+ throws Exception;
+
+ /**
+ * undeploys an element
+ * @param node the element to undeploy
+ * @throws Exception .
+ */
+ public abstract void undeploy(Node node)
+ throws Exception;
+
+}
Modified: trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java 2008-02-27 13:25:11 UTC (rev 3816)
+++ trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java 2008-02-27 14:17:07 UTC (rev 3817)
@@ -30,6 +30,7 @@
import org.jboss.messaging.core.settings.HierarchicalRepository;
import org.jboss.messaging.core.settings.impl.QueueSettings;
import org.jboss.messaging.core.version.Version;
+import org.jboss.messaging.core.deployers.DeploymentManager;
/**
* This interface defines the internal interface of the Messaging Server exposed
@@ -107,4 +108,6 @@
CreateConnectionResponse createConnection(String username, String password,
String remotingClientSessionID, String clientVMID,
int prefetchSize, String clientAddress) throws Exception;
+
+ DeploymentManager getDeploymentManager();
}
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java 2008-02-27 13:25:11 UTC (rev 3816)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java 2008-02-27 14:17:07 UTC (rev 3817)
@@ -31,6 +31,9 @@
import org.jboss.logging.Logger;
import org.jboss.messaging.core.deployers.impl.QueueSettingsDeployer;
import org.jboss.messaging.core.deployers.impl.SecurityDeployer;
+import org.jboss.messaging.core.deployers.impl.FileDeploymentManager;
+import org.jboss.messaging.core.deployers.DeploymentManager;
+import org.jboss.messaging.core.deployers.Deployer;
import org.jboss.messaging.core.memory.MemoryManager;
import org.jboss.messaging.core.memory.impl.SimpleMemoryManager;
import org.jboss.messaging.core.messagecounter.MessageCounterManager;
@@ -96,9 +99,10 @@
private MemoryManager memoryManager = new SimpleMemoryManager();
private MessageCounterManager messageCounterManager;
private PostOffice postOffice;
- private SecurityDeployer securityDeployer;
- private QueueSettingsDeployer queueSettingsDeployer;
+ private Deployer securityDeployer;
+ private Deployer queueSettingsDeployer;
private AuthenticationManager authenticationManager = new NullAuthenticationManager();
+ private DeploymentManager deploymentManager = new FileDeploymentManager();
// plugins
@@ -163,8 +167,7 @@
securityRepository.setDefault(new HashSet<Role>());
securityStore.setSecurityRepository(securityRepository);
securityStore.setAuthenticationManager(authenticationManager);
- securityDeployer = new SecurityDeployer();
- securityDeployer.setSecurityRepository(securityRepository);
+ securityDeployer = new SecurityDeployer(securityRepository);
queueSettingsRepository.setDefault(new QueueSettings());
scheduledExecutor = new ScheduledThreadPoolExecutor(configuration.getScheduledThreadPoolMaxSize());
queueFactory = new QueueFactoryImpl(queueSettingsRepository, scheduledExecutor);
@@ -193,7 +196,9 @@
remotingService.addFailureListener(connectionManager);
memoryManager.start();
postOffice.start();
- queueSettingsDeployer.start();
+ deploymentManager.start();
+ deploymentManager.registerDeployer(securityDeployer);
+ deploymentManager.registerDeployer(queueSettingsDeployer);
MessagingServerPacketHandler serverPacketHandler = new MessagingServerPacketHandler(this);
getRemotingService().getDispatcher().register(serverPacketHandler);
@@ -228,6 +233,7 @@
// Stop the wired components
securityDeployer.stop();
queueSettingsDeployer.stop();
+ deploymentManager.stop();
connectionManager.stop();
remotingService.removeFailureListener(connectionManager);
connectionManager = null;
@@ -277,6 +283,10 @@
return remotingService;
}
+ public DeploymentManager getDeploymentManager()
+ {
+ return deploymentManager;
+ }
public void enableMessageCounters()
{
Modified: trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerDeployer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerDeployer.java 2008-02-27 13:25:11 UTC (rev 3816)
+++ trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerDeployer.java 2008-02-27 14:17:07 UTC (rev 3817)
@@ -24,6 +24,8 @@
import org.jboss.logging.Logger;
import org.jboss.messaging.core.deployers.Deployer;
import org.jboss.messaging.core.deployers.DeploymentManager;
+import org.jboss.messaging.core.deployers.impl.XmlDeployer;
+import org.jboss.messaging.core.server.MessagingServer;
import org.jboss.messaging.jms.server.JMSServerManager;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -31,12 +33,14 @@
/**
* @author <a href="ataylor at redhat.com">Andy Taylor</a>
*/
-public class JMSServerDeployer extends Deployer
+public class JMSServerDeployer extends XmlDeployer
{
Logger log = Logger.getLogger(JMSServerManagerImpl.class);
private JMSServerManager jmsServerManager;
+ private MessagingServer messagingServer;
+
private static final String CLIENTID_ELEMENT = "client-id";
private static final String DUPS_OK_BATCH_SIZE_ELEMENT = "dups-ok-batch-size";
private static final String PREFETECH_SIZE_ELEMENT = "prefetch-size";
@@ -54,6 +58,11 @@
this.jmsServerManager = jmsServerManager;
}
+ public void setMessagingServer(MessagingServer messagingServer)
+ {
+ this.messagingServer = messagingServer;
+ }
+
/**
* lifecycle method
*/
@@ -61,7 +70,7 @@
{
try
{
- DeploymentManager.getInstance().registerDeployable(this);
+ messagingServer.getDeploymentManager().registerDeployer(this);
}
catch (Exception e)
{
@@ -75,7 +84,7 @@
public void stop() throws Exception
{
super.stop();
- DeploymentManager.getInstance().unregisterDeployable(this);
+ messagingServer.getDeploymentManager().unregisterDeployer(this);
}
/**
Modified: trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/DeployerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/DeployerTest.java 2008-02-27 13:25:11 UTC (rev 3816)
+++ trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/DeployerTest.java 2008-02-27 14:17:07 UTC (rev 3817)
@@ -25,6 +25,7 @@
import junit.framework.TestCase;
import org.jboss.messaging.core.deployers.Deployer;
+import org.jboss.messaging.core.deployers.impl.XmlDeployer;
import org.jboss.messaging.util.XMLUtil;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -168,7 +169,7 @@
assertNull(testDeployer.getNodes().get("test3"));
assertNull(testDeployer.getNodes().get("test4"));
}
- class TestDeployer extends Deployer
+ class TestDeployer extends XmlDeployer
{
private String elementname = "test";
Element element = null;
Modified: trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/SecurityDeployerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/SecurityDeployerTest.java 2008-02-27 13:25:11 UTC (rev 3816)
+++ trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/SecurityDeployerTest.java 2008-02-27 14:17:07 UTC (rev 3817)
@@ -54,17 +54,18 @@
private String noRoles =
" <securityfoo match=\"queues.testQueue\">\n" +
" </securityfoo>";
+ private HierarchicalRepository<HashSet<Role>> repository;
protected void setUp() throws Exception
{
- deployer = new SecurityDeployer();
+ repository = EasyMock.createStrictMock(HierarchicalRepository.class);
+ deployer = new SecurityDeployer(EasyMock.createStrictMock(HierarchicalRepository.class));
}
public void testSingle() throws Exception
{
- HierarchicalRepository<HashSet<Role>> repository = EasyMock.createStrictMock(HierarchicalRepository.class);
- deployer.setSecurityRepository(repository);
+
Element e = XMLUtil.stringToElement(conf);
Role role = new Role("durpublisher", true, true, true);
Role role2 = new Role("guest", true, true, false);
@@ -81,8 +82,6 @@
public void testMultiple() throws Exception
{
- HierarchicalRepository<HashSet<Role>> repository = EasyMock.createStrictMock(HierarchicalRepository.class);
- deployer.setSecurityRepository(repository);
Role role = new Role("durpublisher", true, true, true);
Role role2 = new Role("guest", true, true, false);
Role role3 = new Role("publisher", true, true, false);
@@ -99,8 +98,6 @@
}
public void testNoRolesAdded() throws Exception
{
- HierarchicalRepository<HashSet<Role>> repository = EasyMock.createStrictMock(HierarchicalRepository.class);
- deployer.setSecurityRepository(repository);
HashSet<Role> roles = new HashSet<Role>();
repository.addMatch("queues.testQueue", roles);
EasyMock.replay(repository);
More information about the jboss-cvs-commits
mailing list