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,6 +208,8 @@ class AlarmTool(BaseTool): ...@@ -206,6 +208,8 @@ class AlarmTool(BaseTool):
def getCurrentNode(self): def getCurrentNode(self):
""" Return current node in form ip:port """ """ Return current node in form ip:port """
global current_node
if current_node is None:
port = '' port = ''
from asyncore import socket_map from asyncore import socket_map
for k, v in socket_map.items(): for k, v in socket_map.items():
...@@ -216,8 +220,8 @@ class AlarmTool(BaseTool): ...@@ -216,8 +220,8 @@ class AlarmTool(BaseTool):
port = v.port port = v.port
break break
ip = socket.gethostbyname(socket.gethostname()) ip = socket.gethostbyname(socket.gethostname())
currentNode = '%s:%s' %(ip, port) current_node = '%s:%s' %(ip, port)
return currentNode 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