diff options
| author | Robert Gemmell <robbie@apache.org> | 2010-05-31 16:01:48 +0000 |
|---|---|---|
| committer | Robert Gemmell <robbie@apache.org> | 2010-05-31 16:01:48 +0000 |
| commit | a2d26b71f141f3166bdd0342b481723d98b0bb99 (patch) | |
| tree | 7e692d05bdf1df9680cdfeff8a68a8412f98043c /java | |
| parent | 71098e50d6a4685205abc4937586ae414b4cee8d (diff) | |
| download | qpid-python-a2d26b71f141f3166bdd0342b481723d98b0bb99.tar.gz | |
QPID-2585: Upgrade Felix to 2.0.5
Applied patch from Andrew Kennedy <andrew.international@gmail.com>
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@949780 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
5 files changed, 254 insertions, 169 deletions
diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugins/Activator.java b/java/broker/src/main/java/org/apache/qpid/server/plugins/Activator.java index 583e480970..df72e87fd8 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/plugins/Activator.java +++ b/java/broker/src/main/java/org/apache/qpid/server/plugins/Activator.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.qpid.server.plugins; +import org.apache.log4j.Logger; import org.apache.qpid.server.configuration.ServerConfiguration; import org.apache.qpid.server.registry.ApplicationRegistry; import org.osgi.framework.BundleActivator; @@ -26,17 +26,21 @@ import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { + private static final Logger _logger = Logger.getLogger(Activator.class); - BundleContext _context = null; + private BundleContext _context = null; public void start(BundleContext ctx) throws Exception { _context = ctx; - ctx.registerService(ServerConfiguration.class.getName(), ApplicationRegistry.getInstance().getConfiguration(), null); + _logger.info("Registering bundle: " + _context.getBundle().getSymbolicName()); + ctx.registerService(ServerConfiguration.class.getName(), ApplicationRegistry.getInstance().getConfiguration(), null); } public void stop(BundleContext ctx) throws Exception - { + { + _logger.info("Stopping bundle: " + _context.getBundle().getSymbolicName()); + _context = null; } public BundleContext getContext() diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugins/Plugin.java b/java/broker/src/main/java/org/apache/qpid/server/plugins/Plugin.java new file mode 100644 index 0000000000..252bd711e8 --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/server/plugins/Plugin.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.server.plugins; + +import org.apache.commons.configuration.ConfigurationException; + +public interface Plugin +{ + /** + * The name of this plugin. + */ + String getPluginName(); + + /** + * Is this plugin configured?. + */ + boolean isConfigured(); + + /** + * Configure this plugin + */ + void configure() throws ConfigurationException; +} diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java b/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java index 58dbe69fa1..bbf3e74a30 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java +++ b/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java @@ -1,5 +1,4 @@ /* - * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,11 +15,17 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - * */ package org.apache.qpid.server.plugins; -public interface PluginFactory +import org.apache.commons.configuration.ConfigurationException; +import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin; + +public interface PluginFactory<P extends Plugin> { + public Class<P> getPluginClass(); + public String getPluginName(); + + public P newInstance(ConfigurationPlugin config) throws ConfigurationException; } diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java b/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java index cba8dda425..9d76e98f4d 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java +++ b/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java @@ -16,180 +16,222 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.qpid.server.plugins; +import static org.apache.felix.framework.util.FelixConstants.*; +import static org.apache.felix.main.AutoProcessor.*; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; + import org.apache.commons.configuration.ConfigurationException; import org.apache.felix.framework.Felix; -import org.apache.felix.framework.util.FelixConstants; import org.apache.felix.framework.util.StringMap; -import org.apache.felix.main.AutoProcessor; +import org.apache.log4j.Logger; import org.apache.qpid.common.Closeable; import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; import org.apache.qpid.server.exchange.ExchangeType; -import org.apache.qpid.server.security.access.ACLPlugin; -import org.apache.qpid.server.security.access.ACLPluginFactory; +import org.apache.qpid.server.security.SecurityPluginFactory; import org.apache.qpid.server.security.access.plugins.AllowAll; import org.apache.qpid.server.security.access.plugins.DenyAll; -import org.apache.qpid.server.security.access.plugins.LegacyAccessPlugin; -import org.apache.qpid.server.security.access.plugins.SimpleXML; -import org.apache.qpid.server.security.access.plugins.network.FirewallPlugin; +import org.apache.qpid.server.security.access.plugins.LegacyAccess; import org.apache.qpid.server.virtualhost.plugins.VirtualHostPluginFactory; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleException; import org.osgi.util.tracker.ServiceTracker; -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - /** - * @author aidan - * - * Provides access to pluggable elements, such as exchanges + * Provides access to pluggable elements, such as exchanges */ - +@SuppressWarnings("unchecked") public class PluginManager implements Closeable { + private static final Logger _logger = Logger.getLogger(PluginManager.class); + + private static final int FELIX_STOP_TIMEOUT = 30000; + private static final String VERSION = "2.6.0.4"; + + private Felix _felix; + private ServiceTracker _exchangeTracker = null; private ServiceTracker _securityTracker = null; private ServiceTracker _configTracker = null; private ServiceTracker _virtualHostTracker = null; - private Felix _felix; - - Activator _activator; + private Activator _activator; - private Map<String, ACLPluginFactory> _securityPlugins; - private static final int FELIX_STOP_TIMEOUT = 30000; + private Map<String, SecurityPluginFactory> _securityPlugins = new HashMap<String, SecurityPluginFactory>(); + private Map<List<String>, ConfigurationPluginFactory> _configPlugins = new IdentityHashMap<List<String>, ConfigurationPluginFactory>(); - public PluginManager(String plugindir) throws Exception + public PluginManager(String pluginPath, String cachePath) throws Exception { - StringMap configMap = new StringMap(false); - - // Add the bundle provided service interface package and the core OSGi - // packages to be exported from the class path via the system bundle. - configMap.put(FelixConstants.FRAMEWORK_SYSTEMPACKAGES, - "org.osgi.framework; version=1.3.0," + - "org.osgi.service.packageadmin; version=1.2.0," + - "org.osgi.service.startlevel; version=1.0.0," + - "org.osgi.service.url; version=1.0.0," + - "org.osgi.util.tracker; version=1.0.0," + - "org.apache.qpid.junit.extensions.util; version=0.7," + - "org.apache.qpid; version=0.7," + - "org.apache.qpid.framing; version=0.7," + - "org.apache.qpid.protocol; version=0.7," + - "org.apache.qpid.server.exchange; version=0.7," + - "org.apache.qpid.server.management; version=0.7," + - "org.apache.qpid.server.protocol; version=0.7," + - "org.apache.qpid.server.virtualhost; version=0.7," + - "org.apache.qpid.server.virtualhost.plugins; version=0.7," + - "org.apache.qpid.server.registry; version=0.7," + - "org.apache.qpid.server.queue; version=0.7," + - "org.apache.qpid.server.binding; version=0.7," + - "org.apache.qpid.server.configuration; version=0.7," + - "org.apache.qpid.server.configuration.plugins; version=0.7," + - "org.apache.qpid.server.configuration.management; version=0.7," + - "org.apache.qpid.server.persistent; version=0.7," + - "org.apache.qpid.server.plugins; version=0.7," + - "org.apache.qpid.server.queue; version=0.7," + - "org.apache.qpid.server.security; version=0.7," + - "org.apache.qpid.framing.AMQShortString; version=0.7," + - "org.apache.qpid.server.queue.AMQQueue; version=0.7," + - "org.apache.qpid.server.security.access; version=0.7," + - "org.apache.commons.configuration; version=0.7," + - "org.apache.log4j; version=1.2.12," + - "javax.management.openmbean; version=1.0.0," + - "javax.management; version=1.0.0," - ); - - if (plugindir == null) + // Store all non-OSGi plugins + // A little gross that we have to add them here, but not all the plugins are OSGIfied + for (SecurityPluginFactory<?> pluginFactory : Arrays.asList( + AllowAll.FACTORY, DenyAll.FACTORY, LegacyAccess.FACTORY)) { - return; + _securityPlugins.put(pluginFactory.getPluginName(), pluginFactory); + } + for (ConfigurationPluginFactory configFactory : Arrays.asList( + AllowAll.AllowAllConfiguration.FACTORY, + DenyAll.DenyAllConfiguration.FACTORY, + LegacyAccess.LegacyAccessConfiguration.FACTORY)) + { + _configPlugins.put(configFactory.getParentPaths(), configFactory); } - // Set the list of bundles to load - File dir = new File(plugindir); - if (!dir.exists()) + // Check the plugin directory path is set and exist + if (pluginPath == null) { return; } + File pluginDir = new File(pluginPath); + if (!pluginDir.exists()) + { + return; + } - StringBuffer pluginJars = new StringBuffer(); + // Setup OSGi configuration propery map + StringMap configMap = new StringMap(false); - if (dir.isDirectory()) + // Add the bundle provided service interface package and the core OSGi + // packages to be exported from the class path via the system bundle. + configMap.put(FRAMEWORK_SYSTEMPACKAGES, + "org.osgi.framework; version=1.3.0," + + "org.osgi.service.packageadmin; version=1.2.0," + + "org.osgi.service.startlevel; version=1.0.0," + + "org.osgi.service.url; version=1.0.0," + + "org.osgi.util.tracker; version=1.0.0," + + "org.apache.qpid.junit.extensions.util; version=0.7," + + "org.apache.qpid; version=0.7," + + "org.apache.qpid.exchange; version=0.7," + + "org.apache.qpid.framing; version=0.7," + + "org.apache.qpid.protocol; version=0.7," + + "org.apache.qpid.server.binding; version=0.7," + + "org.apache.qpid.server.configuration; version=0.7," + + "org.apache.qpid.server.configuration.plugins; version=0.7," + + "org.apache.qpid.server.configuration.management; version=0.7," + + "org.apache.qpid.server.exchange; version=0.7," + + "org.apache.qpid.server.management; version=0.7," + + "org.apache.qpid.server.persistent; version=0.7," + + "org.apache.qpid.server.plugins; version=0.7," + + "org.apache.qpid.server.protocol; version=0.7," + + "org.apache.qpid.server.queue; version=0.7," + + "org.apache.qpid.server.registry; version=0.7," + + "org.apache.qpid.server.security; version=0.7," + + "org.apache.qpid.server.security.access; version=0.7," + + "org.apache.qpid.server.security.access.plugins; version=0.7," + + "org.apache.qpid.server.virtualhost; version=0.7," + + "org.apache.qpid.server.virtualhost.plugins; version=0.7," + + "org.apache.qpid.util; version=0.7," + + "org.apache.commons.configuration; version=1.0.0," + + "org.apache.commons.lang; version=1.0.0," + + "org.apache.commons.lang.builder; version=1.0.0," + + "org.apache.commons.logging; version=1.0.0," + + "org.apache.log4j; version=1.2.12," + + "javax.management.openmbean; version=1.0.0," + + "javax.management; version=1.0.0" + ); + + // No automatic shutdown hook + configMap.put("felix.shutdown.hook", "false"); + + // Add system activator + List<BundleActivator> activators = new ArrayList<BundleActivator>(); + _activator = new Activator(); + activators.add(_activator); + configMap.put(SYSTEMBUNDLE_ACTIVATORS_PROP, activators); + + // Get the list of bundles to load + StringBuffer pluginJars = new StringBuffer(); + if (pluginDir.isDirectory()) { - for (File child : dir.listFiles()) + for (String file : pluginDir.list()) { - if (child.getName().endsWith("jar")) + if (file.endsWith(".jar")) { - pluginJars.append(String.format(" file:%s%s%s", plugindir, File.separator, child.getName())); + pluginJars.append(String.format("file:%s%s%s ", pluginPath, File.separator, file)); } } } - if (pluginJars.length() == 0) - { - return; + if (cachePath != null) + { + File cacheDir = new File(cachePath); + if (!cacheDir.exists() && cacheDir.canWrite()) + { + _logger.info("Creating plugin cache directory: " + cachePath); + cacheDir.mkdir(); + } + + // Set plugin cache directory and empty it + _logger.info("Cache bundles in directory " + cachePath); + configMap.put("org.osgi.framework.storage", cachePath); } - -// configMap.put(FelixConstants.AUTO_START_PROP + ".1", pluginJars.toString()); -// configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, plugindir); - - configMap.put(AutoProcessor.AUTO_START_PROP + ".1", pluginJars.toString()); - - configMap.put(FelixConstants.FRAMEWORK_STORAGE, plugindir); - - - List<BundleActivator> activators = new ArrayList<BundleActivator>(); - _activator = new Activator(); - activators.add(_activator); - configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, activators); - + configMap.put("org.osgi.framework.storage.clean", "onFirstInit"); + + // Set directory with plugins + _logger.info("Auto deploy bundles from directory " + pluginPath); + + // Set list of auto-start plugin JAR files + configMap.put(AUTO_START_PROP + "." + FRAMEWORK_DEFAULT_STARTLEVEL, pluginJars.toString()); + + // FIXME why does this not work? + configMap.put(AUTO_DEPLOY_DIR_PROPERY, pluginPath); + configMap.put(AUTO_DEPLOY_ACTION_PROPERY, AUTO_DEPLOY_START_VALUE); + + // Start plugin manager and trackers _felix = new Felix(configMap); try { - System.out.println("Starting Plugin manager"); - + _logger.info("Starting plugin manager..."); + _felix.init(); + process(configMap, _felix.getBundleContext()); _felix.start(); - - - AutoProcessor.process(configMap, _felix.getBundleContext()); - - System.out.println("Started Plugin manager"); - - _exchangeTracker = new ServiceTracker(_activator.getContext(), ExchangeType.class.getName(), null); - _exchangeTracker.open(); - - _securityTracker = new ServiceTracker(_activator.getContext(), ACLPlugin.class.getName(), null); - _securityTracker.open(); - - _configTracker = new ServiceTracker(_activator.getContext(), ConfigurationPluginFactory.class.getName(), null); - _configTracker.open(); - - _virtualHostTracker = new ServiceTracker(_activator.getContext(), VirtualHostPluginFactory.class.getName(), null); - _virtualHostTracker.open(); - + _logger.info("Started plugin manager"); } catch (BundleException e) { - throw new ConfigurationException("Could not start PluginManager:" + e.getMessage(), e); + throw new ConfigurationException("Could not start plugin manager: " + e.getMessage(), e); } + + // TODO save trackers in a map, keyed by class name + + _exchangeTracker = new ServiceTracker(_activator.getContext(), ExchangeType.class.getName(), null); + _exchangeTracker.open(); + + _securityTracker = new ServiceTracker(_activator.getContext(), SecurityPluginFactory.class.getName(), null); + _securityTracker.open(); + + _configTracker = new ServiceTracker(_activator.getContext(), ConfigurationPluginFactory.class.getName(), null); + _configTracker.open(); + + _virtualHostTracker = new ServiceTracker(_activator.getContext(), VirtualHostPluginFactory.class.getName(), null); + _virtualHostTracker.open(); + + _logger.info("Opened service trackers"); + + // Load security and configuration plugins from their trackers for access + _configPlugins.putAll(getConfigurationServices()); + _securityPlugins.putAll(getPlugins(SecurityPluginFactory.class)); } - private <T> Map<String, T> getServices(ServiceTracker tracker) - { + private static <T> Map<String, T> getServices(ServiceTracker tracker) + { Map<String, T> services = new HashMap<String, T>(); - + if ((tracker != null) && (tracker.getServices() != null)) { for (Object service : tracker.getServices()) { - if (service instanceof PluginFactory) + if (service instanceof PluginFactory<?>) { - services.put(((PluginFactory) service).getPluginName(), (T) service); + services.put(((PluginFactory<?>) service).getPluginName(), (T) service); } else { @@ -201,41 +243,25 @@ public class PluginManager implements Closeable return services; } - public Map<String, ExchangeType<?>> getExchanges() - { - return getServices(_exchangeTracker); - } - - public Map<String, ACLPluginFactory> getSecurityPlugins() - { - _securityPlugins = getServices(_securityTracker); - // A little gross that we have to add them here, but not all the plugins are OSGIfied - _securityPlugins.put(SimpleXML.class.getName(), SimpleXML.FACTORY); - _securityPlugins.put(AllowAll.class.getName(), AllowAll.FACTORY); - _securityPlugins.put(DenyAll.class.getName(), DenyAll.FACTORY); - _securityPlugins.put(LegacyAccessPlugin.class.getName(), LegacyAccessPlugin.FACTORY); - _securityPlugins.put(FirewallPlugin.class.getName(), FirewallPlugin.FACTORY); - - return _securityPlugins; - } - - public Map<String, ConfigurationPluginFactory> getConfigurationPlugins() - { - Map<String, ConfigurationPluginFactory> services = new HashMap<String, ConfigurationPluginFactory>(); - - if ((_configTracker != null) && (_configTracker.getServices() != null)) + private Map<List<String>, ConfigurationPluginFactory> getConfigurationServices() + { + Map<List<String>, ConfigurationPluginFactory> services = new IdentityHashMap<List<String>, ConfigurationPluginFactory>(); + + if (_configTracker.getServices() != null) { for (Object service : _configTracker.getServices()) { - for (String parent : ((ConfigurationPluginFactory) service).getParentPaths()) - { - services.put(parent, ((ConfigurationPluginFactory) service)); - } + ConfigurationPluginFactory factory = (ConfigurationPluginFactory) service; + services.put(factory.getParentPaths(), factory); } } return services; + } + public Map<String, ExchangeType<?>> getExchanges() + { + return getServices(_exchangeTracker); } public Map<String, VirtualHostPluginFactory> getVirtualHostPlugins() @@ -243,7 +269,7 @@ public class PluginManager implements Closeable return getServices(_virtualHostTracker); } - public <P extends PluginFactory> Map<String, P> getPlugins(Class<P> plugin) + public <P extends PluginFactory<?>> Map<String, P> getPlugins(Class<P> plugin) { // If plugins are not configured then return an empty set if (_activator == null) @@ -263,6 +289,16 @@ public class PluginManager implements Closeable tracker.close(); } } + + public Map<String, SecurityPluginFactory> getSecurityPlugins() + { + return _securityPlugins; + } + + public Map<List<String>, ConfigurationPluginFactory> getConfigurationPlugins() + { + return _configPlugins; + } public void close() { @@ -270,25 +306,23 @@ public class PluginManager implements Closeable { try { + // Close all bundle trackers _exchangeTracker.close(); - _securityTracker.close(); - _configTracker.close(); - _virtualHostTracker.close(); } finally { - System.out.println("Stopping Plugin manager"); - //fixme should be stopAndWait() but hangs VM, need upgrade in felix + _logger.info("Stopping plugin manager"); try { + // FIXME should be stopAndWait() but hangs VM, need upgrade in felix _felix.stop(); } catch (BundleException e) { - //ignore + // Ignore } try @@ -297,12 +331,10 @@ public class PluginManager implements Closeable } catch (InterruptedException e) { - //ignore + // Ignore } - - System.out.println("Stopped Plugin manager"); + _logger.info("Stopped plugin manager"); } } } - } diff --git a/java/broker/src/test/java/org/apache/qpid/server/plugins/MockPluginManager.java b/java/broker/src/test/java/org/apache/qpid/server/plugins/MockPluginManager.java index 9599848dde..a64ec5d3b1 100644 --- a/java/broker/src/test/java/org/apache/qpid/server/plugins/MockPluginManager.java +++ b/java/broker/src/test/java/org/apache/qpid/server/plugins/MockPluginManager.java @@ -19,22 +19,21 @@ package org.apache.qpid.server.plugins; import java.util.HashMap; +import java.util.List; import java.util.Map; +import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory; import org.apache.qpid.server.exchange.ExchangeType; -import org.apache.qpid.server.security.access.ACLPlugin; -import org.apache.qpid.server.security.access.ACLPluginFactory; -import org.apache.qpid.server.security.access.QueueDenier; +import org.apache.qpid.server.security.SecurityPluginFactory; public class MockPluginManager extends PluginManager { + private Map<String, SecurityPluginFactory> _securityPlugins = new HashMap<String, SecurityPluginFactory>(); + private Map<List<String>, ConfigurationPluginFactory> _configPlugins = new HashMap<List<String>, ConfigurationPluginFactory>(); - private Map<String, ACLPluginFactory> _securityPlugins = new HashMap<String, ACLPluginFactory>(); - - public MockPluginManager(String plugindir) throws Exception + public MockPluginManager(String pluginPath, String cachePath) throws Exception { - super(plugindir); - _securityPlugins.put("org.apache.qpid.server.security.access.QueueDenier", QueueDenier.FACTORY); + super(pluginPath, cachePath); } @Override @@ -44,8 +43,14 @@ public class MockPluginManager extends PluginManager } @Override - public Map<String, ACLPluginFactory> getSecurityPlugins() + public Map<String, SecurityPluginFactory> getSecurityPlugins() { return _securityPlugins; } + + @Override + public Map<List<String>, ConfigurationPluginFactory> getConfigurationPlugins() + { + return _configPlugins; + } } |
