Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two ways of doing this, depending on whether you want to receive the information via an ongoing service or the current snapshot in a message.</p> <p>To get a snapshot of the IDs of the currently available agent containers, send a Request message to the Agent Management Service (AMS) and wait for its reply. Using the JADE Management Ontology and the <em>QueryPlatformLocationsAction</em> term, the sending and receiving methods would be:</p> <pre><code>private void queryAMS() throws CodecException, OntologyException { QueryPlatformLocationsAction query = new QueryPlatformLocationsAction(); Action action = new Action(myAgent.getAID(), query); ACLMessage message = new ACLMessage(ACLMessage.REQUEST); message.addReceiver(myAgent.getAMS()); message.setLanguage(FIPANames.ContentLanguage.FIPA_SL); message.setOntology(JADEManagementOntology.getInstance().getName()); myAgent.getContentManager().fillContent(message, action); myAgent.send(message); } private void listenForAMSReply() throws UngroundedException, CodecException, OntologyException { ACLMessage receivedMessage = myAgent.blockingReceive(MessageTemplate .MatchSender(myAgent.getAMS())); ContentElement content = myAgent.getContentManager().extractContent( receivedMessage); // received message is a Result object, whose Value field is a List of // ContainerIDs Result result = (Result) content; List listOfPlatforms = (List) result.getValue(); // use it Iterator iter = listOfPlatforms.iterator(); while (iter.hasNext()) { ContainerID next = (ContainerID) iter.next(); System.out.println(next.getID()); } } </code></pre> <p>To get this information as an ongoing service, and to receive the ContainerID of each container as it registers with the AMS, create a Behaviour that extends the AMSSubscriber. Register a handler for the AddedContainer event and you will be able to access the ContainerID of the newly available container:</p> <pre><code>public class AMSListenerBehaviour extends AMSSubscriber { @Override public void installHandlers(Map handlersTable) { handlersTable.put(AddedContainer.NAME, addedContainerHandler); } public final class AddedContainerHandler implements EventHandler { @Override public void handle(Event ev) { AddedContainer event = (AddedContainer) ev; ContainerID addedContainer = event.getContainer(); System.out.println(addedContainer.getID()); } </code></pre> <p>Hope this helps,</p> <p>Russ</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload