registerServerPlugin(file);
}
this.scanned.clear();
// we now have to see if the state of existing plugins have changed in the DB
ServerPluginManagerLocal serverPluginsManager = LookupUtil.getServerPluginManager();
List<ServerPlugin> allPlugins = serverPluginsManager.getAllServerPlugins();
List<ServerPlugin> installedPlugins = new ArrayList<ServerPlugin>();
List<ServerPlugin> undeployedPlugins = new ArrayList<ServerPlugin>();
for (ServerPlugin plugin : allPlugins) {
if (plugin.getStatus() == PluginStatusType.INSTALLED) {
installedPlugins.add(plugin);
} else {
undeployedPlugins.add(plugin);
}
}
// first, have any plugins been undeployed since we last checked?
for (ServerPlugin undeployedPlugin : undeployedPlugins) {
File undeployedFile = new File(this.getServerPluginDir(), undeployedPlugin.getPath());
PluginWithDescriptor pluginWithDescriptor = this.serverPluginsOnFilesystem.get(undeployedFile);
if (pluginWithDescriptor != null) {
try {
log.info("Plugin file [" + undeployedFile + "] has been undeployed. It will be deleted.");
List<Integer> id = Arrays.asList(undeployedPlugin.getId());
serverPluginsManager.deleteServerPlugins(LookupUtil.getSubjectManager().getOverlord(), id);
} finally {
this.serverPluginsOnFilesystem.remove(undeployedFile);
}
}
}
// now see if any plugins changed state from enabled->disabled or vice versa
// this also checks to see if the plugin configuration has changed since it was last loaded
MasterServerPluginContainer master = LookupUtil.getServerPluginService().getMasterPluginContainer();
if (master != null) {
for (ServerPlugin installedPlugin : installedPlugins) {
PluginKey key = PluginKey.createServerPluginKey(installedPlugin.getType(), installedPlugin.getName());
AbstractTypeServerPluginContainer pc = master.getPluginContainerByPlugin(key);
if (pc != null && pc.isPluginLoaded(key)) {
boolean needToReloadPlugin = false;
boolean currentlyEnabled = pc.isPluginEnabled(key);
if (installedPlugin.isEnabled() != currentlyEnabled) {
log.info("Detected a state change to plugin [" + key + "]. It will now be "
+ ((installedPlugin.isEnabled()) ? "[enabled]" : "[disabled]"));
needToReloadPlugin = true;
} else {
Long pluginLoadTime = pc.getPluginLoadTime(key);
if (pluginLoadTime != null) {
long configChangeTimestamp = serverPluginsManager
.getLastConfigurationChangeTimestamp(installedPlugin.getId());
if (configChangeTimestamp > pluginLoadTime) {
// since the last time the plugin was loaded, its configuration has changed, reload it to pick up the new config
log.info("Detected a config change to plugin [" + key + "]. It will be reloaded and "
+ ((installedPlugin.isEnabled()) ? "[enabled]" : "[disabled]"));