From d30a10676cc844c4cc8953348b53bbac133406ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Wed, 2 May 2012 13:53:46 +0200 Subject: Fix State issues. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit – State now copies correctly. – Remove updatedComponents which was not used. --- same/src/main/java/com/orbekk/same/State.java | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'same/src') diff --git a/same/src/main/java/com/orbekk/same/State.java b/same/src/main/java/com/orbekk/same/State.java index e62fbee..ce4f18d 100644 --- a/same/src/main/java/com/orbekk/same/State.java +++ b/same/src/main/java/com/orbekk/same/State.java @@ -38,7 +38,6 @@ public class State { private Logger logger = LoggerFactory.getLogger(getClass()); private Map state = new HashMap(); private ObjectMapper mapper = new ObjectMapper(); - private Set updatedComponents = new TreeSet(); public static final String PARTICIPANTS = ".participants0"; @@ -49,11 +48,12 @@ public class State { } public State(State other) { - state.putAll(other.state); + for (Component c : other.getComponents()) { + state.put(c.getName(), c); + } } public synchronized void clear() { - updatedComponents.clear(); state.clear(); } @@ -62,7 +62,6 @@ public class State { Component oldComponent = state.get(componentName); Component newComponent = new Component(componentName, revision, data); state.put(componentName, newComponent); - updatedComponents.add(componentName); } public synchronized boolean update(String componentName, String data, @@ -75,12 +74,8 @@ public class State { } if (revision > component.getRevision()) { - Component oldComponent = new Component(component); - component.setName(componentName); - component.setRevision(revision); - component.setData(data); - state.put(componentName, component); - updatedComponents.add(componentName); + Component newComponent = new Component(componentName, revision, data); + state.put(componentName, newComponent); return true; } else { return false; @@ -187,15 +182,6 @@ public class State { return list; } - public synchronized List getAndClearUpdatedComponents() { - List components = new ArrayList(); - for (String name : updatedComponents) { - components.add(state.get(name)); - } - updatedComponents.clear(); - return components; - } - public static class Component { private String name; private long revision; -- cgit v1.2.3