/** @see ContainerService#shutdown() */ public void shutdown() { // Inform the plugins we are shutting them down. // We want to shut them down in the reverse order that we initialized them. Collections.reverse(this.loadedPlugins); for (Plugin plugin : loadedPlugins) { PluginLifecycleListener listener = pluginLifecycleListenerMgr.getListener(plugin.getName()); if (listener != null) { try { ClassLoader originalCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread() .setContextClassLoader( this.classLoaderManager.obtainPluginClassLoader(plugin.getName())); try { listener.shutdown(); } finally { Thread.currentThread().setContextClassLoader(originalCL); } } catch (Throwable t) { log.warn( "Failed to get lifecycle listener to shutdown [" + plugin.getName() + "]. Cause: " + ThrowableUtil.getAllMessages(t)); } } } // Clean up the plugin environment and the temp dirs that were used by the plugin classloaders. for (PluginEnvironment pluginEnvironment : this.loadedPluginEnvironments.values()) { pluginEnvironment.destroy(); } this.classLoaderManager.destroy(); this.loadedPluginEnvironments.clear(); this.loadedPlugins.clear(); pluginLifecycleListenerMgr.shutdown(); }
/** * This will create a {@link PluginEnvironment} for the plugin at the given URL. The plugin's * descriptor is parsed. Once this method returns, the plugin's components are ready to be created * and used. * * @param pluginUrl the new plugin's jar location * @param classLoader the new plugin's classloader * @param pluginDescriptor the already parsed plugin descriptor for this plugin * @throws PluginContainerException if the plugin fails to load */ private void loadPlugin(URL pluginUrl, ClassLoader classLoader, PluginDescriptor pluginDescriptor) throws PluginContainerException { if (log.isDebugEnabled()) { log.debug("Loading plugin from [" + pluginUrl + "] in classloader [" + classLoader + "]..."); } PluginDescriptorLoader pluginDescriptorLoader = new PluginDescriptorLoader(pluginUrl, classLoader); PluginEnvironment pluginEnvironment = new PluginEnvironment(pluginDescriptor.getName(), pluginDescriptorLoader); String pluginName = pluginEnvironment.getPluginName(); // tell the plugin we have loaded it PluginLifecycleListener overseer = getPluginLifecycleListener(pluginName, pluginEnvironment, pluginDescriptor); if (overseer != null) { PluginContext context = createPluginContext(pluginName); ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(classLoader); overseer.initialize(context); } catch (Throwable t) { throw new PluginContainerException( "Plugin Lifecycle Listener failed to initialize plugin", t); } finally { Thread.currentThread().setContextClassLoader(originalContextClassLoader); } } // everything is loaded and initialized this.loadedPluginEnvironments.put(pluginName, pluginEnvironment); this.metadataManager.loadPlugin(pluginDescriptor); pluginLifecycleListenerMgr.setListener(pluginDescriptor.getName(), overseer); updateLoadedPlugins.execute(pluginDescriptor, pluginUrl); }