Commit 32f3588d authored by Matt Tucker's avatar Matt Tucker Committed by matt

Move plugin init even earlier. Call the plugin monitor as soon as a new plugin...

Move plugin init even earlier. Call the plugin monitor as soon as a new plugin is installed for speedier user interaction.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4149 b35dd754-fafc-0310-a699-88a17e54d16e
parent d2fa59a9
...@@ -54,6 +54,7 @@ public class PluginManager { ...@@ -54,6 +54,7 @@ public class PluginManager {
private Map<Plugin, List<String>> parentPluginMap; private Map<Plugin, List<String>> parentPluginMap;
private Map<Plugin, String> childPluginMap; private Map<Plugin, String> childPluginMap;
private Set<String> devPlugins; private Set<String> devPlugins;
private PluginMonitor pluginMonitor;
/** /**
* Constructs a new plugin manager. * Constructs a new plugin manager.
...@@ -69,6 +70,7 @@ public class PluginManager { ...@@ -69,6 +70,7 @@ public class PluginManager {
parentPluginMap = new HashMap<Plugin, List<String>>(); parentPluginMap = new HashMap<Plugin, List<String>>();
childPluginMap = new HashMap<Plugin, String>(); childPluginMap = new HashMap<Plugin, String>();
devPlugins = new HashSet<String>(); devPlugins = new HashSet<String>();
pluginMonitor = new PluginMonitor();
} }
/** /**
...@@ -79,10 +81,10 @@ public class PluginManager { ...@@ -79,10 +81,10 @@ public class PluginManager {
// See if we're in development mode. If so, check for new plugins once every 5 seconds. // See if we're in development mode. If so, check for new plugins once every 5 seconds.
// Otherwise, default to every 30 seconds. // Otherwise, default to every 30 seconds.
if (Boolean.getBoolean("developmentMode")) { if (Boolean.getBoolean("developmentMode")) {
executor.scheduleWithFixedDelay(new PluginMonitor(), 1, 5, TimeUnit.SECONDS); executor.scheduleWithFixedDelay(pluginMonitor, 1, 5, TimeUnit.SECONDS);
} }
else { else {
executor.scheduleWithFixedDelay(new PluginMonitor(), 1, 20, TimeUnit.SECONDS); executor.scheduleWithFixedDelay(pluginMonitor, 1, 20, TimeUnit.SECONDS);
} }
} }
...@@ -103,6 +105,7 @@ public class PluginManager { ...@@ -103,6 +105,7 @@ public class PluginManager {
classloaders.clear(); classloaders.clear();
pluginDevelopment.clear(); pluginDevelopment.clear();
childPluginMap.clear(); childPluginMap.clear();
pluginMonitor = null;
} }
/** /**
...@@ -129,6 +132,8 @@ public class PluginManager { ...@@ -129,6 +132,8 @@ public class PluginManager {
new File(absolutePath).delete(); new File(absolutePath).delete();
// Rename temp file to .jar // Rename temp file to .jar
new File(absolutePath + ".part").renameTo(new File(absolutePath)); new File(absolutePath + ".part").renameTo(new File(absolutePath));
// Ask the plugin monitor to update the plugin immediately.
pluginMonitor.run();
} }
catch (IOException e) { catch (IOException e) {
Log.error("Error installing new version of plugin: " + pluginFilename, e); Log.error("Error installing new version of plugin: " + pluginFilename, e);
...@@ -362,6 +367,9 @@ public class PluginManager { ...@@ -362,6 +367,9 @@ public class PluginManager {
classloaders.put(plugin, pluginLoader); classloaders.put(plugin, pluginLoader);
} }
// Check the plugin's database schema (if it requires one).
DbConnectionManager.getSchemaManager().checkPluginSchema(plugin);
// Load any JSP's defined by the plugin. // Load any JSP's defined by the plugin.
File webXML = new File(pluginDir, "web" + File.separator + "WEB-INF" + File webXML = new File(pluginDir, "web" + File.separator + "WEB-INF" +
File.separator + "web.xml"); File.separator + "web.xml");
...@@ -379,12 +387,9 @@ public class PluginManager { ...@@ -379,12 +387,9 @@ public class PluginManager {
pluginDevelopment.put(plugin, dev); pluginDevelopment.put(plugin, dev);
} }
// Check the plugin's database schema (if it requires one). // Init the plugin.
DbConnectionManager.getSchemaManager().checkPluginSchema(plugin);
plugin.initializePlugin(this, pluginDir); plugin.initializePlugin(this, pluginDir);
// If there a <adminconsole> section defined, register it. // If there a <adminconsole> section defined, register it.
Element adminElement = (Element)pluginXML.selectSingleNode("/plugin/adminconsole"); Element adminElement = (Element)pluginXML.selectSingleNode("/plugin/adminconsole");
if (adminElement != null) { if (adminElement != null) {
...@@ -739,8 +744,21 @@ public class PluginManager { ...@@ -739,8 +744,21 @@ public class PluginManager {
*/ */
private class PluginMonitor implements Runnable { private class PluginMonitor implements Runnable {
/**
* Tracks if the monitor is currently running.
*/
private boolean running = false;
public void run() { public void run() {
// If the task is already running, return.
synchronized (this) {
if (running) {
return;
}
running = true;
}
try { try {
running = true;
// Look for extra plugin directories specified as a system property. // Look for extra plugin directories specified as a system property.
String pluginDirs = System.getProperty("pluginDirs"); String pluginDirs = System.getProperty("pluginDirs");
if (pluginDirs != null) { if (pluginDirs != null) {
...@@ -843,7 +861,7 @@ public class PluginManager { ...@@ -843,7 +861,7 @@ public class PluginManager {
while (!deleteDir(dir) && count < 5) { while (!deleteDir(dir) && count < 5) {
Log.error("Error unloading plugin " + pluginName + ". " + Log.error("Error unloading plugin " + pluginName + ". " +
"Will attempt again momentarily."); "Will attempt again momentarily.");
Thread.sleep(5000); Thread.sleep(10000);
count++; count++;
} }
} }
...@@ -859,6 +877,10 @@ public class PluginManager { ...@@ -859,6 +877,10 @@ public class PluginManager {
catch (Throwable e) { catch (Throwable e) {
Log.error(e); Log.error(e);
} }
// Finished running task.
synchronized (this) {
running = false;
}
} }
/** /**
......
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