''' 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()
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.
# ---------------------------------------------------------
self.thread = None
self.service = None
-
@staticmethod
def find_or_create(thread):
if thread in Session.session_cache:
# 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:
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(
})
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):