From 9088dd26a10dcf38d129703356a68139b4c653e2 Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nie@informatik.uni-kiel.de> Date: Mon, 4 Jun 2012 11:49:06 +0200 Subject: [PATCH] Removed some more bugs. --- .../session/CurrentWorkSpaceProjectBean.java | 97 +++++++++++-------- .../java/kieker/webgui/common/ACManager.java | 2 +- 2 files changed, 60 insertions(+), 39 deletions(-) diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentWorkSpaceProjectBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentWorkSpaceProjectBean.java index 955519a8..e457bfd1 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentWorkSpaceProjectBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentWorkSpaceProjectBean.java @@ -70,7 +70,8 @@ import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; /** - * This bean contains the project of the current (session) user for the project work space. + * This bean contains the project of the current (session) user for the project work space. Note: This bean is thread-safe within a session, although a user should + * only use one window at a time. Keep also in mind that due to this fact the synchronization is very simple. * * @author Nils Christian Ehmke * @version 1.0 @@ -309,14 +310,18 @@ public final class CurrentWorkSpaceProjectBean { * project. */ private void reloadClassLoader() { - this.classLoader = FSManager.getInstance().getClassLoader(this.projectName); + synchronized (this) { + this.classLoader = FSManager.getInstance().getClassLoader(this.projectName); + } } /** * This method sets the time stamp to the current system time. */ public void resetTimeStamp() { - this.timeStamp = System.currentTimeMillis(); + synchronized (this) { + this.timeStamp = System.currentTimeMillis(); + } } /** @@ -325,7 +330,9 @@ public final class CurrentWorkSpaceProjectBean { * @return The project name for this user. */ public String getProjectName() { - return this.projectName; + synchronized (this) { + return this.projectName; + } } /** @@ -334,7 +341,9 @@ public final class CurrentWorkSpaceProjectBean { * @return The time stamp for this user. */ public long getTimeStamp() { - return this.timeStamp; + synchronized (this) { + return this.timeStamp; + } } /** @@ -395,10 +404,13 @@ public final class CurrentWorkSpaceProjectBean { try { // Use the file system manager to upload the new file - final MIDependency lib = FSManager.getInstance().uploadLibrary(file, this.projectName); - CurrentWorkSpaceProjectBean.showMessage(FacesMessage.SEVERITY_INFO, "Libary uploaded."); - // As it seem to have worked, we can add the library to our model. - this.project.getDependencies().add(lib); + final MIDependency lib; + synchronized (this) { + lib = FSManager.getInstance().uploadLibrary(file, this.projectName); + CurrentWorkSpaceProjectBean.showMessage(FacesMessage.SEVERITY_INFO, "Libary uploaded."); + // As it seem to have worked, we can add the library to our model. + this.project.getDependencies().add(lib); + } // Update our class loader and the available plugins & repositories this.reloadClassLoader(); this.addToToolPalette(lib); @@ -416,7 +428,9 @@ public final class CurrentWorkSpaceProjectBean { * @return The available libraries. */ public List<Pair<String, String>> getLibraries() { - return FSManager.getInstance().getLibraries(this.projectName); + synchronized (this) { + return FSManager.getInstance().getLibraries(this.projectName); + } } /** @@ -453,15 +467,17 @@ public final class CurrentWorkSpaceProjectBean { * This flag determines whether a newer project should be overwritten. */ public void saveProject(final boolean overwriteNewerProject) { - try { - FSManager.getInstance().saveProject(this.projectName, this.project, this.timeStamp, overwriteNewerProject); - CurrentWorkSpaceProjectBean.showMessage(FacesMessage.SEVERITY_INFO, "Project saved."); - // Update the time stamp! - this.resetTimeStamp(); - } catch (final IOException ex) { - CurrentWorkSpaceProjectBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while saving the projct."); - } catch (final NewerProjectException ex) { - CurrentWorkSpaceProjectBean.showMessage(FacesMessage.SEVERITY_WARN, "The project has been modified externally in the meanwhile."); + synchronized (this) { + try { + FSManager.getInstance().saveProject(this.projectName, this.project, this.timeStamp, overwriteNewerProject); + CurrentWorkSpaceProjectBean.showMessage(FacesMessage.SEVERITY_INFO, "Project saved."); + // Update the time stamp! + this.resetTimeStamp(); + } catch (final IOException ex) { + CurrentWorkSpaceProjectBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while saving the projct."); + } catch (final NewerProjectException ex) { + CurrentWorkSpaceProjectBean.showMessage(FacesMessage.SEVERITY_WARN, "The project has been modified externally in the meanwhile."); + } } } @@ -718,7 +734,6 @@ public final class CurrentWorkSpaceProjectBean { synchronized (this) { this.selectedPlugin = selectedPlugin; this.selectedRepository = null; - System.out.println(this); } } @@ -741,18 +756,20 @@ public final class CurrentWorkSpaceProjectBean { * @return A list with all properties of the plugin plus the name-property. If no plugin is selected, an empty list will be returned. */ public List<Object> getAdvancedPluginProperties() { - final List<Object> result = new ArrayList<Object>(); + synchronized (this) { + final List<Object> result = new ArrayList<Object>(); - // Add the name-property as a string - result.add("Name"); - // Get the original properties of the plugin - if (this.selectedPlugin != null) { - result.addAll(this.selectedPlugin.getProperties()); - } else { - result.addAll(this.selectedRepository.getProperties()); - } + // Add the name-property as a string + result.add("Name"); + // Get the original properties of the plugin + if (this.selectedPlugin != null) { + result.addAll(this.selectedPlugin.getProperties()); + } else { + result.addAll(this.selectedRepository.getProperties()); + } - return result; + return result; + } } /** @@ -762,16 +779,18 @@ public final class CurrentWorkSpaceProjectBean { * @return A list with the available filters. */ public List<MIPlugin> getFilters() { - final EList<MIPlugin> plugins = this.project.getPlugins(); - final List<MIPlugin> filter = new ArrayList<MIPlugin>(); + synchronized (this) { + final EList<MIPlugin> plugins = this.project.getPlugins(); + final List<MIPlugin> filter = new ArrayList<MIPlugin>(); - for (final MIPlugin plugin : plugins) { - if (plugin instanceof MIFilter) { - filter.add(plugin); + for (final MIPlugin plugin : plugins) { + if (plugin instanceof MIFilter) { + filter.add(plugin); + } } - } - return filter; + return filter; + } } /** @@ -827,7 +846,9 @@ public final class CurrentWorkSpaceProjectBean { * @return A list with all repositories within the model. */ public EList<MIRepository> getRepositories() { - return this.project.getRepositories(); + synchronized (this) { + return this.project.getRepositories(); + } } /** diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/ACManager.java b/Kieker.WebGUI/src/main/java/kieker/webgui/common/ACManager.java index 7305b217..5758caf9 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/ACManager.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/common/ACManager.java @@ -250,7 +250,7 @@ public final class ACManager { * @version 1.0 */ @SuppressWarnings("unused") - private class DisplayUpdateThread extends Thread { + private static class DisplayUpdateThread extends Thread { /** * This is the time the thread waits between the updates. -- GitLab