added a session_data disctionary to ServerSession class for storing per-session data...
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 10 Jun 2009 21:46:00 +0000 (21:46 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 10 Jun 2009 21:46:00 +0000 (21:46 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1717 9efc2488-bf62-4759-914b-345cdb29e865

src/python/osrf/app.py
src/python/osrf/apps/example.py
src/python/osrf/ses.py

index a073f89..45ef2b1 100644 (file)
@@ -102,7 +102,7 @@ class Application(object):
         ''' Find the handler, construct the server request, then run the method '''
 
         req_method = osrf_msg.payload()
-        params = req_method.params()
+        params = req_method.params() or []
         method = Application.methods[req_method.method()]
         handler = method.get_func()
 
index f4b6790..3c219d7 100644 (file)
@@ -47,6 +47,19 @@ class Example(Application):
             idx -= 1
 
     # ---------------------------------------------------------
+
+    Application.register_method(
+        api_name = 'opensrf.stateful_session_test',
+        method = 'session_test',
+        argc = 0
+    )
+
+    def session_test(self, request):
+        c = request.session.session_data.get('counter', 0) + 1
+        request.session.session_data['counter'] = c
+        return c
+
+    # ---------------------------------------------------------
     # These example methods override methods from 
     # osrf.app.Application.  They are not required.
     # ---------------------------------------------------------
index 09182a0..1628f9a 100644 (file)
@@ -46,7 +46,6 @@ class Session(object):
         self.thread = None
         self.service = None
 
-
     @staticmethod
     def find_or_create(thread):
         if thread in Session.session_cache:
@@ -115,7 +114,6 @@ class ClientSession(Session):
         # cache this session in the global session cache
         Session.session_cache[self.thread] = self
 
-
     def reset_request_timeout(self, rid):
         req = self.find_request(rid)
         if req:
@@ -336,7 +334,9 @@ class ServerSession(Session):
     def __init__(self, thread):
         Session.__init__(self)
         self.thread = thread
-        Session.session_cache[thread] = self
+        self.callbacks = {}
+        self.session_data = {}
+        Session.session_cache[self.thread] = self
 
     def send_status(self, thread_trace, payload):
         self.send(
@@ -356,6 +356,11 @@ class ServerSession(Session):
         })
         self.send_status(thread_trace, status_msg)
 
+    def cleanup(self):
+        Session.cleanup(self)
+        if 'death' in self.callbacks:
+            self.callbacks['death'](self)
+
 
 class ServerRequest(Request):