[Opensrf-commits] r1201 - trunk/src/python/osrf

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Jan 6 15:48:58 EST 2008


Author: erickson
Date: 2008-01-06 15:24:43 -0500 (Sun, 06 Jan 2008)
New Revision: 1201

Modified:
   trunk/src/python/osrf/system.py
Log:
providing option to connect to memcache at general connect time

Modified: trunk/src/python/osrf/system.py
===================================================================
--- trunk/src/python/osrf/system.py	2008-01-06 20:22:57 UTC (rev 1200)
+++ trunk/src/python/osrf/system.py	2008-01-06 20:24:43 UTC (rev 1201)
@@ -15,14 +15,17 @@
 
 from osrf.conf import Config, get, get_no_ex
 from osrf.net import Network, set_network_handle, get_network_handle
-import osrf.stack
-import osrf.log
-import osrf.set
+import osrf.stack, osrf.log, osrf.set, osrf.cache
 import sys
 
 
-def connect(configFile, configContext):
-    """ Connects to the opensrf network """
+def connect(configFile, configContext, init_cache=False):
+    """ Connects to the opensrf network 
+        @param configFile The OpenSRF config
+        @param configContext The path to the configuration element in the XML config.
+            e.g. 'config.opensrf'
+        @param init_cache If true, connect to the cache servers
+    """
 
     if get_network_handle():
         ''' This thread already has a handle '''
@@ -44,6 +47,7 @@
         port = osrf.conf.get('port'),
         username = osrf.conf.get('username'), 
         password = osrf.conf.get('passwd'))
+
     network.set_receive_callback(osrf.stack.push)
     osrf.net.set_network_handle(network)
     network.connect()
@@ -51,3 +55,17 @@
     # load the domain-wide settings file
     osrf.set.load(osrf.conf.get('domains.domain'))
 
+    if init_cache:
+        connect_cache()
+
+
+def connect_cache():
+    ''' Initializes the cache connections '''
+    cache_servers = osrf.set.get('cache.global.servers.server')
+    if cache_servers:
+        if not isinstance(cache_servers, list):
+            cache_servers = [cache_servers]
+        if not osrf.cache.CacheClient.get_client():
+            osrf.cache.CacheClient.connect(cache_servers)
+
+



More information about the opensrf-commits mailing list