Replaced ContextResponder with a more generic Destroyable interface.
[jsvc.git] / src / dolda / jsvc / util / PerSession.java
index 7973e0a..0bb1ab0 100644 (file)
@@ -19,11 +19,11 @@ public class PerSession implements Responder {
     private Object makedata(Session sess) {
        try {
            try {
-               return(dcl.getConstructor().newInstance());
+               return(dcl.getConstructor(Session.class).newInstance(sess));
            } catch(NoSuchMethodException e) {
            }
            try {
-               return(dcl.getConstructor(Session.class).newInstance(sess));
+               return(dcl.getConstructor().newInstance());
            } catch(NoSuchMethodException e) {
            }
        } catch(InstantiationException e) {
@@ -88,11 +88,19 @@ public class PerSession implements Responder {
     public void respond(Request req) {
        Session sess = Session.get(req);
        Responder resp;
-       synchronized(sess) {
+       synchronized(this) {
            resp = (Responder)sess.get(rcl, null);
            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);