本文整理汇总了Python中framework.Framework.forward_message方法的典型用法代码示例。如果您正苦于以下问题:Python Framework.forward_message方法的具体用法?Python Framework.forward_message怎么用?Python Framework.forward_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类framework.Framework
的用法示例。
在下文中一共展示了Framework.forward_message方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rcv_clientput
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import forward_message [as 别名]
def rcv_clientput(self, msg):
preference_list, avoided = DynamoNode.chash.find_nodes(msg.key, DynamoNode.N, self.failed_nodes)
non_extra_count = DynamoNode.N - len(avoided)
# Determine if we are in the list
if self not in preference_list:
# Forward to the coordinator for this key
_logger.info("put(%s=%s) maps to %s", msg.key, msg.value, preference_list)
coordinator = preference_list[0]
Framework.forward_message(msg, coordinator)
else:
# Use an incrementing local sequence number to distinguish
# multiple requests for the same key
seqno = self.generate_sequence_number()
_logger.info("%s, %d: put %s=%s", self, seqno, msg.key, msg.value)
metadata = (self.name, seqno) # For now, metadata is just sequence number at coordinator
# Send out to preference list, and keep track of who has replied
self.pending_req[PutReq][seqno] = set()
self.pending_put_rsp[seqno] = set()
self.pending_put_msg[seqno] = msg
reqcount = 0
for ii, node in enumerate(preference_list):
if ii >= non_extra_count:
# This is an extra node that's only include because of a failed node
handoff = avoided
else:
handoff = None
# Send message to get node in preference list to store
putmsg = PutReq(self, node, msg.key, msg.value, metadata, msg_id=seqno, handoff=handoff)
self.pending_req[PutReq][seqno].add(putmsg)
Framework.send_message(putmsg)
reqcount = reqcount + 1
if reqcount >= DynamoNode.N:
# preference_list may have more than N entries to allow for failed nodes
break
示例2: rcv_clientput
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import forward_message [as 别名]
def rcv_clientput(self, msg):
preference_list = DynamoNode.chash.find_nodes(msg.key, DynamoNode.N)[0]
# Determine if we are in the list
if self not in preference_list:
# Forward to the coordinator for this key
_logger.info("put(%s=%s) maps to %s", msg.key, msg.value, preference_list)
coordinator = preference_list[0]
Framework.forward_message(msg, coordinator)
else:
# Use an incrementing local sequence number to distinguish
# multiple requests for the same key
seqno = self.generate_sequence_number()
_logger.info("%s, %d: put %s=%s", self, seqno, msg.key, msg.value)
metadata = (self.name, seqno) # For now, metadata is just sequence number at coordinator
# Send out to preference list, and keep track of who has replied
self.pending_put_rsp[seqno] = set()
self.pending_put_msg[seqno] = msg
reqcount = 0
for node in preference_list:
# Send message to get node in preference list to store
putmsg = PutReq(self, node, msg.key, msg.value, metadata, msg_id=seqno)
Framework.send_message(putmsg)
reqcount = reqcount + 1
if reqcount >= DynamoNode.N:
# preference_list may have more than N entries to allow for failed nodes
break
示例3: rcv_clientget
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import forward_message [as 别名]
def rcv_clientget(self, msg):
preference_list = DynamoNode.chash.find_nodes(msg.key, DynamoNode.N)[0]
# Determine if we are in the list
if self not in preference_list:
# Forward to the coordinator for this key
_logger.info("get(%s=?) maps to %s", msg.key, preference_list)
coordinator = preference_list[0]
Framework.forward_message(msg, coordinator)
else:
seqno = self.generate_sequence_number()
self.pending_get_rsp[seqno] = set()
self.pending_get_msg[seqno] = msg
reqcount = 0
for node in preference_list:
getmsg = GetReq(self, node, msg.key, msg_id=seqno)
Framework.send_message(getmsg)
reqcount = reqcount + 1
if reqcount >= DynamoNode.N:
# preference_list may have more than N entries to allow for failed nodes
break
示例4: rcv_clientget
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import forward_message [as 别名]
def rcv_clientget(self, msg):
preference_list = DynamoNode.chash.find_nodes(msg.key, DynamoNode.N, self.failed_nodes)[0]
# Determine if we are in the list
#modified
if self.addr not in preference_list:
################################
# Forward to the coordinator for this key
_logger.info("get(%s=?) maps to %s", msg.key, preference_list)
for e in preference_list:
con = self.connections[self.servers.index(e)]
result = Framework.forward_message(msg, con, e)
if result is not False:
break
if e not in self.failed_nodes:
self.failed_nodes.append(e)
return result
else:
seqno = self.generate_sequence_number()
self.pending_req[GetReq][seqno] = set()
self.pending_get_rsp[seqno] = set()
self.pending_get_msg[seqno] = msg
reqcount = 0
#modified
value = []
################
for node in preference_list:
getmsg = GetReq(self.addr, node, msg.key, msg_id=seqno)
self.pending_req[GetReq][seqno].add(getmsg)
#modified
con = self.connections[self.servers.index(getmsg.to_node)]
result = Framework.send_message(getmsg, con)
if result is not False:
value.append(result)
reqcount = reqcount + 1
############################################
if reqcount >= DynamoNode.N:
# preference_list may have more than N entries to allow for failed nodes
break
# print value
#modified
# no value for this key
if len(value) < 1:
return False
##########################
return value
示例5: DynamoNode
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import forward_message [as 别名]
#.........这里部分代码省略.........
def retry_request(self, reqmsg):
self.failed_nodes.append(reqmsg.to_node)
if not isinstance(reqmsg, DynamoRequestMessage):
return
# Send the request to an additional node by regenerating the preference list
preference_list = DynamoNode.chash.find_nodes(reqmsg.key, DynamoNode.N, self.failed_nodes)[0]
kls = reqmsg.__class__
# Check the pending-request list for this type of request message
if kls in self.pending_req and reqmsg.msg_id in self.pending_req[kls]:
for node in preference_list:
try:
if node not in [req.to_node for req in self.pending_req[kls][reqmsg.msg_id]]:
# Found a node on the new preference list that hasn't been sent the request.
# Send it a copy
newreqmsg = copy.copy(reqmsg)
newreqmsg.to_node = node
self.pending_req[kls][reqmsg.msg_id].add(newreqmsg)
self.framework.send_message(newreqmsg)
self.framework.schedule()
except:
pass
# PART rcv_clientput
def rcv_clientput(self, msg):
preference_list, avoided = DynamoNode.chash.find_nodes(msg.key, DynamoNode.N, self.failed_nodes)
non_extra_count = DynamoNode.N - len(avoided)
# Determine if we are in the list
if self.addr not in preference_list:
# Forward to the coordinator for this key
_logger.info("put(%s=%s) maps to %s", msg.key, msg.value, preference_list)
coordinator = preference_list[0]
self.framework.forward_message(msg, coordinator)
self.framework.schedule()
else:
# Use an incrementing local sequence number to distinguish
# multiple requests for the same key
seqno = self.generate_sequence_number()
_logger.info("%s, %d: put %s=%s", self, seqno, msg.key, msg.value)
# The metadata for a key is passed in by the client, and updated by the coordinator node.
metadata = copy.deepcopy(msg.metadata)
metadata.update(self.name, seqno)
# Send out to preference list, and keep track of who has replied
self.pending_req[PutReq][seqno] = set()
self.pending_put_rsp[seqno] = set()
self.pending_put_msg[seqno] = msg
reqcount = 0
for ii, node in enumerate(preference_list):
if ii >= non_extra_count:
# This is an extra node that's only include because of a failed node
handoff = avoided
else:
handoff = None
# Send message to get node in preference list to store
putmsg = PutReq(self.addr, node, msg.key, msg.value, metadata, msg_id=seqno, handoff=handoff)
try:
self.pending_req[PutReq][seqno].add(putmsg)
except:
pass
self.framework.send_message(putmsg)
self.framework.schedule()
reqcount = reqcount + 1
if reqcount >= DynamoNode.N:
# preference_list may have more than N entries to allow for failed nodes
break
示例6: rcv_clientput
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import forward_message [as 别名]
def rcv_clientput(self, msg):
preference_list, avoided = DynamoNode.chash.find_nodes(msg.key, DynamoNode.N, self.failed_nodes)
non_extra_count = DynamoNode.N - len(avoided)
# Determine if we are in the list
#modified
if self.addr not in preference_list:
# Forward to the coordinator for this key
_logger.info("put(%s=%s) maps to %s", msg.key, msg.value, preference_list)
result = True
for e in preference_list:
con = self.connections[self.servers.index(e)]
result = Framework.forward_message(msg, con, e)
if result is not False:
break
if e not in self.failed_nodes:
self.failed_nodes.append(e)
return result
#####################################
else:
# Use an incrementing local sequence number to distinguish
# multiple requests for the same key
seqno = self.generate_sequence_number()
_logger.info("%s, %d: put %s=%s", self, seqno, msg.key, msg.value)
# The metadata for a key is passed in by the client, and updated by the coordinator node.
metadata = copy.deepcopy(msg.metadata)
metadata.update(self.name, seqno)
# Send out to preference list, and keep track of who has replied
self.pending_req[PutReq][seqno] = set()
self.pending_put_rsp[seqno] = set()
self.pending_put_msg[seqno] = msg
reqcount = 0
#modified
nodes = []
#####################
for ii, node in enumerate(preference_list):
if ii >= non_extra_count:
# This is an extra node that's only include because of a failed node
handoff = avoided
else:
handoff = None
# Send message to get node in preference list to store
putmsg = PutReq(self.addr, node, msg.key, msg.value, metadata, msg_id=seqno, handoff=handoff)
self.pending_req[PutReq][seqno].add(putmsg)
#modified
con = self.connections[self.servers.index(putmsg.to_node)]
result = Framework.send_message(putmsg, con)
if result is False and putmsg.to_node not in self.failed_nodes:
self.failed_nodes.append(putmsg.to_node)
if result is not False:
nodes.append(node)
reqcount = reqcount + 1
####################################
# print "---------------------------------", type(putmsg)
if reqcount >= DynamoNode.N:
# preference_list may have more than N entries to allow for failed nodes
break
#modified
if reqcount >= DynamoNode.N:
return nodes
return False