本文整理汇总了Python中hash_ring.HashRing.remove方法的典型用法代码示例。如果您正苦于以下问题:Python HashRing.remove方法的具体用法?Python HashRing.remove怎么用?Python HashRing.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hash_ring.HashRing
的用法示例。
在下文中一共展示了HashRing.remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LocatorHandler
# 需要导入模块: from hash_ring import HashRing [as 别名]
# 或者: from hash_ring.HashRing import remove [as 别名]
class LocatorHandler(BaseHandler, Locator.Iface):
def __init__(self, peer=None, port=9900):
self.address = socket.gethostbyname(socket.gethostname())
self.port = port
self.peer = peer
self.ring = HashRing()
try:
ping(self.location)
print 'Uh-oh. Our location responded to a ping!'
raise socket.error(43, 'Address already in use')
except NodeNotFound:
pass
@property
def here(self):
"Give the canonical string representation"
return loc2str(self)
@property
def location(self):
"Give the canonical Location"
return Location(address=self.address, port=self.port)
def join(self, location):
"""
Parameters:
- location
"""
self.add(location, [self.location])
ping_until_return(location)
items = self.ring.nodes.difference([loc2str(location)])
def remove(self, location, authorities):
"""
Parameters:
- location
- authorities
"""
key = loc2str(location)
self.ring.remove(loc2str(location))
authorities.append(self.location)
destinations = select_peers(self.ring.nodes.difference(map(loc2str,authorities)))
for destination in destinations:
try:
remote_call('remove', str2loc(destination), location, authorities)
break
except NodeNotFound, tx:
# enter all nodes as authorities to avoid race conditions
# lazy invalidation
self.remove(tx.location, map(str2loc, self.ring.nodes))
print "removed %s:%d" % (location.address, location.port)