Skip to content
Snippets Groups Projects
Commit 7139168b authored by Nils Christian Ehmke's avatar Nils Christian Ehmke
Browse files

Added Caches for a faster searching within the jar-files, Observer-Update is still missing though.

parent a0578fa8
No related branches found
No related tags found
No related merge requests found
...@@ -89,7 +89,7 @@ public class ProjectsBean { ...@@ -89,7 +89,7 @@ public class ProjectsBean {
if (FileManager.getInstance().saveNewProject(project)) { if (FileManager.getInstance().saveNewProject(project)) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "", "New Project: " + projectName)); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "", "New Project: " + projectName));
this.projects.add(project); this.projects.add(project);
RequestContext.getCurrentInstance().addPartialUpdateTarget("projectsForm"); RequestContext.getCurrentInstance().addPartialUpdateTarget("projectsForm");
} else { } else {
/* Inform the user about the fail. */ /* Inform the user about the fail. */
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "A project with this name exists already.")); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "A project with this name exists already."));
......
...@@ -31,15 +31,25 @@ import java.util.jar.JarFile; ...@@ -31,15 +31,25 @@ import java.util.jar.JarFile;
import kieker.analysis.plugin.AbstractPlugin; import kieker.analysis.plugin.AbstractPlugin;
import kieker.analysis.plugin.annotation.Plugin; import kieker.analysis.plugin.annotation.Plugin;
import kieker.analysis.repository.AbstractRepository; import kieker.analysis.repository.AbstractRepository;
import sun.misc.Cache;
/** /**
* This tool class can be used to find all plugins and repositories within a given jar file - assuming that the <code>PluginClassLoader</code> knows these jars. * This tool class can be used to find all plugins and repositories within a given jar file - assuming that the <code>PluginClassLoader</code> knows these jars.
* *
* @author Nils Christian Ehmke * @author Nils Christian Ehmke
* @version 1.0 * @version 1.0
* TODO Cache and observer update!
*/ */
public final class PluginFinder { public final class PluginFinder {
private static final Cache PLUGIN_CACHE;
private static final Cache REPOSITORY_CACHE;
static {
PLUGIN_CACHE = new Cache(15);
REPOSITORY_CACHE = new Cache(15);
}
/** /**
* Creates a new instance of this class. * Creates a new instance of this class.
*/ */
...@@ -56,6 +66,10 @@ public final class PluginFinder { ...@@ -56,6 +66,10 @@ public final class PluginFinder {
*/ */
public static List<Class<AbstractRepository>> getAllRepositoriesWithinJar(final URL url) { public static List<Class<AbstractRepository>> getAllRepositoriesWithinJar(final URL url) {
// TODO: Merge this with the other method // TODO: Merge this with the other method
final List<Class<AbstractRepository>> repositoryClasses = (List<Class<AbstractRepository>>) REPOSITORY_CACHE.get(url);
if (repositoryClasses != null) {
return repositoryClasses;
}
try { try {
/* /*
* Open the jar file and run through all entries within this file. * Open the jar file and run through all entries within this file.
...@@ -82,6 +96,7 @@ public final class PluginFinder { ...@@ -82,6 +96,7 @@ public final class PluginFinder {
} }
} }
jarFile.close(); jarFile.close();
REPOSITORY_CACHE.put(url, result);
return result; return result;
} catch (final IOException ex) { } catch (final IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
...@@ -98,6 +113,10 @@ public final class PluginFinder { ...@@ -98,6 +113,10 @@ public final class PluginFinder {
* @return A list containing all available plugin-classes or null, if an exception occurred. * @return A list containing all available plugin-classes or null, if an exception occurred.
*/ */
public static List<Class<AbstractPlugin>> getAllPluginsWithinJar(final URL url) { public static List<Class<AbstractPlugin>> getAllPluginsWithinJar(final URL url) {
final List<Class<AbstractPlugin>> pluginClasses = (List<Class<AbstractPlugin>>) PLUGIN_CACHE.get(url);
if (pluginClasses != null) {
return pluginClasses;
}
try { try {
/* /*
* Open the jar file and run through all entries within this file. * Open the jar file and run through all entries within this file.
...@@ -127,6 +146,7 @@ public final class PluginFinder { ...@@ -127,6 +146,7 @@ public final class PluginFinder {
} }
} }
jarFile.close(); jarFile.close();
PLUGIN_CACHE.put(url, result);
return result; return result;
} catch (final IOException ex) { } catch (final IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment