当前位置: 首页>>代码示例>>Python>>正文


Python HashRing.remove方法代码示例

本文整理汇总了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)
开发者ID:atl,项目名称:thrifty-p2p,代码行数:53,代码来源:location.py


注:本文中的hash_ring.HashRing.remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。