代理servlet通信

时间:2016-05-14 21:16:42

标签: servlets agents-jade

我刚刚开始使用Jade,我想知道是否可以使用JadeGateway从代理向servlet发送消息,我已经设法从servlet向代理发送消息,但我想要那个代理人回复回复,似乎没有什么对我有用 这是我的servlet的doPost方法:

String champ = request.getParameter("action");
            try {
                JadeGateway.execute(new OneShotBehaviour() {
                    @Override
                    public void action() {
                        out.println("action");
                        final ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
                        AID theAgent = new AID("Agent47", false);
                        msg.addReceiver(theAgent);
                        msg.setConversationId("Agent servlet communication");
                        msg.setContent(champ);
                        myAgent.send(msg);
                        ACLMessage res = myAgent.receive();
                        if (res != null) {
                            System.out.println(res.getContent());
                        }
                    }
                });

servlet将用户在jsp页面中输入的数据发送给代理。 这是代理人的代码:

//The cyclic behaviour i added to the agent
public class ProcessExternalRequests extends CyclicBehaviour {
    private MessageTemplate mt;
    @Override
    public void action() {
        mt = MessageTemplate.MatchConversationId("Agent servlet communication");
        ACLMessage msg = myAgent.receive(mt);
        if(msg!=null){
            if(msg.getPerformative()==ACLMessage.REQUEST){
                String content = msg.getContent();
                System.out.println("Agent " + myAgent.getAID().getLocalName() + " Content = " + content);
                //Response
                ACLMessage res = new ACLMessage(ACLMessage.CONFIRM);
                res.addReceiver(msg.getSender());
                res.setContent("Bien reçu!");
                myAgent.send(res);
            }
        }else{
            block();
        }

我的问题是代理不会将消息发送回servlet。我该怎么办?

0 个答案:

没有答案