Commit 2264ab3a authored by Yoshinori Okuji's avatar Yoshinori Okuji

Broadcasting messages is supported.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2003 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cacdc675
...@@ -59,6 +59,7 @@ class SQLDict(RAMDict): ...@@ -59,6 +59,7 @@ class SQLDict(RAMDict):
activity_tool.SQLDict_writeMessage( path = '/'.join(m.object_path) , activity_tool.SQLDict_writeMessage( path = '/'.join(m.object_path) ,
method_id = m.method_id, method_id = m.method_id,
priority = m.activity_kw.get('priority', 1), priority = m.activity_kw.get('priority', 1),
broadcast = m.activity_kw.get('broadcast', 0),
message = self.dumpMessage(m), message = self.dumpMessage(m),
date = m.activity_kw.get('at_date', DateTime())) date = m.activity_kw.get('at_date', DateTime()))
# Also store uid of activity # Also store uid of activity
...@@ -239,6 +240,8 @@ class SQLDict(RAMDict): ...@@ -239,6 +240,8 @@ class SQLDict(RAMDict):
method_id = line.method_id method_id = line.method_id
if not method_dict.has_key(method_id): if not method_dict.has_key(method_id):
# Only invoke once (it would be different for a queue) # Only invoke once (it would be different for a queue)
# This is optimisation with the goal to process objects on the same
# node and minimize network traffic with ZEO server
method_dict[method_id] = 1 method_dict[method_id] = 1
m = self.loadMessage(line.message, uid = line.uid) m = self.loadMessage(line.message, uid = line.uid)
self.deleteMessage(activity_tool, m) self.deleteMessage(activity_tool, m)
...@@ -283,10 +286,23 @@ class SQLDict(RAMDict): ...@@ -283,10 +286,23 @@ class SQLDict(RAMDict):
path_dict = {} path_dict = {}
for line in result: for line in result:
path = line.path path = line.path
if not path_dict.has_key(path): broadcast = line.broadcast
if broadcast:
# Broadcast messages must be distributed into all nodes.
uid = line.uid
activity_tool.SQLDict_assignMessage(processing_node=1, uid=[uid])
for node in range(2, node_count+1):
activity_tool.SQLDict_writeMessage( path = path,
method_id = line.method_id,
priority = line.priority,
broadcast = 1,
processing_node = node,
message = line.message,
date = line.date)
elif not path_dict.has_key(path):
# Only assign once (it would be different for a queue) # Only assign once (it would be different for a queue)
path_dict[path] = 1 path_dict[path] = 1
activity_tool.SQLDict_assignMessage(path=path, processing_node=processing_node, uid=None) activity_tool.SQLDict_assignMessage(path=path, processing_node=processing_node, uid=None, broadcast=0)
get_transaction().commit() # Release locks immediately to allow processing of messages get_transaction().commit() # Release locks immediately to allow processing of messages
processing_node = processing_node + 1 processing_node = processing_node + 1
if processing_node > node_count: if processing_node > node_count:
...@@ -295,7 +311,10 @@ class SQLDict(RAMDict): ...@@ -295,7 +311,10 @@ class SQLDict(RAMDict):
# Validation private methods # Validation private methods
def _validate_after_method_id(self, activity_tool, message, value): def _validate_after_method_id(self, activity_tool, message, value):
# Count number of occurances of method_id # Count number of occurances of method_id
result = activity_tool.SQLDict_validateMessageList(method_id=value, message_uid=None, path=None) if type(value) == type(''):
value = [value]
for method_id in value:
result = activity_tool.SQLDict_validateMessageList(method_id=method_id, message_uid=None, path=None)
if result[0].uid_count > 0: if result[0].uid_count > 0:
return INVALID_ORDER return INVALID_ORDER
return VALID return VALID
......
...@@ -10,7 +10,8 @@ class_file: ...@@ -10,7 +10,8 @@ class_file:
<params>path <params>path
processing_node processing_node
method_id method_id
uid=None</params> uid
broadcast</params>
UPDATE message UPDATE message
SET SET
processing_node=<dtml-sqlvar processing_node type="int">, processing_node=<dtml-sqlvar processing_node type="int">,
...@@ -23,3 +24,6 @@ WHERE ...@@ -23,3 +24,6 @@ WHERE
path = <dtml-sqlvar path type="string"> path = <dtml-sqlvar path type="string">
<dtml-if method_id>AND method_id = <dtml-sqlvar method_id type="string"></dtml-if> <dtml-if method_id>AND method_id = <dtml-sqlvar method_id type="string"></dtml-if>
</dtml-if> </dtml-if>
<dtml-if broadcast>
AND broadcast = <dtml-sqlvar broadcast type="int">
</dtml-if>
...@@ -17,6 +17,7 @@ CREATE TABLE `message` ( ...@@ -17,6 +17,7 @@ CREATE TABLE `message` (
`processing` INT DEFAULT 0, `processing` INT DEFAULT 0,
`processing_date` datetime, `processing_date` datetime,
`priority` INT DEFAULT 0, `priority` INT DEFAULT 0,
`broadcast` INT DEFAULT 0,
`message` BLOB, `message` BLOB,
PRIMARY KEY (`uid`), PRIMARY KEY (`uid`),
KEY `date` (`date`), KEY `date` (`date`),
......
...@@ -11,13 +11,16 @@ class_file: ...@@ -11,13 +11,16 @@ class_file:
method_id method_id
message message
priority priority
date</params> broadcast
date
processing_node=-1</params>
INSERT INTO message INSERT INTO message
SET SET
path = <dtml-sqlvar path type="string">, path = <dtml-sqlvar path type="string">,
<dtml-if date>date = <dtml-sqlvar date type="string">, <dtml-else>date = <dtml-sqlvar "_.DateTime()" type="string">, </dtml-if> <dtml-if date>date = <dtml-sqlvar date type="string">, <dtml-else>date = <dtml-sqlvar "_.DateTime()" type="string">, </dtml-if>
method_id = <dtml-sqlvar method_id type="string">, method_id = <dtml-sqlvar method_id type="string">,
processing_node = -1, processing_node = <dtml-sqlvar processing_node type="int">,
processing = -1, processing = -1,
priority = <dtml-sqlvar priority type="int">, priority = <dtml-sqlvar priority type="int">,
broadcast = <dtml-sqlvar broadcast type="int">,
message = <dtml-sqlvar message type="string"> message = <dtml-sqlvar message type="string">
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