Commit 2a48f66f authored by Yoshinori Okuji's avatar Yoshinori Okuji

Do not refer to the activity tool in _finish.

Instead, store the path in ActivityBuffer in __init__.
Make the parameter activity_tool to __init__ in ActivityBuffer obligatory.
Some performance tuning.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@8153 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a6e65ddc
...@@ -188,50 +188,50 @@ class Queue: ...@@ -188,50 +188,50 @@ class Queue:
def getMessageList(self, activity_tool, processing_node=None,**kw): def getMessageList(self, activity_tool, processing_node=None,**kw):
return [] return []
# Transaction Management # Transaction Management
def prepareQueueMessage(self, activity_tool, m): def prepareQueueMessage(self, activity_tool, m):
# Called to prepare transaction commit for queued messages # Called to prepare transaction commit for queued messages
pass pass
def finishQueueMessage(self, activity_tool, m): def finishQueueMessage(self, activity_tool_path, m):
# Called to commit queued messages # Called to commit queued messages
pass pass
def prepareDeleteMessage(self, activity_tool, m): def prepareDeleteMessage(self, activity_tool, m):
# Called to prepare transaction commit for deleted messages # Called to prepare transaction commit for deleted messages
pass pass
def finishDeleteMessage(self, activity_tool, m): def finishDeleteMessage(self, activity_tool_path, m):
# Called to commit deleted messages # Called to commit deleted messages
pass pass
# Registration Management # Registration Management
def registerActivityBuffer(self, activity_buffer): def registerActivityBuffer(self, activity_buffer):
class_name = self.__class__.__name__ class_name = self.__class__.__name__
setattr(activity_buffer, '_%s_message_list' % class_name, []) setattr(activity_buffer, '_%s_message_list' % class_name, [])
def isMessageRegistered(self, activity_buffer, activity_tool, m): def isMessageRegistered(self, activity_buffer, activity_tool, m):
class_name = self.__class__.__name__ class_name = self.__class__.__name__
return m in getattr(activity_buffer, '_%s_message_list' % class_name) return m in getattr(activity_buffer, '_%s_message_list' % class_name)
def registerMessage(self, activity_buffer, activity_tool, m): def registerMessage(self, activity_buffer, activity_tool, m):
class_name = self.__class__.__name__ class_name = self.__class__.__name__
getattr(activity_buffer, '_%s_message_list' % class_name).append(m) getattr(activity_buffer, '_%s_message_list' % class_name).append(m)
m.is_registered = 1 m.is_registered = 1
def unregisterMessage(self, activity_buffer, activity_tool, m): def unregisterMessage(self, activity_buffer, activity_tool, m):
m.is_registered = 0 m.is_registered = 0
def getRegisteredMessageList(self, activity_buffer, activity_tool): def getRegisteredMessageList(self, activity_buffer, activity_tool):
class_name = self.__class__.__name__ class_name = self.__class__.__name__
if hasattr(activity_buffer, '_%s_message_list' % class_name): if hasattr(activity_buffer, '_%s_message_list' % class_name):
return filter(lambda m: m.is_registered, getattr(activity_buffer, '_%s_message_list' % class_name)) return filter(lambda m: m.is_registered, getattr(activity_buffer, '_%s_message_list' % class_name))
else: else:
return () return ()
# Required for tests (time shift) # Required for tests (time shift)
def timeShift(self, activity_tool, delay): def timeShift(self, activity_tool, delay):
""" """
delay is provided in fractions of day delay is provided in fractions of day
""" """
......
...@@ -50,20 +50,17 @@ class RAMDict(Queue): ...@@ -50,20 +50,17 @@ class RAMDict(Queue):
Queue.__init__(self) Queue.__init__(self)
self.queue_dict = {} self.queue_dict = {}
def getDict(self, activity_tool): def getDict(self, activity_tool_path):
path = activity_tool.getPhysicalPath() return self.queue_dict.setdefault(activity_tool_path, {})
if not self.queue_dict.has_key(path):
self.queue_dict[path] = {} def finishQueueMessage(self, activity_tool_path, m):
return self.queue_dict[path]
def finishQueueMessage(self, activity_tool, m):
if m.is_registered: if m.is_registered:
self.getDict(activity_tool)[(tuple(m.object_path), m.method_id)] = m self.getDict(activity_tool_path)[(tuple(m.object_path), m.method_id)] = m
def finishDeleteMessage(self, activity_tool, message): def finishDeleteMessage(self, activity_tool_path, message):
for key, m in self.getDict(activity_tool).items(): for key, m in self.getDict(activity_tool_path).items():
if m.object_path == message.object_path and m.method_id == message.method_id: if m.object_path == message.object_path and m.method_id == message.method_id:
del self.getDict(activity_tool)[(tuple(m.object_path), m.method_id)] del self.getDict(activity_tool_path)[(tuple(m.object_path), m.method_id)]
def registerActivityBuffer(self, activity_buffer): def registerActivityBuffer(self, activity_buffer):
class_name = self.__class__.__name__ class_name = self.__class__.__name__
...@@ -81,13 +78,14 @@ class RAMDict(Queue): ...@@ -81,13 +78,14 @@ class RAMDict(Queue):
m.is_registered = 1 m.is_registered = 1
def dequeueMessage(self, activity_tool, processing_node): def dequeueMessage(self, activity_tool, processing_node):
if len(self.getDict(activity_tool).keys()) is 0: path = activity_tool.getPhysicalPath()
if len(self.getDict(path).keys()) is 0:
return 1 # Go to sleep return 1 # Go to sleep
for key, m in self.getDict(activity_tool).items(): for key, m in self.getDict(path).items():
if m.validate(self, activity_tool) is VALID: if m.validate(self, activity_tool) is VALID:
activity_tool.invoke(m) activity_tool.invoke(m)
if m.is_executed: if m.is_executed:
del self.getDict(activity_tool)[key] del self.getDict(path)[key]
get_transaction().commit() get_transaction().commit()
return 0 return 0
else: else:
...@@ -99,9 +97,10 @@ class RAMDict(Queue): ...@@ -99,9 +97,10 @@ class RAMDict(Queue):
if object is not None: if object is not None:
object_path = object.getPhysicalPath() object_path = object.getPhysicalPath()
else: else:
object_path = None object_path = None
active_process = kw.get('active_process', None) active_process = kw.get('active_process', None)
for m in self.getDict(activity_tool).values(): path = activity_tool.getPhysicalPath()
for m in self.getDict(path).values():
# Filter active process and path if defined # Filter active process and path if defined
if active_process is None or m.active_process == active_process: if active_process is None or m.active_process == active_process:
if object_path is None or m.object_path == object_path: if object_path is None or m.object_path == object_path:
...@@ -133,16 +132,17 @@ class RAMDict(Queue): ...@@ -133,16 +132,17 @@ class RAMDict(Queue):
'The document %s does not exist' % path) 'The document %s does not exist' % path)
else: else:
method_dict[m.method_id] = 1 method_dict[m.method_id] = 1
activity_tool.unregisterMessage(self, m) activity_tool.unregisterMessage(self, m)
else: else:
method_dict[m.method_id] = 1 method_dict[m.method_id] = 1
activity_tool.unregisterMessage(self, m) activity_tool.unregisterMessage(self, m)
# Parse each message in RAM dict # Parse each message in RAM dict
for key, m in self.getDict(activity_tool).items(): path = activity_tool.getPhysicalPath()
for key, m in self.getDict(path).items():
if object_path == m.object_path and (method_id is None or method_id == m.method_id): if object_path == m.object_path and (method_id is None or method_id == m.method_id):
if not method_dict.has_key(m.method_id): if not method_dict.has_key(m.method_id):
LOG('CMFActivity RAMDict: ', 0, 'flushing object %s' % '/'.join(m.object_path)) LOG('CMFActivity RAMDict: ', 0, 'flushing object %s' % '/'.join(m.object_path))
if invoke: if invoke:
activity_tool.invoke(m) activity_tool.invoke(m)
if m.is_executed: if m.is_executed:
method_dict[m.method_id] = 1 method_dict[m.method_id] = 1
...@@ -150,15 +150,16 @@ class RAMDict(Queue): ...@@ -150,15 +150,16 @@ class RAMDict(Queue):
else: else:
method_dict[m.method_id] = 1 method_dict[m.method_id] = 1
self.deleteMessage(activity_tool, m) self.deleteMessage(activity_tool, m)
else: else:
self.deleteMessage(activity_tool, m) self.deleteMessage(activity_tool, m)
def getMessageList(self, activity_tool, processing_node=None,**kw): def getMessageList(self, activity_tool, processing_node=None,**kw):
new_queue = [] new_queue = []
for m in self.getDict(activity_tool).values(): path = activity_tool.getPhysicalPath()
for m in self.getDict(path).values():
m.processing_node = 1 m.processing_node = 1
m.priority = 0 m.priority = 0
new_queue.append(m) new_queue.append(m)
return new_queue return new_queue
registerActivity(RAMDict) registerActivity(RAMDict)
...@@ -43,23 +43,20 @@ class RAMQueue(Queue): ...@@ -43,23 +43,20 @@ class RAMQueue(Queue):
Queue.__init__(self) Queue.__init__(self)
self.queue_dict = {} self.queue_dict = {}
self.last_uid = 0 self.last_uid = 0
def getQueue(self, activity_tool): def getQueue(self, activity_tool_path):
path = activity_tool.getPhysicalPath() return self.queue_dict.setdefault(activity_tool_path, [])
if not self.queue_dict.has_key(path):
self.queue_dict[path] = [] def finishQueueMessage(self, activity_tool_path, m):
return self.queue_dict[path]
def finishQueueMessage(self, activity_tool, m):
if m.is_registered: if m.is_registered:
# XXX - Some lock is required on this section # XXX - Some lock is required on this section
self.last_uid = self.last_uid + 1 self.last_uid = self.last_uid + 1
m.uid = self.last_uid m.uid = self.last_uid
self.getQueue(activity_tool).append(m) self.getQueue(activity_tool_path).append(m)
def finishDeleteMessage(self, activity_tool, m): def finishDeleteMessage(self, activity_tool_path, m):
i = 0 i = 0
queue = self.getQueue(activity_tool) queue = self.getQueue(activity_tool_path)
for my_message in queue: for my_message in queue:
if my_message.uid == m.uid: if my_message.uid == m.uid:
del queue[i] del queue[i]
...@@ -67,7 +64,8 @@ class RAMQueue(Queue): ...@@ -67,7 +64,8 @@ class RAMQueue(Queue):
i = i + 1 i = i + 1
def dequeueMessage(self, activity_tool, processing_node): def dequeueMessage(self, activity_tool, processing_node):
for m in self.getQueue(activity_tool): path = activity_tool.getPhysicalPath()
for m in self.getQueue(path):
if m.validate(self, activity_tool) is not VALID: if m.validate(self, activity_tool) is not VALID:
self.deleteMessage(activity_tool, m) # Trash messages which are not validated (no error handling) self.deleteMessage(activity_tool, m) # Trash messages which are not validated (no error handling)
get_transaction().commit() # Start a new transaction get_transaction().commit() # Start a new transaction
...@@ -76,7 +74,7 @@ class RAMQueue(Queue): ...@@ -76,7 +74,7 @@ class RAMQueue(Queue):
if m.is_executed: if m.is_executed:
self.deleteMessage(activity_tool, m) # Trash messages which are not validated (no error handling) self.deleteMessage(activity_tool, m) # Trash messages which are not validated (no error handling)
get_transaction().commit() # Start a new transaction get_transaction().commit() # Start a new transaction
return 0 # Keep on ticking return 0 # Keep on ticking
else: else:
# Start a new transaction and keep on to next message # Start a new transaction and keep on to next message
get_transaction().commit() get_transaction().commit()
...@@ -88,8 +86,9 @@ class RAMQueue(Queue): ...@@ -88,8 +86,9 @@ class RAMQueue(Queue):
object_path = object.getPhysicalPath() object_path = object.getPhysicalPath()
else: else:
object_path = None object_path = None
active_process = kw.get('active_process', None) active_process = kw.get('active_process', None)
for m in self.getQueue(activity_tool): path = activity_tool.getPhysicalPath()
for m in self.getQueue(path):
# Filter active process and path if defined # Filter active process and path if defined
if active_process is None or m.active_process == active_process: if active_process is None or m.active_process == active_process:
if object_path is None or m.object_path == object_path: if object_path is None or m.object_path == object_path:
...@@ -102,29 +101,31 @@ class RAMQueue(Queue): ...@@ -102,29 +101,31 @@ class RAMQueue(Queue):
if object_path == m.object_path and (method_id is None or method_id == m.method_id): if object_path == m.object_path and (method_id is None or method_id == m.method_id):
if m.validate(self, activity_tool) is not VALID: if m.validate(self, activity_tool) is not VALID:
activity_tool.unregisterMessage(self, m) # Trash messages which are not validated (no error handling) activity_tool.unregisterMessage(self, m) # Trash messages which are not validated (no error handling)
else: else:
if invoke: if invoke:
activity_tool.invoke(m) activity_tool.invoke(m)
if m.is_executed: if m.is_executed:
activity_tool.unregisterMessage(self, m) activity_tool.unregisterMessage(self, m)
else: else:
activity_tool.unregisterMessage(self, m) activity_tool.unregisterMessage(self, m)
# Parse each message in queue # Parse each message in queue
for m in self.getQueue(activity_tool): path = activity_tool.getPhysicalPath()
for m in self.getQueue(path):
if object_path == m.object_path and (method_id is None or method_id == m.method_id): if object_path == m.object_path and (method_id is None or method_id == m.method_id):
if m.validate(self, activity_tool) is not VALID: if m.validate(self, activity_tool) is not VALID:
self.deleteMessage(activity_tool, m) # Trash messages which are not validated (no error handling) self.deleteMessage(activity_tool, m) # Trash messages which are not validated (no error handling)
else: else:
if invoke: if invoke:
activity_tool.invoke(m) activity_tool.invoke(m)
if m.is_executed: if m.is_executed:
self.deleteMessage(activity_tool, m) # Only delete if no error happens self.deleteMessage(activity_tool, m) # Only delete if no error happens
else: else:
self.deleteMessage(activity_tool, m) self.deleteMessage(activity_tool, m)
def getMessageList(self, activity_tool, processing_node=None,**kw): def getMessageList(self, activity_tool, processing_node=None,**kw):
new_queue = [] new_queue = []
for m in self.getQueue(activity_tool): path = activity_tool.getPhysicalPath()
for m in self.getQueue(path):
m.processing_node = 1 m.processing_node = 1
m.priority = 0 m.priority = 0
new_queue.append(m) new_queue.append(m)
......
This diff is collapsed.
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