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 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)