From 9ed4749a09b5fc0b1fa0f00a5986fbf93931f4ba Mon Sep 17 00:00:00 2001 From: Vincent Pelletier <vincent@nexedi.com> Date: Wed, 16 Jan 2008 21:49:43 +0000 Subject: [PATCH] Apply the same cache as in CMFActivity.ActivityTool to getCurrentNode method. Reorder test to execute less costly operations first. Use accessor to get alarmNode value. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18753 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Tool/AlarmTool.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/product/ERP5/Tool/AlarmTool.py b/product/ERP5/Tool/AlarmTool.py index 8fdc3be67b..ac4ae6cb94 100644 --- a/product/ERP5/Tool/AlarmTool.py +++ b/product/ERP5/Tool/AlarmTool.py @@ -54,6 +54,7 @@ except ImportError: last_tic = time.time() last_tic_lock = threading.Lock() +current_node = None class AlarmTool(BaseTool): """ @@ -193,8 +194,9 @@ class AlarmTool(BaseTool): in zope.conf. The Default is every 5 seconds. """ # only start when we are the alarmNode or if it's empty - if (self.alarmNode == self.getCurrentNode()) \ - or not self.alarmNode: + alarmNode = self.getAlarmNode() + if (not alarmNode) \ + or (alarmNode == self.getCurrentNode()): global last_tic last_tic_lock.acquire(1) try: @@ -206,18 +208,20 @@ class AlarmTool(BaseTool): def getCurrentNode(self): """ Return current node in form ip:port """ - port = '' - from asyncore import socket_map - for k, v in socket_map.items(): - if hasattr(v, 'port'): - # see Zope/lib/python/App/ApplicationManager.py: def getServers(self) - type = str(getattr(v, '__class__', 'unknown')) - if type == 'ZServer.HTTPServer.zhttp_server': - port = v.port - break - ip = socket.gethostbyname(socket.gethostname()) - currentNode = '%s:%s' %(ip, port) - return currentNode + global current_node + if current_node is None: + port = '' + from asyncore import socket_map + for k, v in socket_map.items(): + if hasattr(v, 'port'): + # see Zope/lib/python/App/ApplicationManager.py: def getServers(self) + type = str(getattr(v, '__class__', 'unknown')) + if type == 'ZServer.HTTPServer.zhttp_server': + port = v.port + break + ip = socket.gethostbyname(socket.gethostname()) + current_node = '%s:%s' %(ip, port) + return current_node security.declarePublic('getAlarmNode') def getAlarmNode(self): -- 2.30.9