Example #1
0
def runAgent():
    signal.signal(signal.SIGINT, handler)
    signal.signal(signal.SIGTERM, handler)
    print("Loading " + AGENT_NAME + " ...\n")
    mAction = BoardAction()
    mAgent = Transport()
    mAction.set_mAgent(mAgent)
    mAction.register()
    fm = FIPAMessage()
    msg_id=[]
    while True:
        time.sleep(1)
        rcv = mAgent.receive_data_from_agents()
        if not len(rcv) == 0:
            match = re.search("message-id:(.\w+\-\w+)", rcv)
            if match:
                message_id = match.group(1).lstrip()
                if message_id in msg_id:
                    continue
                else:
                    msg_id.append(message_id)
                    fm.parse_pkg(rcv)
                    print(rcv)
                    mAgent.zera_buff()
            else:
                print(rcv)
Example #2
0
    def receive_pkg(self, mAgent):
        fm = FIPAMessage()
        while True:
            time.sleep(1)
            rcv = mAgent.receive_data_from_agents()
            if not len(rcv) == 0:
                fm.parse_pkg(rcv)
                match = re.search("message-id:(.\w+\-\w+)", rcv)
                if match:
                    message_id = match.group(1).lstrip()
                    if message_id in self.msg_id:
                        continue
                    else:
                        self.msg_id.append(message_id)
                        mAgent.zera_buff()
                        receiver = fm.get_receiver()
                        sender = fm.get_sender()
                        if receiver == ALL_AGENTS or receiver == AGENT_NAME:
                            if sender != AGENT_NAME:
                                self.parse_action(fm)
                            #break
                        else:
                            print(rcv)
                        #break

                else:
                    print(rcv)
                    break
Example #3
0
def runAgent():
    signal.signal(signal.SIGINT, handler)
    signal.signal(signal.SIGTERM, handler)

    print("Loading %s...\n" % AGENT_NAME)

    toAgent = "All Agents"
    content = ("Register Agent (= (agent-name) (" + AGENT_NAME + "))\n")
    reply_with = utl.id_generator()
    conversation_id = utl.id_gen()
    mAction = WebInfraAction()
    mAgent = Transport()
    mAction.set_mAgent(mAgent)
    mAction.registerAgent()
    fm = FIPAMessage()
    agent_id = []
    while True:
        time.sleep(1)
        rcv = mAgent.receive_data_from_agents()
        if not len(rcv) == 0:
            fm.parse_pkg(rcv)
            match = re.search("(agent-name(.)+)(\(\w+\))", rcv)
            if match:
                field = match.group(3).lstrip()
                match2 = re.search("\w+", field)
                if match2:
                    agt_id = match2.group(0)

                if agt_id in agent_id:
                    continue
                else:
                    print("agentID: ", agt_id)
                    agent_id.append(agt_id)
                    print(rcv)
                    mAction.add_avaiable_agent(agt_id)
                    break
            else:
                print(rcv)

    mAction = WebInfraAction()
    mAgent = Transport()
    mAction.set_mAgent(mAgent)
    #request url base to check
    toAgent = "AgentTarget"
    ret = mAction.requestUrlBase(toAgent)
    mAction.receive_pkg(mAgent)
Example #4
0
def runAgent(toAgent, Question):
    signal.signal(signal.SIGINT, handler)
    signal.signal(signal.SIGTERM, handler)
    print("Loading " + AGENT_NAME + " ...\n")
    mAction = QuestionAction()
    mAgent = Transport()
    mAction.set_mAgent(mAgent)
    mAction.register()
    fm = FIPAMessage()
    msg_id = []
    agent_id = []
    while True:
        time.sleep(1)
        rcv = mAgent.receive_data_from_agents()
        if not len(rcv) == 0:
            fm.parse_pkg(rcv)
            match = re.search("(agent-name(.)+)(\(\w+\))", rcv)
            if match:
                field = match.group(3).lstrip()
                match2 = re.search("\w+", field)
                if match2:
                    agt_id = match2.group(0)

                if agt_id in agent_id:
                    continue
                else:
                    print("agentID: ", agt_id)
                    agent_id.append(agt_id)
                    print(rcv)
                    mAction.add_avaiable_agent(agt_id)
                    break
            else:
                continue
                #print(rcv)

    mAction = QuestionAction()
    mAgent = Transport()
    mAction.set_mAgent(mAgent)
    ret = mAction.sendQuestion(toAgent, Question)
    mAction.receive_pkg(mAgent)
    mAgent.send_disconnect()
    time.sleep(2)

    agent_quit()
Example #5
0
def runAgent():
    signal.signal(signal.SIGINT, handler)
    signal.signal(signal.SIGTERM, handler)
    print("Loading MasterAgent...\n")
    mAgent = Transport()
    mAction = MasterAction()
    mAction.set_mAgent(mAgent)
    mAction.registerAgent()
    fm = FIPAMessage()
    agent_id = []
    while True:
        time.sleep(1)
        rcv = mAgent.receive_data_from_agents()
        if not len(rcv) == 0:
            fm.parse_pkg(rcv)
            match = re.search("(agent-name(.)+)(\(\w+\))", rcv)
            if match:
                field = match.group(3).lstrip()
                match2 = re.search("\w+", field)
                if match2:
                    agt_id = match2.group(0)

                if agt_id in agent_id:
                    continue
                else:
                    print("agentID: ", agt_id)
                    agent_id.append(agt_id)
                    print(rcv)
                    mAction.add_available_agent(agt_id)
                    break
            else:
                print(rcv)

    print("Avaiable Agents: ", mAction.get_available_agents())

    mAgent = Transport()
    mAction = MasterAction()
    mAction.set_mAgent(mAgent)
    mAction.cfp("master-agent", "*")

    msg_id = []
    while True:
        time.sleep(1)
        rcv = mAgent.receive_data_from_agents()
        if not len(rcv) == 0:
            fm.parse_pkg(rcv)
            match = re.search("message-id:(.\w+\-\w+)", rcv)
            if match:
                message_id = match.group(1).lstrip()
                if message_id in msg_id:
                    continue
                else:
                    msg_id.append(message_id)
                    print(rcv)
                    mAgent.zera_buff()
                    break
            else:
                print(rcv)

    p = Process(target=get_url_base())
    p.start()
    p.join(3)