Stamp out lazy loading in the PluginManager. This is an attempt to stamp

out the non-deterministic VariantEvalIntegrationTest errors we've been seeing.


git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4995 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
hanna 2011-01-13 20:58:28 +00:00
parent 2163420942
commit c0031b05ff
1 changed files with 14 additions and 16 deletions

View File

@ -74,10 +74,10 @@ public class PluginManager<PluginType> {
/** /**
* Plugins stored based on their name. * Plugins stored based on their name.
*/ */
private SortedMap<String, Class<? extends PluginType>> pluginsByName = null; private final SortedMap<String, Class<? extends PluginType>> pluginsByName;
private List<Class<? extends PluginType>> plugins; private final List<Class<? extends PluginType>> plugins;
private List<Class<? extends PluginType>> interfaces; private final List<Class<? extends PluginType>> interfaces;
/** /**
* Create a new plugin manager. * Create a new plugin manager.
@ -138,6 +138,12 @@ public class PluginManager<PluginType> {
else else
interfaces.add(type); interfaces.add(type);
} }
pluginsByName = new TreeMap<String, Class<? extends PluginType>>();
for (Class<? extends PluginType> pluginClass : plugins) {
String pluginName = getName(pluginClass);
pluginsByName.put(pluginName, pluginClass);
}
} }
/** /**
@ -161,16 +167,8 @@ public class PluginManager<PluginType> {
} }
} }
protected SortedMap<String, Class<? extends PluginType>> getPluginsByName() { protected Map<String, Class<? extends PluginType>> getPluginsByName() {
if (pluginsByName == null) { return Collections.unmodifiableMap(pluginsByName);
SortedMap<String, Class<? extends PluginType>> newPlugins = new TreeMap<String, Class<? extends PluginType>>();
for (Class<? extends PluginType> pluginClass : plugins) {
String pluginName = getName(pluginClass);
newPlugins.put(pluginName, pluginClass);
}
pluginsByName = newPlugins;
}
return pluginsByName;
} }
/** /**
@ -180,7 +178,7 @@ public class PluginManager<PluginType> {
* @return True if the plugin exists, false otherwise. * @return True if the plugin exists, false otherwise.
*/ */
public boolean exists(String pluginName) { public boolean exists(String pluginName) {
return getPluginsByName().containsKey(pluginName); return pluginsByName.containsKey(pluginName);
} }
/** /**
@ -190,7 +188,7 @@ public class PluginManager<PluginType> {
* @return True if the plugin exists, false otherwise. * @return True if the plugin exists, false otherwise.
*/ */
public boolean exists(Class<?> plugin) { public boolean exists(Class<?> plugin) {
return getPluginsByName().containsValue(plugin); return pluginsByName.containsValue(plugin);
} }
/** /**
@ -231,7 +229,7 @@ public class PluginManager<PluginType> {
* @return The plugin object if found; null otherwise. * @return The plugin object if found; null otherwise.
*/ */
public PluginType createByName(String pluginName) { public PluginType createByName(String pluginName) {
Class<? extends PluginType> plugin = getPluginsByName().get(pluginName); Class<? extends PluginType> plugin = pluginsByName.get(pluginName);
if( plugin == null ) if( plugin == null )
throw new UserException(String.format("Could not find %s with name: %s", pluginCategory,pluginName)); throw new UserException(String.format("Could not find %s with name: %s", pluginCategory,pluginName));
try { try {