Commit 9ed4749a authored by Vincent Pelletier's avatar Vincent Pelletier

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
parent d3885f92
...@@ -54,6 +54,7 @@ except ImportError: ...@@ -54,6 +54,7 @@ except ImportError:
last_tic = time.time() last_tic = time.time()
last_tic_lock = threading.Lock() last_tic_lock = threading.Lock()
current_node = None
class AlarmTool(BaseTool): class AlarmTool(BaseTool):
""" """
...@@ -193,8 +194,9 @@ class AlarmTool(BaseTool): ...@@ -193,8 +194,9 @@ class AlarmTool(BaseTool):
in zope.conf. The Default is every 5 seconds. in zope.conf. The Default is every 5 seconds.
""" """
# only start when we are the alarmNode or if it's empty # only start when we are the alarmNode or if it's empty
if (self.alarmNode == self.getCurrentNode()) \ alarmNode = self.getAlarmNode()
or not self.alarmNode: if (not alarmNode) \
or (alarmNode == self.getCurrentNode()):
global last_tic global last_tic
last_tic_lock.acquire(1) last_tic_lock.acquire(1)
try: try:
...@@ -206,18 +208,20 @@ class AlarmTool(BaseTool): ...@@ -206,18 +208,20 @@ class AlarmTool(BaseTool):
def getCurrentNode(self): def getCurrentNode(self):
""" Return current node in form ip:port """ """ Return current node in form ip:port """
port = '' global current_node
from asyncore import socket_map if current_node is None:
for k, v in socket_map.items(): port = ''
if hasattr(v, 'port'): from asyncore import socket_map
# see Zope/lib/python/App/ApplicationManager.py: def getServers(self) for k, v in socket_map.items():
type = str(getattr(v, '__class__', 'unknown')) if hasattr(v, 'port'):
if type == 'ZServer.HTTPServer.zhttp_server': # see Zope/lib/python/App/ApplicationManager.py: def getServers(self)
port = v.port type = str(getattr(v, '__class__', 'unknown'))
break if type == 'ZServer.HTTPServer.zhttp_server':
ip = socket.gethostbyname(socket.gethostname()) port = v.port
currentNode = '%s:%s' %(ip, port) break
return currentNode ip = socket.gethostbyname(socket.gethostname())
current_node = '%s:%s' %(ip, port)
return current_node
security.declarePublic('getAlarmNode') security.declarePublic('getAlarmNode')
def getAlarmNode(self): def getAlarmNode(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment