Commit 48f60bb7 authored by Vincent Pelletier's avatar Vincent Pelletier

Do not duplicate data when possible.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19171 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c4442ea1
...@@ -76,12 +76,12 @@ class ActivityBuffer(TM): ...@@ -76,12 +76,12 @@ class ActivityBuffer(TM):
# at end of transaction # at end of transaction
def _beginAndHook(self, activity_tool): def _beginAndHook(self, activity_tool):
# LOG('ActivityBuffer', 0, '_begin %r' % (self,)) # LOG('ActivityBuffer', 0, '_begin %r' % (self,))
from ActivityTool import activity_list from ActivityTool import activity_dict
self.requires_prepare = 1 self.requires_prepare = 1
try: try:
# Reset registration for each transaction. # Reset registration for each transaction.
for activity in activity_list: for activity in activity_dict.itervalues():
activity.registerActivityBuffer(self) activity.registerActivityBuffer(self)
# In Zope 2.8 (ZODB 3.4), use beforeCommitHook instead of # In Zope 2.8 (ZODB 3.4), use beforeCommitHook instead of
......
...@@ -78,7 +78,6 @@ ROLE_PROCESSING = 1 ...@@ -78,7 +78,6 @@ ROLE_PROCESSING = 1
# Activity Registration # Activity Registration
activity_dict = {} activity_dict = {}
activity_list = []
# Here go ActivityBuffer instances # Here go ActivityBuffer instances
# Structure: # Structure:
...@@ -92,7 +91,6 @@ def registerActivity(activity): ...@@ -92,7 +91,6 @@ def registerActivity(activity):
# class and create instance for each activity # class and create instance for each activity
#LOG('Init Activity', 0, str(activity.__name__)) #LOG('Init Activity', 0, str(activity.__name__))
activity_instance = activity() activity_instance = activity()
activity_list.append(activity_instance)
activity_dict[activity.__name__] = activity_instance activity_dict[activity.__name__] = activity_instance
class Message: class Message:
...@@ -349,7 +347,7 @@ class ActivityTool (Folder, UniqueObject): ...@@ -349,7 +347,7 @@ class ActivityTool (Folder, UniqueObject):
global is_initialized global is_initialized
from Activity import RAMQueue, RAMDict, SQLQueue, SQLDict from Activity import RAMQueue, RAMDict, SQLQueue, SQLDict
# Initialize each queue # Initialize each queue
for activity in activity_list: for activity in activity_dict.itervalues():
activity.initialize(self) activity.initialize(self)
is_initialized = 1 is_initialized = 1
...@@ -606,7 +604,7 @@ class ActivityTool (Folder, UniqueObject): ...@@ -606,7 +604,7 @@ class ActivityTool (Folder, UniqueObject):
if not is_initialized: self.initialize() if not is_initialized: self.initialize()
# Call distribute on each queue # Call distribute on each queue
for activity in activity_list: for activity in activity_dict.itervalues():
activity.distribute(aq_inner(self), node_count) activity.distribute(aq_inner(self), node_count)
security.declarePublic('tic') security.declarePublic('tic')
...@@ -644,14 +642,14 @@ class ActivityTool (Folder, UniqueObject): ...@@ -644,14 +642,14 @@ class ActivityTool (Folder, UniqueObject):
try: try:
# Wakeup each queue # Wakeup each queue
for activity in activity_list: for activity in activity_dict.itervalues():
activity.wakeup(inner_self, processing_node) activity.wakeup(inner_self, processing_node)
# Process messages on each queue in round robin # Process messages on each queue in round robin
has_awake_activity = 1 has_awake_activity = 1
while has_awake_activity: while has_awake_activity:
has_awake_activity = 0 has_awake_activity = 0
for activity in activity_list: for activity in activity_dict.itervalues():
activity.tic(inner_self, processing_node) # Transaction processing is the responsability of the activity activity.tic(inner_self, processing_node) # Transaction processing is the responsability of the activity
has_awake_activity = has_awake_activity or activity.isAwake(inner_self, processing_node) has_awake_activity = has_awake_activity or activity.isAwake(inner_self, processing_node)
finally: finally:
...@@ -667,7 +665,7 @@ class ActivityTool (Folder, UniqueObject): ...@@ -667,7 +665,7 @@ class ActivityTool (Folder, UniqueObject):
obj = args[0] obj = args[0]
else: else:
obj = self obj = self
for activity in activity_list: for activity in activity_dict.itervalues():
if activity.hasActivity(aq_inner(self), obj, **kw): if activity.hasActivity(aq_inner(self), obj, **kw):
return 1 return 1
return 0 return 0
...@@ -746,19 +744,19 @@ class ActivityTool (Folder, UniqueObject): ...@@ -746,19 +744,19 @@ class ActivityTool (Folder, UniqueObject):
object_path = obj object_path = obj
else: else:
object_path = obj.getPhysicalPath() object_path = obj.getPhysicalPath()
for activity in activity_list: for activity in activity_dict.itervalues():
activity.flush(aq_inner(self), object_path, invoke=invoke, **kw) activity.flush(aq_inner(self), object_path, invoke=invoke, **kw)
def start(self, **kw): def start(self, **kw):
global is_initialized global is_initialized
if not is_initialized: self.initialize() if not is_initialized: self.initialize()
for activity in activity_list: for activity in activity_dict.itervalues():
activity.start(aq_inner(self), **kw) activity.start(aq_inner(self), **kw)
def stop(self, **kw): def stop(self, **kw):
global is_initialized global is_initialized
if not is_initialized: self.initialize() if not is_initialized: self.initialize()
for activity in activity_list: for activity in activity_dict.itervalues():
activity.stop(aq_inner(self), **kw) activity.stop(aq_inner(self), **kw)
def invoke(self, message): def invoke(self, message):
...@@ -933,7 +931,7 @@ class ActivityTool (Folder, UniqueObject): ...@@ -933,7 +931,7 @@ class ActivityTool (Folder, UniqueObject):
# Obtain all pending messages. # Obtain all pending messages.
message_list = [] message_list = []
if keep: if keep:
for activity in activity_list: for activity in activity_dict.itervalues():
if hasattr(activity, 'dumpMessageList'): if hasattr(activity, 'dumpMessageList'):
try: try:
message_list.extend(activity.dumpMessageList(self)) message_list.extend(activity.dumpMessageList(self))
...@@ -990,7 +988,7 @@ class ActivityTool (Folder, UniqueObject): ...@@ -990,7 +988,7 @@ class ActivityTool (Folder, UniqueObject):
if not is_initialized: self.initialize() if not is_initialized: self.initialize()
message_list = [] message_list = []
for activity in activity_list: for activity in activity_dict.itervalues():
try: try:
message_list += activity.getMessageList(aq_inner(self),**kw) message_list += activity.getMessageList(aq_inner(self),**kw)
except AttributeError: except AttributeError:
...@@ -1003,7 +1001,7 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1003,7 +1001,7 @@ class ActivityTool (Folder, UniqueObject):
Return the number of messages which match the given tag. Return the number of messages which match the given tag.
""" """
message_count = 0 message_count = 0
for activity in activity_list: for activity in activity_dict.itervalues():
message_count += activity.countMessageWithTag(aq_inner(self), value) message_count += activity.countMessageWithTag(aq_inner(self), value)
return message_count return message_count
...@@ -1020,7 +1018,7 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1020,7 +1018,7 @@ class ActivityTool (Folder, UniqueObject):
message_uid : activities with a particular uid message_uid : activities with a particular uid
""" """
message_count = 0 message_count = 0
for activity in activity_list: for activity in activity_dict.itervalues():
message_count += activity.countMessage(aq_inner(self), **kw) message_count += activity.countMessage(aq_inner(self), **kw)
return message_count return message_count
...@@ -1048,7 +1046,7 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1048,7 +1046,7 @@ class ActivityTool (Folder, UniqueObject):
if not is_initialized: self.initialize() if not is_initialized: self.initialize()
message_list = [] message_list = []
method_id = "_validate_%s" % validator_id method_id = "_validate_%s" % validator_id
for activity in activity_list: for activity in activity_dict.itervalues():
method = getattr(activity, method_id, None) method = getattr(activity, method_id, None)
if method is not None: if method is not None:
result = method(aq_inner(self), message, validation_value) result = method(aq_inner(self), message, validation_value)
...@@ -1060,7 +1058,7 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1060,7 +1058,7 @@ class ActivityTool (Folder, UniqueObject):
def timeShift(self, delay): def timeShift(self, delay):
global is_initialized global is_initialized
if not is_initialized: self.initialize() if not is_initialized: self.initialize()
for activity in activity_list: for activity in activity_dict.itervalues():
activity.timeShift(aq_inner(self), delay) activity.timeShift(aq_inner(self), delay)
InitializeClass(ActivityTool) InitializeClass(ActivityTool)
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