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


Python Message.create_message_from_json方法代码示例

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


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

示例1: candidate_receive_message

# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import create_message_from_json [as 别名]
    def candidate_receive_message(self, msg):
        """
        All Candidate Message Receiving
        @:param msg - the JSON message received
        @:return: Void
        """
        if msg['type'] == 'vote':
            #print str(self.id) + ": Got Vote Message----------"
            message = Message.create_message_from_json(msg)
            self.receive_vote(message)

        if msg['type'] == 'heartbeat':
            #print str(self.id) + "got ~~~HEARTBEAT~~~"
            heart_beat = Message.create_message_from_json(msg)

            if heart_beat.term >= self.current_term:
                self.current_term = heart_beat.term
                self.become_follower(heart_beat.leader)

        if msg['type'] == 'voteRequest':
            message = Message.create_message_from_json(msg)
            if message.term > self.current_term:
                self.become_follower(msg['leader'])

        if msg['type'] in ['get', 'put']:
            message = Message.create_message_from_json(msg)
            redirect_message = message.create_redirect_message("FFFF")

            self.send(redirect_message)
开发者ID:ajdcolcord,项目名称:CS3700_Project5,代码行数:31,代码来源:Server.py

示例2: leader_receive_message

# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import create_message_from_json [as 别名]
    def leader_receive_message(self, msg):
        """
        All Leader Message Receiving
        @:param msg - the JSON message received
        @:return: Void
        """
        if msg['type'] in ['get', 'put']:
            # print ":" + str(self.id) + " :LEADER: RECV: " + msg['type'] + " : mid= " + msg['MID']
            self.add_to_client_queue(msg)


        # elif msg['type'] == 'heartbeatACK':
        #     print ":" + self.id + " :LEADER: RECV: " + msg['type'] + " : mid= " + str(msg['MID'])
        #     self.get_new_election_timeout()
        #     # TODO: commit log entry yet?????

        if msg['type'] == 'heartbeat':
            # print ":" + str(self.id) + " :LEADER: RECV: " + msg['type'] + " : mid= " + str(msg['MID'])
            message = Message.create_message_from_json(msg)

            if message.term > self.current_term:
                # print ":" + str(self.id) + " :LEADER: RECV: BECOMING FOLLOWER 0"
                self.become_follower(message.leader)

        if msg['type'] == 'voteRequest':
            # print ":" + str(self.id) + " :LEADER: RECV: " + msg['type'] + " : mid= " + str(msg['MID'])
            message = Message.create_message_from_json(msg)
            if message.term > self.current_term:
                if len(self.log):
                    if msg['last_entry_term'] >= self.log[-1][1] and msg['log_size'] >= len(self.log):
                        # print ":" + str(self.id) + " :LEADER: RECV: BECOMING FOLLOWER 1"
                        self.become_follower(msg['leader'])
                        #self.voted_for = msg['src']
                else:
                    # print ":" + str(self.id) + " :LEADER: RECV: BECOMING FOLLOWER 2"
                    self.become_follower(msg['leader'])
                    #self.voted_for = msg['src']

        if msg['type'] == 'appendACK':
            # print ":" + str(self.id) + " :LEADER: RECV: " + msg['type'] + " : src= " + str(msg['src'])
            self.receive_append_ack(msg)
开发者ID:ajdcolcord,项目名称:CS3700_Project5,代码行数:43,代码来源:Server.py

示例3: receive_heartbeat

# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import create_message_from_json [as 别名]
 def receive_heartbeat(self, msg):
     """
     Run the functions necessary when receiving a heartbeat, only if the heartbeat is 'valid'
     @:param msg - the message (json) from the leader
     @:return: Void
     """
     if msg['term'] >= self.current_term:
         heart_beat = Message.create_message_from_json(msg)
         self.current_term = heart_beat.term
         self.leader_id = heart_beat.leader
         self.get_new_election_timeout()
         self.run_command_follower(msg['leader_last_applied'])
开发者ID:ajdcolcord,项目名称:CS3700_Project5,代码行数:14,代码来源:Server.py

示例4: receive_vote_request_as_follower

# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import create_message_from_json [as 别名]
    def receive_vote_request_as_follower(self, msg):
        """
        Run the desired functions when receiving a vote request from a Candidate
        @:param msg - the json message received from the candidate
        @:return: Void
        """
        #print str(self.id) + ": RECEIVED VOTE REQUEST from: " + str(msg['src']) + " time=" + str(datetime.datetime.now())

        vote_req_message = Message.create_message_from_json(msg)

        if vote_req_message.term >= self.current_term:
            if self.voted_for is None or self.voted_for == vote_req_message.src:
                if len(self.log):
                    if msg['last_entry_term'] >= self.log[-1][1] and msg['log_size'] >= len(self.log):
                        self.send_vote(vote_req_message)
                        self.get_new_election_timeout()
                else:
                    self.send_vote(vote_req_message)
                    self.get_new_election_timeout()
开发者ID:ajdcolcord,项目名称:CS3700_Project5,代码行数:21,代码来源:Server.py

示例5: follower_receive_message

# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import create_message_from_json [as 别名]
    def follower_receive_message(self, msg):
        """
        All Follower Message Receiving
        @:param msg - the JSON message received
        @:return: Void
        """
        if msg['type'] == 'heartbeat':
            self.receive_heartbeat(msg)

        if msg['type'] == 'voteRequest':
            self.receive_vote_request_as_follower(msg)

        if msg['type'] in ['get', 'put']:
            message = Message.create_message_from_json(msg)
            redirect_message = message.create_redirect_message(self.leader_id)

            self.send(redirect_message)

        if msg['type'] == 'appendEntry':
            self.receive_append_entry(msg)
开发者ID:ajdcolcord,项目名称:CS3700_Project5,代码行数:22,代码来源:Server.py


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