/** * Send cfps to all receivers. * @param cfp The cfp. * @param convid The conversation id. * @param receivers The receivers. */ protected void sendCFP(Object cfp, String convid, List receivers) { // Send CFP. IMessageEvent cfpm = getEventbase().createMessageEvent("da_cfp"); cfpm.getParameterSet(SFipa.RECEIVERS).addValues(receivers.toArray()); cfpm.getParameter(SFipa.CONTENT).setValue(cfp); cfpm.getParameter(SFipa.CONVERSATION_ID).setValue(convid); getLogger().info(getComponentName() + ": cfp(" + cfp + ")"); sendMessage(cfpm); }
/** * Dispatch a message event. */ public IFuture<Void> sendMessageEvent(IMessageEvent message) { IMessageFeature mf = component.getComponentFeature(IMessageFeature.class); return mf.sendMessage((Map<String, Object>)message.getMessage(), message.getMessageType()); }
/** * Process the second answer. */ protected void handleSecondAnswer(IMessageEvent answer) { getLogger().info("Second answer: " + answer +" "+this); if(answer.getType().equals(getShortProtocolName()+"_failure")) { Object content = answer.getParameter(SFipa.CONTENT).getValue(); getLogger().info(getScope().getAgentName() + ": Received failure: " + content); requestFinished(false, new Object[]{answer.getType(), content}); } else if(answer.getType().equals(getShortProtocolName()+"_inform")) { Object content = answer.getParameter(SFipa.CONTENT).getValue(); getLogger().info(getScope().getAgentName() + ": Protocol succeeded."); requestFinished(true, content); } else { assert false: "State should not be reached"; } }
/** * Execute the plan. */ public void body() { String eword = (String)((IMessageEvent)getReason()).getParameter(SFipa.CONTENT).getValue(); String gword = (String)wordtable.get(eword); //getLogger().info("Translating from english to german: "+eword+" - "+gword); System.out.println("Translating from english to german: "+eword+" - "+gword); }
cancel.getParameterSet(SFipa.RECEIVERS).addValues(message.getParameterSet(SFipa.RECEIVERS).getValues()); cancel.getParameter(SFipa.CONVERSATION_ID).setValue(message.getParameter(SFipa.CONVERSATION_ID).getValue()); cancel.getParameter(SFipa.LANGUAGE).setValue(message.getParameter(SFipa.LANGUAGE).getValue()); cancel.getParameter(SFipa.ONTOLOGY).setValue(message.getParameter(SFipa.ONTOLOGY).getValue()); cancel.getParameter(SFipa.REPLY_WITH).setValue(SUtil.createUniqueId(getComponentName())); List<Object> rec = SUtil.arrayToList(message.getParameterSet(SFipa.RECEIVERS).getValues()); long timeout = ((Number)getParameter("timeout").getValue()).longValue(); long time = getTime(); rec.remove(reply.getParameter(SFipa.SENDER).getValue()); String response = "cm_inform".equals(reply.getType()) ? InteractionState.CANCELLATION_SUCCEEDED : "cm_failure".equals(reply.getType()) ? InteractionState.CANCELLATION_FAILED : InteractionState.CANCELLATION_UNKNOWN; state.addCancelResponse((IComponentIdentifier)reply.getParameter(SFipa.SENDER).getValue(), response, reply.getParameter(SFipa.CONTENT).getValue());
me.getParameterSet(SFipa.RECEIVERS).removeValues(); me.getParameterSet(SFipa.RECEIVERS).addValue(agents.get(0)); sendMessage(me).get(); tr.setSucceeded(true);
/** * Execute the plan. */ public void body() { System.out.println("Created: "+this); this.wordtable = new HashMap<String, String>(); this.wordtable.put("coffee", "Kaffee"); this.wordtable.put("milk", "Milch"); this.wordtable.put("cow", "Kuh"); this.wordtable.put("cat", "Katze"); this.wordtable.put("dog", "Hund"); String eword = (String)((IMessageEvent)getReason()).getParameter(SFipa.CONTENT).getValue(); String gword = (String)this.wordtable.get(eword); if(gword!=null) { System.out.println("Translating from english to german: "+eword+" - "+gword); } else { System.out.println("Sorry word is not in database: "+eword); } } }
request.getParameterSet(SFipa.RECEIVERS).addValue(getScope().getComponentIdentifier());
/** * Send cfps to all receivers. * @param cfp The cfp. * @param convid The conversation id. * @param receivers The receivers. */ protected void sendCFP(Object cfp, String convid, List receivers) { // Send CFP. IMessageEvent cfpm = getEventbase().createMessageEvent("ea_cfp"); cfpm.getParameterSet(SFipa.RECEIVERS).addValues(receivers.toArray()); cfpm.getParameter(SFipa.CONTENT).setValue(cfp); cfpm.getParameter(SFipa.CONVERSATION_ID).setValue(convid); getLogger().info(getComponentName() + ": cfp(" + cfp + ")"); sendMessage(cfpm); }
/** * Execute the plan. */ public void body() { System.out.println("Created: "+this); this.wordtable = new HashMap(); this.wordtable.put("coffee", "Kaffee"); this.wordtable.put("milk", "Milch"); this.wordtable.put("cow", "Kuh"); this.wordtable.put("cat", "Katze"); this.wordtable.put("dog", "Hund"); String eword = (String)((IMessageEvent)getReason()).getParameter(SFipa.CONTENT).getValue(); String gword = (String)this.wordtable.get(eword); if(gword!=null) { getLogger().info("Translating from english to german: "+eword+" - "+gword); } else { getLogger().info("Sorry word is not in database: "+eword); } } }
if(answer.getType().equals(getShortProtocolName()+"_not_understood") || answer.getType().equals(getShortProtocolName()+"_refuse") || answer.getType().equals(getShortProtocolName()+"_failure")) Object content = answer.getParameter(SFipa.CONTENT).getValue(); getLogger().info(getScope().getAgentName() + ": Received"+answer.getType() + content); requestFinished(false, new Object[]{answer.getType(), content}); else if(answer.getType().equals(getShortProtocolName()+"_agree")) else if(answer.getType().equals(getShortProtocolName()+"_inform"))
/** * Send a message after some delay. * @param me The message event. * @return The filter to wait for an answer. */ public IFuture<Void> sendMessage(IMessageEvent me) { return getAgent().getComponentFeature(IMessageFeature.class).sendMessage((Map<String, Object>)me.getMessage(), me.getMessageType()); }
me.getParameterSet(SFipa.RECEIVERS).addValue(getScope().getComponentIdentifier()); try
/** * Announce the planned auction. * @param auctiondesc the auction description. * @param receivers The receivers. * @param convid The conversation id. */ protected void announceAuction(Object auctiondesc, List receivers, String convid) { // Send the inform_start_auction-message to all receivers. start = getEventbase().createMessageEvent("da_inform_start_auction"); start.getParameterSet(SFipa.RECEIVERS).addValues(receivers.toArray()); start.getParameter(SFipa.CONTENT).setValue(auctiondesc); start.getParameter(SFipa.CONVERSATION_ID).setValue(convid); getLogger().info(getComponentName() + ": inform_start_auction"); getWaitqueue().addReply(start); sendMessage(start); }
String eword = (String)((IMessageEvent)getReason()).getParameter(SFipa.CONTENT).getValue(); try
if(removebidder.getType().equals("da_not_understood")) receivers.remove(removebidder.getParameter(SFipa.SENDER).getValue()); getLogger().info("Removed "+((IComponentIdentifier)removebidder.getParameter(SFipa.SENDER).getValue()).getName() + "."); getLogger().warning("Could not handle message of type "+removebidder.getType() +" from "+((IComponentIdentifier)removebidder.getParameter(SFipa.SENDER).getValue()).getName()+".");
/** * Create a reply to a message event. * @param event The received message event. * @param type The reply message event type. * @return The reply event. */ public IMessageEvent createReply(IMessageEvent event, String type) { if(event==null) throw new IllegalArgumentException("Event must not null"); MMessageEvent mevent = getCapability().getMCapability().getResolvedMessageEvent(scope, type); Map<String, Object> rep = event.getMessageType().createReply((Map<String, Object>)event.getMessage()); return new RMessageEvent(mevent, rep, SFipa.FIPA_MESSAGE_TYPE, getAgent()); }
/** * Announce the planned auction. * @param auctiondesc the auction description. * @param receivers The receivers. * @param convid The conversation id. */ protected void announceAuction(Object auctiondesc, List receivers, String convid) { // Send the inform_start_auction-message to all receivers. start = getEventbase().createMessageEvent("ea_inform_start_auction"); start.getParameterSet(SFipa.RECEIVERS).addValues(receivers.toArray()); start.getParameter(SFipa.CONTENT).setValue(auctiondesc); start.getParameter(SFipa.CONVERSATION_ID).setValue(convid); getLogger().info(getComponentName() + ":\tinform_start_auction"); getWaitqueue().addReply(start); sendMessage(start); }
String eword = (String)me.getParameter(SFipa.CONTENT).getValue(); String gword = (String)this.wordtable.get(eword); if(gword!=null)
if(removebidder.getType().equals("ea_not_understood")) receivers.remove(removebidder.getParameter(SFipa.SENDER).getValue()); getLogger().info("Removed "+((IComponentIdentifier)removebidder.getParameter(SFipa.SENDER).getValue()).getName() + "."); getLogger().warning("Could not handle message of type "+removebidder.getType() +" from "+((IComponentIdentifier)removebidder.getParameter(SFipa.SENDER).getValue()).getName()+".");