Commit a71aef00 authored by Vincent Pelletier's avatar Vincent Pelletier

Factorise code between RAMDict and SQLDict.

Factorise code used to generate an unique identifier for messages (used to avoid inserting duplicate messages in the same transaction).


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21754 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 313d2ae2
......@@ -65,15 +65,18 @@ class RAMDict(Queue):
def registerActivityBuffer(self, activity_buffer):
pass
def generateMessageUID(self, m):
return (tuple(m.object_path), m.method_id)
def isMessageRegistered(self, activity_buffer, activity_tool, m):
uid_set = activity_buffer.getUidSet(self)
return (tuple(m.object_path), m.method_id) in uid_set
return self.generateMessageId(m) in uid_set
def registerMessage(self, activity_buffer, activity_tool, m):
message_list = activity_buffer.getMessageList(self)
message_list.append(m)
uid_set = activity_buffer.getUidSet(self)
uid_set.add((tuple(m.object_path), m.method_id))
uid_set.add(self.generateMessageId(m))
m.is_registered = 1
def dequeueMessage(self, activity_tool, processing_node):
......
......@@ -115,22 +115,14 @@ class SQLDict(RAMDict, SQLBase):
def registerActivityBuffer(self, activity_buffer):
pass
def isMessageRegistered(self, activity_buffer, activity_tool, m):
uid_set = activity_buffer.getUidSet(self)
return (tuple(m.object_path), m.method_id, m.activity_kw.get('tag'), m.activity_kw.get('group_id')) in uid_set
def registerMessage(self, activity_buffer, activity_tool, m):
m.is_registered = 1
uid_set = activity_buffer.getUidSet(self)
uid_set.add((tuple(m.object_path), m.method_id, m.activity_kw.get('tag'), m.activity_kw.get('group_id')))
message_list = activity_buffer.getMessageList(self)
message_list.append(m)
def generateMessageUID(self, m):
return (tuple(m.object_path), m.method_id, m.activity_kw.get('tag'), m.activity_kw.get('group_id'))
def unregisterMessage(self, activity_buffer, activity_tool, m):
m.is_registered = 0 # This prevents from inserting deleted messages into the queue
class_name = self.__class__.__name__
uid_set = activity_buffer.getUidSet(self)
uid_set.discard((tuple(m.object_path), m.method_id, m.activity_kw.get('tag'), m.activity_kw.get('group_id')))
uid_set.discard(self.generateMessageUID(m))
def getRegisteredMessageList(self, activity_buffer, activity_tool):
message_list = activity_buffer.getMessageList(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