繁体   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