3

我编写了一个数据库更新软件,它允许我部署一个玉移动代理来更新数据库。为了让它运行,我需要使用 AMS gui 启动它。我希望能够从 gui 启动它。我现在已经完成了一个不错的 swing gui,我只需要知道允许我在单击“更新”按钮时启动我的移动代理的代码。代码是什么?提前致谢。

4

2 回答 2

1

要启动代理或执行与 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();

于 2012-05-06T11:50:15.407 回答
0

这是我编写的用于从另一个代理启动一个代理的方法。您必须对其进行编辑以供多个容器使用。

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();
        }
}
于 2014-12-15T15:58:01.513 回答