Commit 38d88152 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Bug fixes for reloading and unloading plugins.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@866 b35dd754-fafc-0310-a699-88a17e54d16e
parent 7b63be2c
...@@ -27,7 +27,6 @@ import java.util.zip.ZipFile; ...@@ -27,7 +27,6 @@ import java.util.zip.ZipFile;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* Loads and manages plugins. The <tt>plugins</tt> directory is monitored for any * Loads and manages plugins. The <tt>plugins</tt> directory is monitored for any
...@@ -51,7 +50,7 @@ public class PluginManager { ...@@ -51,7 +50,7 @@ public class PluginManager {
*/ */
public PluginManager(File pluginDir) { public PluginManager(File pluginDir) {
this.pluginDirectory = pluginDir; this.pluginDirectory = pluginDir;
plugins = new ConcurrentHashMap<String,Plugin>(); plugins = new HashMap<String,Plugin>();
classloaders = new HashMap<Plugin,PluginClassLoader>(); classloaders = new HashMap<Plugin,PluginClassLoader>();
} }
...@@ -219,10 +218,12 @@ public class PluginManager { ...@@ -219,10 +218,12 @@ public class PluginManager {
// needs to be unloaded and then reloaded. // needs to be unloaded and then reloaded.
else if (jarFile.lastModified() > dir.lastModified()) { else if (jarFile.lastModified() > dir.lastModified()) {
unloadPlugin(pluginName); unloadPlugin(pluginName);
if (!deleteDir(dir)) { // Ask the system to clean up references.
System.gc();
while (!deleteDir(dir)) {
Log.error("Error unloading plugin " + pluginName + ". " + Log.error("Error unloading plugin " + pluginName + ". " +
"You must manually delete the plugin directory."); "Will attempt again momentarily.");
continue; Thread.sleep(5000);
} }
// Now unzip the plugin. // Now unzip the plugin.
unzipPlugin(pluginName, jarFile, dir); unzipPlugin(pluginName, jarFile, dir);
...@@ -257,21 +258,28 @@ public class PluginManager { ...@@ -257,21 +258,28 @@ public class PluginManager {
} }
} }
// Finally see if any currently running plugins need to be unloaded // See if any currently running plugins need to be unloaded
// due to its JAR file being deleted (ignore admin plugin). // due to its JAR file being deleted (ignore admin plugin).
if (plugins.size() > jars.length + 1) { if (plugins.size() > jars.length + 1) {
// Build a list of plugins to delete first so that the plugins
// keyset is modified as we're iterating through it.
List<String> toDelete = new ArrayList<String>();
for (String pluginName : plugins.keySet()) { for (String pluginName : plugins.keySet()) {
if (pluginName.equals("admin")) { if (pluginName.equals("admin")) {
continue; continue;
} }
File file = new File(pluginDirectory, pluginName + ".jar"); File file = new File(pluginDirectory, pluginName + ".jar");
if (!file.exists()) { if (!file.exists()) {
unloadPlugin(pluginName); toDelete.add(pluginName);
if (!deleteDir(new File(pluginDirectory, pluginName))) { }
Log.error("Error unloading plugin " + pluginName + ". " + }
"You must manually delete the plugin directory."); for (String pluginName : toDelete) {
continue; unloadPlugin(pluginName);
} System.gc();
while (!deleteDir(new File(pluginDirectory, pluginName))) {
Log.error("Error unloading plugin " + pluginName + ". " +
"Will attempt again momentarily.");
Thread.sleep(5000);
} }
} }
} }
...@@ -319,6 +327,8 @@ public class PluginManager { ...@@ -319,6 +327,8 @@ public class PluginManager {
zin.close(); zin.close();
} }
} }
zipFile.close();
zipFile = null;
} }
catch (Exception e) { catch (Exception e) {
Log.error(e); Log.error(e);
......
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