本文整理汇总了Python中framework.Framework类的典型用法代码示例。如果您正苦于以下问题:Python Framework类的具体用法?Python Framework怎么用?Python Framework使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Framework类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rcv_getrsp
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
示例2: 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 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
示例3: rcv_clientput
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
示例4: __init__
def __init__(self, addr, config_file='server_config'):
super(DynamoNode, self).__init__()
self.local_store = MerkleTree() # key => (value, metadata)
self.pending_put_rsp = {} # seqno => set of nodes that have stored
self.pending_put_msg = {} # seqno => original client message
self.pending_get_rsp = {} # seqno => set of (node, value, metadata) tuples
self.pending_get_msg = {} # seqno => original client message
# seqno => set of requests sent to other nodes, for each message class
self.pending_req = {PutReq: {}, GetReq: {}}
self.failed_nodes = []
self.pending_handoffs = {}
# Rebuild the consistent hash table
self.addr = addr
self.servers = []
self.db = leveldb.LevelDB('./' + addr + '_db')
f = open(config_file, 'r')
for line in f.readlines():
line = line.rstrip()
self.servers.append(line)
for i, server in enumerate(self.servers):
DynamoNode.nodelist.append(server)
DynamoNode.chash = ConsistentHashTable(DynamoNode.nodelist, DynamoNode.T)
# Run a timer to retry failed nodes
#self.pool = gevent.pool.Group()
#self.pool.spawn(self.retry_failed_node)
Framework.setNodes(DynamoNode.nodelist)
示例5: test_simple_put
def test_simple_put(self):
for _ in range(6):
dynamo1.DynamoNode()
a = dynamo1.DynamoClientNode('a')
a.put('K1', None, 1)
Framework.schedule()
print History.ladder()
示例6: __init__
def __init__(self, gui):
Framework.__init__(self, gui)
ground = self.world.create_body()
body = self.world.create_static_body(
position=(0, -8),
allow_sleep=False,
shape_fixture=b2d.fixture_def(density=5.0),
shapes=[
b2d.polygon_shape((0.5, 10), (10, 0), 0),
b2d.polygon_shape((0.5, 10), (-10, 0), 0),
b2d.polygon_shape((10, 0.5), (0, 10), 0),
b2d.polygon_shape((10, 0.5), (0, -10), 0),
]
)
pdef = b2d.particle_system_def(viscous_strength=100,spring_strength=0.0)
self.psystem = self.world.create_particle_system(pdef)
self.psystem.radius = 0.3
self.psystem.damping = 0.2
pgDef = b2d.particle_group_def(flags=b2d.ParticleFlag.waterParticle,
group_flags=b2d.ParticleGroupFlag.solidParticleGroup,
strength=0.0)
self.group = self.psystem.create_particle_group(pgDef)
示例7: test_put2_fail_nodes23_2
def test_put2_fail_nodes23_2(self):
"""Show second request for same key skipping failed nodes"""
(a, pref_list) = self.put_fail_nodes23(dynamo2)
coordinator = pref_list[0]
from_line = len(History.history)
a.put('K1', None, 2, destnode=coordinator) # Send client request to coordinator for clarity
Framework.schedule()
print History.ladder(force_include=pref_list, start_line=from_line, spacing=16)
示例8: retry_failed_node
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)
示例9: test_put2_fail_nodes23_5
def test_put2_fail_nodes23_5(self):
"""Show Put after a failure including handoff, and the resulting Pings"""
(a, pref_list) = self.put_fail_nodes23(dynamo4)
coordinator = pref_list[0]
from_line = len(History.history)
a.put('K1', None, 2, destnode=coordinator) # Send client request to coordinator for clarity
Framework.schedule(timers_to_process=10)
print History.ladder(force_include=pref_list, start_line=from_line, spacing=16)
示例10: step
def step(self, settings):
Framework.step(self, settings)
r = random.random()
px =(random.random() - 0.5)*10.0
py =(random.random() - 0.5)*2.0
if self.step_count < 1500:
pd = b2d.particle_def(group=self.group, position=(px, py))#, velocity=(vx,vy))
self.psystem.create_particle(pd)
示例11: test_put2_fail_nodes23_3
def test_put2_fail_nodes23_3(self):
"""Show PingReq failing"""
(a, pref_list) = self.put_fail_nodes23(dynamo4)
coordinator = pref_list[0]
a.put('K1', None, 2, destnode=coordinator) # Send client request to coordinator for clarity
Framework.schedule(timers_to_process=0)
from_line = len(History.history)
Framework.schedule(timers_to_process=3)
print History.ladder(force_include=pref_list, start_line=from_line, spacing=16)
示例12: test_partition_restore_metadata
def test_partition_restore_metadata(self):
self.partition()
self.partition_repair()
# Put a new value, which coalesces
a = Node.node['a']
getrsp = a.last_msg
putmsg = a.put('K1', getrsp.metadata, 101)
Framework.schedule(timers_to_process=0)
print putmsg.metadata
示例13: put_fail_initial_node
def put_fail_initial_node(self, cls):
for _ in range(6):
cls.DynamoNode()
a = cls.DynamoClientNode('a')
destnode = random.choice(cls.DynamoNode.nodelist)
a.put('K1', None, 1, destnode=destnode)
# Fail at the forwarding node before it gets a chance to forward
destnode.fail()
Framework.schedule()
print History.ladder()
示例14: test_double_put
def test_double_put(self):
for _ in range(6):
dynamo1.DynamoNode()
a = dynamo1.DynamoClientNode('a')
b = dynamo1.DynamoClientNode('b')
a.put('K1', None, 1)
Framework.schedule(1)
b.put('K2', None, 17)
Framework.schedule()
print History.ladder(spacing=14)
示例15: test_simple_get
def test_simple_get(self):
for _ in range(6):
dynamo1.DynamoNode()
a = dynamo1.DynamoClientNode('a')
a.put('K1', None, 1)
Framework.schedule()
from_line = len(History.history)
a.get('K1')
Framework.schedule()
print History.ladder(start_line=from_line)