Commit fae2712b authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Plugin that fails to be unloaded is not loaded again. JM-1092

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8661 b35dd754-fafc-0310-a699-88a17e54d16e
parent eb94fbb8
......@@ -563,6 +563,28 @@ public class PluginManager {
catch (Exception e) {
Log.error(e);
}
// Try to remove the folder where the plugin was exploded. If this works then
// the plugin was successfully removed. Otherwise, some objects created by the
// plugin are still in memory.
File dir = new File(pluginDirectory, pluginName);
// Give the plugin 2 seconds to unload.
try {
Thread.sleep(2000);
// Ask the system to clean up references.
System.gc();
int count = 0;
while (!deleteDir(dir) && count < 5) {
Log.warn("Error unloading plugin " + pluginName + ". " + "Will attempt again momentarily.");
Thread.sleep(8000);
count++;
// Ask the system to clean up references.
System.gc();
}
} catch (InterruptedException e) {
Log.error(e);
}
if (!dir.exists()) {
plugins.remove(pluginName);
pluginDirs.remove(plugin);
classloaders.remove(plugin);
......@@ -575,6 +597,7 @@ public class PluginManager {
childPluginMap.remove(plugin);
firePluginDestroyedEvent(pluginName, plugin);
}
}
private void firePluginDestroyedEvent(String name, Plugin plugin) {
for (PluginListener listener : pluginListeners) {
......@@ -874,21 +897,8 @@ public class PluginManager {
// needs to be unloaded and then reloaded.
else if (jarFile.lastModified() > dir.lastModified()) {
unloadPlugin(pluginName);
// Give the plugin 2 seconds to unload.
Thread.sleep(2000);
// Ask the system to clean up references.
System.gc();
int count = 0;
while (!deleteDir(dir) && count < 5) {
Log.warn("Error unloading plugin " + pluginName + ". " +
"Will attempt again momentarily.");
Thread.sleep(8000);
count++;
// Ask the system to clean up references.
System.gc();
}
// If the delete operation was a success, unzip the plugin.
if (count != 5) {
if (!dir.exists()) {
unzipPlugin(pluginName, jarFile, dir);
}
}
......@@ -940,15 +950,6 @@ public class PluginManager {
}
for (String pluginName : toDelete) {
unloadPlugin(pluginName);
System.gc();
int count = 0;
File dir = new File(pluginDirectory, pluginName);
while (!deleteDir(dir) && count < 5) {
Log.error("Error unloading plugin " + pluginName + ". " +
"Will attempt again momentarily.");
Thread.sleep(10000);
count++;
}
}
// Load all plugins that need to be loaded.
......@@ -1076,6 +1077,8 @@ public class PluginManager {
}
}
}
/**
* Deletes a directory.
*
......@@ -1117,7 +1120,6 @@ public class PluginManager {
}
return deleted;
}
}
public void addPluginListener(PluginListener listener) {
pluginListeners.add(listener);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment