From 919138305d240babf0ab7aaf51d70b8b23884cbd Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Tue, 29 Mar 2011 02:05:05 +0200 Subject: [PATCH] Use Destroyable values instead of session listeners. --- src/dolda/jsvc/util/PerSession.java | 8 -------- src/dolda/jsvc/util/Session.java | 19 +++++-------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/dolda/jsvc/util/PerSession.java b/src/dolda/jsvc/util/PerSession.java index 0bb1ab0..d4e4d73 100644 --- a/src/dolda/jsvc/util/PerSession.java +++ b/src/dolda/jsvc/util/PerSession.java @@ -93,14 +93,6 @@ public class PerSession implements Responder { if(resp == null) { resp = create(sess); sess.put(rcl, resp); - if(resp instanceof Destroyable) { - final Destroyable cr = (Destroyable)resp; - sess.listen(new Session.Listener() { - public void destroy(Session sess) { - cr.destroy(); - } - }); - } } } resp.respond(req); diff --git a/src/dolda/jsvc/util/Session.java b/src/dolda/jsvc/util/Session.java index 01c6d16..7b87d12 100644 --- a/src/dolda/jsvc/util/Session.java +++ b/src/dolda/jsvc/util/Session.java @@ -9,11 +9,6 @@ public abstract class Session implements java.io.Serializable { private static final Map cache = new WeakHashMap(); private final Map props = new IdentityHashMap(); public long ctime = System.currentTimeMillis(), atime = ctime, etime = 86400 * 1000; - private Collection ll = new HashSet(); - - public static interface Listener { - public void destroy(Session sess); - } public static interface Storage { public Session get(Request req); @@ -154,12 +149,6 @@ public abstract class Session implements java.io.Serializable { public abstract String id(); - public void listen(Listener l) { - synchronized(ll) { - ll.add(l); - } - } - public Object get(Object key, Object def) { synchronized(props) { if(props.containsKey(key)) @@ -174,9 +163,11 @@ public abstract class Session implements java.io.Serializable { } public void destroy() { - synchronized(ll) { - for(Listener l : ll) - l.destroy(this); + synchronized(props) { + for(Object val : props.values()) { + if(val instanceof Destroyable) + ((Destroyable)val).destroy(); + } } } -- 2.11.0