From 37606bf64f2829258cc612e730782e081e2ac6bb Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 13 Jan 2012 10:57:59 -0500 Subject: [PATCH] Python libs for OpenSRF ingress tracking osrf.ses.Session.ingress(ingress) This also set the "srfsh" ingress value for srfsh.py. Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander --- src/python/osrf/ses.py | 12 +++++++++++- src/python/osrf/stack.py | 2 ++ src/python/srfsh.py | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/python/osrf/ses.py b/src/python/osrf/ses.py index 15e1f10..6fd2d24 100644 --- a/src/python/osrf/ses.py +++ b/src/python/osrf/ses.py @@ -25,7 +25,7 @@ import random, os, time, threading # ----------------------------------------------------------------------- # Go ahead and register the common network objects # ----------------------------------------------------------------------- -osrf.net_obj.register_hint('osrfMessage', ['threadTrace', 'locale', 'type', 'payload'], 'hash') +osrf.net_obj.register_hint('osrfMessage', ['threadTrace', 'locale', 'type', 'payload', 'ingress'], 'hash') osrf.net_obj.register_hint('osrfMethod', ['method', 'params'], 'hash') osrf.net_obj.register_hint('osrfResult', ['status', 'statusCode', 'content'], 'hash') osrf.net_obj.register_hint('osrfConnectStatus', ['status', 'statusCode'], 'hash') @@ -37,6 +37,7 @@ class Session(object): ''' Global cache of in-service sessions ''' session_cache = {} + current_ingress = 'opensrf'; def __init__(self): # by default, we're connected to no one @@ -52,6 +53,12 @@ class Session(object): return Session.session_cache[thread] return ServerSession(thread) + @staticmethod + def ingress(ingress): + if ingress: + Session.current_ingress = ingress + return Session.current_ingress + def set_remote_id(self, remoteid): self.remote_id = remoteid osrf.log.log_internal("Setting request remote ID to %s" % self.remote_id) @@ -66,6 +73,9 @@ class Session(object): """Sends an OpenSRF message""" if not isinstance(omessages, list): omessages = [omessages] + + for msg in omessages: + msg.ingress(Session.current_ingress); net_msg = osrf.net.NetworkMessage( recipient = self.remote_id, diff --git a/src/python/osrf/stack.py b/src/python/osrf/stack.py index cc5a4dc..ddecf69 100644 --- a/src/python/osrf/stack.py +++ b/src/python/osrf/stack.py @@ -43,6 +43,8 @@ def handle_message(session, message): osrf.log.log_internal("handle_message(): processing message of " "type %s" % message.type()) + osrf.ses.Session.ingress(message.ingress()) + if isinstance(session, osrf.ses.ClientSession): handle_client(session, message) else: diff --git a/src/python/srfsh.py b/src/python/srfsh.py index ba90c7a..5dfc8ee 100755 --- a/src/python/srfsh.py +++ b/src/python/srfsh.py @@ -410,6 +410,7 @@ class Srfsh(object): def do_connect(self): ''' Connects this instance to the OpenSRF network. ''' + osrf.ses.Session.ingress('srfsh') file = os.path.join(self.get_var('HOME'), ".srfsh.xml") osrf.system.System.connect(config_file=file, config_context='srfsh') -- 2.43.2