From: erickson Date: Wed, 10 Jun 2009 21:46:00 +0000 (+0000) Subject: added a session_data disctionary to ServerSession class for storing per-session data... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b6150be40e75dc5f9d10cf297d025ac16954101b;p=opensrf%2Fbjwebb.git added a session_data disctionary to ServerSession class for storing per-session data. fixed bug where no params caused serer-side confusion. added exmample of session_data usage to example app git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1717 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/python/osrf/app.py b/src/python/osrf/app.py index a073f89..45ef2b1 100644 --- a/src/python/osrf/app.py +++ b/src/python/osrf/app.py @@ -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() diff --git a/src/python/osrf/apps/example.py b/src/python/osrf/apps/example.py index f4b6790..3c219d7 100644 --- a/src/python/osrf/apps/example.py +++ b/src/python/osrf/apps/example.py @@ -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. # --------------------------------------------------------- diff --git a/src/python/osrf/ses.py b/src/python/osrf/ses.py index 09182a0..1628f9a 100644 --- a/src/python/osrf/ses.py +++ b/src/python/osrf/ses.py @@ -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):