本文整理汇总了Python中framework.Framework.send_message方法的典型用法代码示例。如果您正苦于以下问题:Python Framework.send_message方法的具体用法?Python Framework.send_message怎么用?Python Framework.send_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类framework.Framework
的用法示例。
在下文中一共展示了Framework.send_message方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rcv_clientput
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import send_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
示例2: rcv_getrsp
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import send_message [as 别名]
def rcv_getrsp(self, getrsp):
seqno = getrsp.msg_id
if seqno in self.pending_get_rsp:
self.pending_get_rsp[seqno].add((getrsp.from_node, getrsp.value, getrsp.metadata))
if len(self.pending_get_rsp[seqno]) >= DynamoNode.R:
_logger.info("%s: read %d copies of %s=? so done", self, DynamoNode.R, getrsp.key)
# _logger.debug(" copies at %s", [(node.name, value) for (node, value, _) in self.pending_get_rsp[seqno]])
# Coalesce all compatible (value, metadata) pairs across the responses
results = VectorClock.coalesce2([(value, metadata) for (node, value, metadata) in self.pending_get_rsp[seqno]])
# Tidy up tracking data structures
original_msg = self.pending_get_msg[seqno]
del self.pending_req[GetReq][seqno]
del self.pending_get_rsp[seqno]
del self.pending_get_msg[seqno]
# Reply to the original client, including all received values
client_getrsp = ClientGetRsp(original_msg,
[value for (value, metadata) in results],
[metadata for (value, metadata) in results])
#modified
con = self.connections[self.servers.index(client_getrsp.to_node)]
Framework.send_message(client_getrsp, con)
########################################
else:
pass # Superfluous reply
示例3: rcv_clientput
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import send_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
示例4: retry_failed_node
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import send_message [as 别名]
def retry_failed_node(self, _): # Permanently repeating timer
if self.failed_nodes:
node = self.failed_nodes.pop(0)
# Send a test message to the oldest failed node
pingmsg = PingReq(self, node)
Framework.send_message(pingmsg)
# Restart the timer
TimerManager.start_timer(self, reason="retry", priority=15, callback=self.retry_failed_node)
示例5: rcv_put
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import send_message [as 别名]
def rcv_put(self, putmsg):
_logger.info("%s: store %s=%s", self, putmsg.key, putmsg.value)
self.store(putmsg.key, putmsg.value, putmsg.metadata)
if putmsg.handoff is not None:
for failed_node in putmsg.handoff:
self.failed_nodes.append(failed_node)
if failed_node not in self.pending_handoffs:
self.pending_handoffs[failed_node] = set()
self.pending_handoffs[failed_node].add(putmsg.key)
putrsp = PutRsp(putmsg)
Framework.send_message(putrsp)
示例6: put_message
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import send_message [as 别名]
def put_message(self, fromnode, key, value, metadata):
#print 'client put!!!'
metadata = pickle.loads(metadata)
if metadata is None:
metadata = VectorClock()
else:
# A Put operation always implies convergence
metadata = VectorClock.converge(metadata)
putmsg = ClientPut(fromnode, self.addr, key, value, metadata)
Framework.send_message(putmsg)
# Framework.schedule(timers_to_process=0)
Framework.schedule()
示例7: rcv_pingrsp
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import send_message [as 别名]
def rcv_pingrsp(self, pingmsg):
# Remove all instances of recovered node from failed node list
recovered_node = pingmsg.from_node
while recovered_node in self.failed_nodes:
self.failed_nodes.remove(recovered_node)
if recovered_node in self.pending_handoffs:
for key in self.pending_handoffs[recovered_node]:
# Send our latest value for this key
(value, metadata) = self.retrieve(key)
putmsg = PutReq(self, recovered_node, key, value, metadata)
Framework.send_message(putmsg)
del self.pending_handoffs[recovered_node]
示例8: rcv_putrsp
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import send_message [as 别名]
def rcv_putrsp(self, putrsp):
seqno = putrsp.msg_id
if seqno in self.pending_put_rsp:
self.pending_put_rsp[seqno].add(putrsp.from_node)
if len(self.pending_put_rsp[seqno]) >= DynamoNode.W:
_logger.info("%s: written %d copies of %s=%s so done", self, DynamoNode.W, putrsp.key, putrsp.value)
_logger.debug(" copies at %s", [node.name for node in self.pending_put_rsp[seqno]])
# Tidy up tracking data structures
original_msg = self.pending_put_msg[seqno]
del self.pending_put_rsp[seqno]
del self.pending_put_msg[seqno]
# Reply to the original client
client_putrsp = ClientPutRsp(original_msg)
Framework.send_message(client_putrsp)
else:
pass # Superfluous reply
示例9: retry_request
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import send_message [as 别名]
def retry_request(self, reqmsg):
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:
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)
Framework.send_message(newreqmsg)
示例10: rcv_pingrsp
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import send_message [as 别名]
def rcv_pingrsp(self, pingmsg):
# Remove all instances of recovered node from failed node list
recovered_node = pingmsg.from_node
while recovered_node in self.failed_nodes:
self.failed_nodes.remove(recovered_node)
Framework.clearBlock(recovered_node)
if recovered_node in self.pending_handoffs:
for key in self.pending_handoffs[recovered_node]:
#print 'recovery ---------------------------------'
# Send our latest value for this key
(value, metadata) = self.retrieve(key)
putmsg = PutReq(self, recovered_node, key, value, metadata)
Framework.send_message(putmsg)
#print 'schedule'
Framework.schedule(timers_to_process=0)
del self.pending_handoffs[recovered_node]
示例11: recovery
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import send_message [as 别名]
def recovery(self, node):
# Remove all instances of recovered node from failed node list
#print 'recover+++++++++++++++++++++++++++'
recovered_node = node
while recovered_node in self.failed_nodes:
self.failed_nodes.remove(recovered_node)
Framework.clearBlock(recovered_node)
if recovered_node in self.pending_handoffs:
for key in self.pending_handoffs[recovered_node]:
#print 'recovery ---------------------------------'
# Send our latest value for this key
(value, metadata) = self.retrieve(key)
putmsg = PutReq(self.addr, recovered_node, key, value, metadata)
Framework.send_message(putmsg)
Framework.schedule()
del self.pending_handoffs[recovered_node]
示例12: put
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import send_message [as 别名]
def put(self, key, metadata, value, destnode=None):
# print "node: ",len(DynamoNode.nodelist)
#modified
temp = metadata
while True:
###################################
metadata = temp
if destnode is None: # Pick a random node to send the request to
destnode = random.choice(DynamoNode.nodelist)
# Input metadata is always a sequence, but we always need to insert a
# single VectorClock object into the ClientPut message
# print '-------------------------choice:', destnode
if len(metadata) == 1 and metadata[0] is None:
metadata = VectorClock()
else:
# A Put operation always implies convergence
metadata = VectorClock.converge(metadata)
putmsg = ClientPut(self.addr, destnode, key, value, metadata)
#modified
con = self.connections[self.servers.index(destnode)]
result = Framework.send_message(putmsg, con)
if result is not False:
break
destnode = None
##################################
return result
示例13: rcv_pingreq
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import send_message [as 别名]
def rcv_pingreq(self, pingmsg):
# Always reply to a test message
pingrsp = PingRsp(pingmsg)
# print '-------------------------------------pingreq', pingmsg.from_node, pingmsg.to_node
#modified
con = self.connections[self.servers.index(pingrsp.to_node)]
result = Framework.send_message(pingrsp, con)
if result is False and pingrsp.to_node not in self.failed_nodes:
self.failed_nodes.append(pingrsp.to_node)
示例14: rcv_clientget
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import send_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
示例15: rcv_getrsp
# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import send_message [as 别名]
def rcv_getrsp(self, getrsp):
seqno = getrsp.msg_id
if seqno in self.pending_get_rsp:
self.pending_get_rsp[seqno].add((getrsp.from_node, getrsp.value, getrsp.metadata))
if len(self.pending_get_rsp[seqno]) >= DynamoNode.R:
_logger.info("%s: read %d copies of %s=? so done", self, DynamoNode.R, getrsp.key)
_logger.debug(" copies at %s", [(node.name, value) for (node, value, _) in self.pending_get_rsp[seqno]])
# Build up all the distinct values/metadata values for the response to the original request
results = set([(value, metadata) for (node, value, metadata) in self.pending_get_rsp[seqno]])
# Tidy up tracking data structures
original_msg = self.pending_get_msg[seqno]
del self.pending_get_rsp[seqno]
del self.pending_get_msg[seqno]
# Reply to the original client, including all received values
client_getrsp = ClientGetRsp(original_msg,
[value for (value, metadata) in results],
[metadata for (value, metadata) in results])
Framework.send_message(client_getrsp)
else:
pass # Superfluous reply