簡體   English   中英

使用swing啟動Jade代理

[英]Launch Jade agents using swing

我編寫了一個數據庫更新軟件,允許我部署一個玉移動代理,以更新數據庫。 為了運行它,我需要使用AMS gui啟動它。 我希望能夠從gui發布它。 我現在做了一個很好的搖擺gui,我只需要知道允許我在點擊“更新”按鈕時啟動我的移動代理的代碼。 代碼是什么? 提前致謝。

要啟動代理或執行與JADE相關的任何操作,您需要使用JADE庫和API編寫代碼,而不管您使用的是什么前端(在這種情況下為Swing)一個建議是,為了保持模塊性,創建另一個文件它可以執行您想要的許多此類操作之一,並讓您的Swing GUI與該文件進行交互(例如通過套接字),從而觸發您的操作。 該文件將充當服務器,將收聽前端並執行相應的工作。 但是所有命令都要使用JADE API進行編碼。 一個這樣的代碼是:

ContainerController cc = Runtime.instance().createAgentContainer(newProfileImpl());

Object arguments[] = new Object[1];``arguments[0]=new Object();

AgentController dummy = cc.createNewAgent("mob2","mobiletrial", arguments);

dummy.start();

這是我為從另一個代理啟動一個代理而編寫的方法。您需要編輯它以便多個容器使用。

void launchAgent( final String AgentName, final String AgentType)
{
    log(Level.FINER,"attempting to launch angent name: "+AgentName+" type: "+AgentType);
    CreateAgent ca = new CreateAgent();
    ca.setAgentName(AgentName);
    ca.setClassName(AgentType);
    ca.setContainer(new ContainerID(AgentContainer.MAIN_CONTAINER_NAME, null));
    Action actExpr = new Action(this.getAMS(), ca);
    ACLMessage request = new ACLMessage(ACLMessage.REQUEST);
    request.addReceiver(this.getAMS());

    request.setOntology(JADEManagementOntology.getInstance().getName());


    request.setLanguage(FIPANames.ContentLanguage.FIPA_SL);
    request.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST);
    try {
        getContentManager().fillContent(request, actExpr);

        addBehaviour(new AchieveREInitiator(this, request) {
            protected void handleInform(ACLMessage inform) {
            log(Level.INFO,"Agent successfully created name:"+AgentName+" type: "+AgentType);
            }

        protected void handleFailure(ACLMessage failure) {
            log(Level.SEVERE,"Agent launch failed name: "+AgentName+" type: "+AgentType);
            }
            } );
        }
    catch (Exception e) {
        e.printStackTrace();
        }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM