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


Python KVMsg.key方法代码示例

本文整理汇总了Python中kvmsg.KVMsg.key方法的典型用法代码示例。如果您正苦于以下问题:Python KVMsg.key方法的具体用法?Python KVMsg.key怎么用?Python KVMsg.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kvmsg.KVMsg的用法示例。


在下文中一共展示了KVMsg.key方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_snapshot

# 需要导入模块: from kvmsg import KVMsg [as 别名]
# 或者: from kvmsg.KVMsg import key [as 别名]
    def handle_snapshot(self, msg):
        """snapshot requests"""

        logging.info("I: received state request on snapshot: %s" % msg)
        if len(msg) != 3 or msg[1] != "ICANHAZ?":
            print "E: bad request, aborting"
            dump(msg)
            self.loop.stop()
            return
        identity, request, subtree = msg
        if subtree:
            # Send state snapshot to client
            route = Route(self.snapshot, identity, subtree)

            # For each entry in kvmap, send kvmsg to client
            for k, v in self.kvmap.items():
                logging.info("I: Sending snapshot: %s" % v)
                send_single(k, v, route)

            # Now send END message with sequence number
            self.snapshot.send(identity, zmq.SNDMORE)
            kvmsg = KVMsg(self.sequence)
            kvmsg.key = "KTHXBAI"
            kvmsg.body = subtree
            logging.info("I: Sending snapshot end message: %s" % kvmsg)
            kvmsg.send(self.snapshot)
开发者ID:luafran,项目名称:pybackend,代码行数:28,代码来源:clonesrv5.py

示例2: handle_snapshot

# 需要导入模块: from kvmsg import KVMsg [as 别名]
# 或者: from kvmsg.KVMsg import key [as 别名]
    def handle_snapshot(self, socket, msg):
        """snapshot requests"""
        if msg[1] != "ICANHAZ?" or len(msg) != 3:
            logging.error("E: bad request, aborting")
            dump(msg)
            self.bstar.loop.stop()
            return
        identity, request = msg[:2]
        if len(msg) >= 3:
            subtree = msg[2]
            # Send state snapshot to client
            route = Route(socket, identity, subtree)

            # For each entry in kvmap, send kvmsg to client
            for k,v in self.kvmap.items():
                send_single(k,v,route)
            
            # Now send END message with sequence number
            logging.info("I: Sending state shapshot=%d" % self.sequence)
            socket.send(identity, zmq.SNDMORE)
            kvmsg = KVMsg(self.sequence)
            kvmsg.key = "KTHXBAI"
            kvmsg.body = subtree
            kvmsg.send(socket)
开发者ID:343829084,项目名称:zguide,代码行数:26,代码来源:clonesrv6.py

示例3: send_hugz

# 需要导入模块: from kvmsg import KVMsg [as 别名]
# 或者: from kvmsg.KVMsg import key [as 别名]
 def send_hugz(self):
     """Send hugz to anyone listening on the publisher socket"""
     kvmsg = KVMsg(self.sequence)
     kvmsg.key = "HUGZ"
     kvmsg.body = ""
     kvmsg.send(self.publisher)
开发者ID:343829084,项目名称:zguide,代码行数:8,代码来源:clonesrv6.py

示例4: main

# 需要导入模块: from kvmsg import KVMsg [as 别名]
# 或者: from kvmsg.KVMsg import key [as 别名]
def main():
    
    # Prepare our context and subscriber
    ctx = zmq.Context()
    snapshot = ctx.socket(zmq.DEALER)
    snapshot.linger = 0
    snapshot.connect("tcp://localhost:5556")
    subscriber = ctx.socket(zmq.SUB)
    subscriber.linger = 0
    subscriber.setsockopt(zmq.SUBSCRIBE, SUBTREE)
    subscriber.connect("tcp://localhost:5557")
    publisher = ctx.socket(zmq.PUB)
    publisher.linger = 0
    publisher.connect("tcp://localhost:5558")

    random.seed(time.time())
    kvmap = {}

    # Get state snapshot
    sequence = 0
    snapshot.send_multipart(["ICANHAZ?", SUBTREE])
    while True:
        try:
            kvmsg = KVMsg.recv(snapshot)
        except:
            raise
            return          # Interrupted
            
        if kvmsg.key == "KTHXBAI":
            sequence = kvmsg.sequence
            print "I: Received snapshot=%d" % sequence
            break          # Done
        kvmsg.store(kvmap)
    
    poller = zmq.Poller()
    poller.register(subscriber, zmq.POLLIN)
    
    alarm = time.time()+1.
    while True:
        tickless = 1000*max(0, alarm - time.time())
        try:
            items = dict(poller.poll(tickless))
        except:
            break           # Interrupted
        
        if subscriber in items:
            kvmsg = KVMsg.recv(subscriber)

            # Discard out-of-sequence kvmsgs, incl. heartbeats
            if kvmsg.sequence > sequence:
                sequence = kvmsg.sequence
                kvmsg.store(kvmap)
                action = "update" if kvmsg.body else "delete"
                print "I: received %s=%d" % (action, sequence)
        
        # If we timed-out, generate a random kvmsg
        if time.time() >= alarm:
            kvmsg = KVMsg(0)
            kvmsg.key = SUBTREE + "%d" % random.randint(1,10000)
            kvmsg.body = "%d" % random.randint(1,1000000)
            kvmsg['ttl'] = random.randint(0,30)
            kvmsg.send(publisher)
            kvmsg.store(kvmap)
            alarm = time.time() + 1.

    print " Interrupted\n%d messages in" % sequence
开发者ID:Alex-Benveniste,项目名称:zguide,代码行数:68,代码来源:clonecli5.py


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