|
|
@ -19,6 +19,7 @@ import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
@ -163,6 +164,34 @@ public class DefaultPluginManager implements PluginManager { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Start the specified plugin and it's dependencies. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public PluginState startPlugin(String pluginId) { |
|
|
|
|
|
|
|
if (!plugins.containsKey(pluginId)) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException(String.format("Unknown pluginId %s", pluginId)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
PluginWrapper pluginWrapper = plugins.get(pluginId); |
|
|
|
|
|
|
|
PluginDescriptor pluginDescriptor = pluginWrapper.getDescriptor(); |
|
|
|
|
|
|
|
if (pluginWrapper.getPluginState().equals(PluginState.STARTED)) { |
|
|
|
|
|
|
|
log.debug("Already started plugin '{}:{}'", pluginDescriptor.getPluginId(), pluginDescriptor.getVersion()); |
|
|
|
|
|
|
|
return PluginState.STARTED; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (PluginDependency dependency : pluginDescriptor.getDependencies()) { |
|
|
|
|
|
|
|
startPlugin(dependency.getPluginId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
log.info("Start plugin '{}:{}'", pluginDescriptor.getPluginId(), pluginDescriptor.getVersion()); |
|
|
|
|
|
|
|
pluginWrapper.getPlugin().start(); |
|
|
|
|
|
|
|
pluginWrapper.setPluginState(PluginState.STARTED); |
|
|
|
|
|
|
|
startedPlugins.add(pluginWrapper); |
|
|
|
|
|
|
|
} catch (PluginException e) { |
|
|
|
|
|
|
|
log.error(e.getMessage(), e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return pluginWrapper.getPluginState(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Stop all active plugins. |
|
|
|
* Stop all active plugins. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -170,17 +199,49 @@ public class DefaultPluginManager implements PluginManager { |
|
|
|
public void stopPlugins() { |
|
|
|
public void stopPlugins() { |
|
|
|
// stop started plugins in reverse order
|
|
|
|
// stop started plugins in reverse order
|
|
|
|
Collections.reverse(startedPlugins); |
|
|
|
Collections.reverse(startedPlugins); |
|
|
|
for (PluginWrapper pluginWrapper : startedPlugins) { |
|
|
|
Iterator<PluginWrapper> itr = startedPlugins.iterator(); |
|
|
|
|
|
|
|
while (itr.hasNext()) { |
|
|
|
|
|
|
|
PluginWrapper pluginWrapper = itr.next(); |
|
|
|
|
|
|
|
PluginDescriptor pluginDescriptor = pluginWrapper.getDescriptor(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
log.info("Stop plugin '{}'", pluginWrapper.getDescriptor().getPluginId()); |
|
|
|
log.info("Stop plugin '{}:{}'", pluginDescriptor.getPluginId(), pluginDescriptor.getVersion()); |
|
|
|
pluginWrapper.getPlugin().stop(); |
|
|
|
pluginWrapper.getPlugin().stop(); |
|
|
|
pluginWrapper.setPluginState(PluginState.STOPPED); |
|
|
|
pluginWrapper.setPluginState(PluginState.STOPPED); |
|
|
|
|
|
|
|
itr.remove(); |
|
|
|
} catch (PluginException e) { |
|
|
|
} catch (PluginException e) { |
|
|
|
log.error(e.getMessage(), e); |
|
|
|
log.error(e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Stop the specified plugin and it's dependencies. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public PluginState stopPlugin(String pluginId) { |
|
|
|
|
|
|
|
if (!plugins.containsKey(pluginId)) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException(String.format("Unknown pluginId %s", pluginId)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
PluginWrapper pluginWrapper = plugins.get(pluginId); |
|
|
|
|
|
|
|
PluginDescriptor pluginDescriptor = pluginWrapper.getDescriptor(); |
|
|
|
|
|
|
|
if (pluginWrapper.getPluginState().equals(PluginState.STOPPED)) { |
|
|
|
|
|
|
|
log.debug("Already stopped plugin '{}:{}'", pluginDescriptor.getPluginId(), pluginDescriptor.getVersion()); |
|
|
|
|
|
|
|
return PluginState.STOPPED; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (PluginDependency dependency : pluginDescriptor.getDependencies()) { |
|
|
|
|
|
|
|
stopPlugin(dependency.getPluginId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
log.info("Stop plugin '{}:{}'", pluginDescriptor.getPluginId(), pluginDescriptor.getVersion()); |
|
|
|
|
|
|
|
pluginWrapper.getPlugin().stop(); |
|
|
|
|
|
|
|
pluginWrapper.setPluginState(PluginState.STOPPED); |
|
|
|
|
|
|
|
startedPlugins.remove(pluginWrapper); |
|
|
|
|
|
|
|
} catch (PluginException e) { |
|
|
|
|
|
|
|
log.error(e.getMessage(), e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return pluginWrapper.getPluginState(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Load plugins. |
|
|
|
* Load plugins. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -233,6 +294,45 @@ public class DefaultPluginManager implements PluginManager { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean unloadPlugin(String pluginId) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
PluginState state = stopPlugin(pluginId); |
|
|
|
|
|
|
|
if (!PluginState.STOPPED.equals(state)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PluginWrapper pluginWrapper = plugins.get(pluginId); |
|
|
|
|
|
|
|
PluginDescriptor descriptor = pluginWrapper.getDescriptor(); |
|
|
|
|
|
|
|
List<PluginDependency> dependencies = descriptor.getDependencies(); |
|
|
|
|
|
|
|
for (PluginDependency dependency : dependencies) { |
|
|
|
|
|
|
|
if (!unloadPlugin(dependency.getPluginId())) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// remove the plugin
|
|
|
|
|
|
|
|
plugins.remove(pluginId); |
|
|
|
|
|
|
|
resolvedPlugins.remove(pluginWrapper); |
|
|
|
|
|
|
|
pathToIdMap.remove(pluginWrapper.getPluginPath()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// remove the classloader
|
|
|
|
|
|
|
|
if (pluginClassLoaders.containsKey(pluginId)) { |
|
|
|
|
|
|
|
PluginClassLoader classLoader = pluginClassLoaders.remove(pluginId); |
|
|
|
|
|
|
|
compoundClassLoader.removeLoader(classLoader); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
classLoader.close(); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
log.error(e.getMessage(), e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} catch (IllegalArgumentException e) { |
|
|
|
|
|
|
|
// ignore not found exceptions because this method is recursive
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get plugin class loader for this path. |
|
|
|
* Get plugin class loader for this path. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|