Package jade.lang.acl

Examples of jade.lang.acl.ACLMessage


   @see jade.proto.SubscriptionInitiator
   @see #createCancelMessage(Agent, AID, ACLMessage)
   @see #decodeNotification(String)
   */
  public static ACLMessage createSubscriptionMessage(Agent a, AID dfName, DFAgentDescription template, SearchConstraints constraints) {
    ACLMessage subscribe = createRequestMessage(a, dfName);
    subscribe.setPerformative(ACLMessage.SUBSCRIBE);
    subscribe.setProtocol(FIPANames.InteractionProtocol.FIPA_SUBSCRIBE);
    // Note that iota is not included in SL0
    subscribe.setLanguage(FIPANames.ContentLanguage.FIPA_SL)
    if (constraints == null) {
      constraints = new SearchConstraints();
      constraints.setMaxResults(MINUSONE);
    }   
    subscribe.setContent(encodeIota(dfName, template, constraints));
    return subscribe;
  }
View Full Code Here


   @see jade.proto.SubscriptionInitiator
   @see #createSubscriptionMessage(Agent, AID, DFAgentDescription, SearchConstraints)
   @see #decodeNotification(String)
   */
  public static ACLMessage createCancelMessage(Agent a, AID dfName, ACLMessage subscribe) {
    ACLMessage cancel = new ACLMessage(ACLMessage.CANCEL);
    cancel.addReceiver(dfName);
    cancel.setLanguage(subscribe.getLanguage());
    cancel.setOntology(subscribe.getOntology());
    cancel.setProtocol(subscribe.getProtocol());
    cancel.setConversationId(subscribe.getConversationId());
    cancel.setContent(encodeCancel(dfName, subscribe));
    return cancel;
  }
View Full Code Here

   */
  protected abstract void installHandlers(Map handlersTable);
 
  public final void action() {
    if (active) {
      ACLMessage current = myAgent.receive(listenTemplate);
      if(current != null) {
        // Handle 'inform' messages from the AMS
        try {
          Occurred o = (Occurred) myAgent.getContentManager().extractContent(current);
          EventRecord er = (EventRecord)o.getWhat();
View Full Code Here

    this.remoteDF = remoteDF;
    this.myAction = myAction;
  }
 
  protected ACLMessage prepareRequest(ACLMessage msg){
    ACLMessage request = new ACLMessage(ACLMessage.REQUEST);
    request.addReceiver(remoteDF);
    request.setOntology(FIPAManagementOntology.getInstance().getName());
    request.setLanguage(FIPANames.ContentLanguage.FIPA_SL0);
    request.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST);
   
    Action act = new Action(remoteDF, myAction);
    try {
      myAgent.getContentManager().fillContent(request, act);
      return request;
View Full Code Here

   a <code>refuse</code> or <code>failure</code> messages are
   received from the AMS to indicate some error condition or when
   the method locally discovers that the amsdescription is not valid.
   */
  public static void register(Agent a, AID AMSName, AMSAgentDescription amsd) throws FIPAException {
    ACLMessage request = createRequestMessage(a, AMSName);
   
    if (amsd.getName() == null)
      amsd.setName(a.getAID());
    if (amsd.getState() == null)
      amsd.setState(AMSAgentDescription.ACTIVE);
View Full Code Here

   received from the AMS to indicate some error condition or when
   the method locally discovers that the amsdescription is not valid.
   */
  public static void deregister(Agent a, AID AMSName, AMSAgentDescription amsd) throws FIPAException {
   
    ACLMessage request = createRequestMessage(a, AMSName);
   
    if (amsd.getName() == null)
      amsd.setName(a.getAID());
    if (amsd.getState() == null)
      amsd.setState(AMSAgentDescription.ACTIVE);
View Full Code Here

   a <code>refuse</code> or <code>failure</code> messages are
   received from the AMS to indicate some error condition or when
   the method locally discovers that the amsdescription is not valid.
   */
  public static void modify(Agent a, AID AMSName, AMSAgentDescription amsd) throws FIPAException {
    ACLMessage request = createRequestMessage(a, AMSName);
   
    if (amsd.getName() == null)
      amsd.setName(a.getAID());
    checkIsValid(amsd);
    // Build a AMS action object for the request
View Full Code Here

   @exception FIPAException A suitable exception can be thrown when
   a <code>refuse</code> or <code>failure</code> messages are
   received from the AMS to indicate some error condition.
   */
  public static AMSAgentDescription[] search(Agent a, AID AMSName, AMSAgentDescription amsd, SearchConstraints constraints) throws FIPAException {
    ACLMessage request = createRequestMessage(a, AMSName);
   
    // Build a AMS action object for the request
    Search s = new Search();
    s.setDescription(amsd);
    s.setConstraints(constraints);
   
    Action act = new Action();
    act.setActor(AMSName);
    act.setAction(s);
   
    synchronized (cm) {
      try{   
        cm.fillContent(request, act);
      }
      catch(Exception e){
        throw new FIPAException("Error encoding REQUEST content. "+e);
      }
    }
   
    // Send message and collect reply
    ACLMessage inform = doFipaRequestClient(a,request);
   
    Result r = null;
    synchronized (cm) {
      try{
        r = (Result) cm.extractContent( inform );
View Full Code Here

    template = MessageTemplate.and(mt, conversations.getMessageTemplate());
    logger = Logger.getMyLogger(theDF.getLocalName());
  }
 
  public void action() {
    ACLMessage msg = theDF.receive(template);
    if (msg != null) {
      if (logger.isLoggable(Logger.FINE)) {
        logger.log(Logger.FINE, "DF "+myAgent.getName()+": Iterated-search request received from "+msg.getSender().getName()+". Conv-ID = "+msg.getConversationId());
      }
      theDF.addBehaviour(new SSIteratedAchieveREResponder(theDF, msg) {
        private KBIterator iterator = null;
        private String myConversationId = null;
        private int cnt = 0; // Only for debugging purposes
       
        protected ACLMessage handleRequest(ACLMessage request) throws RefuseException, FailureException, NotUnderstoodException {
          ACLMessage reply = null;
         
          if (logger.isLoggable(Logger.FINE)) {
            logger.log(Logger.FINE, "DF "+myAgent.getName()+": Iterated-search "+request.getConversationId()+". Serving request # "+cnt);
          }
          cnt++;
          try {
            // Parse the request content
            Action aExpr = (Action) theDF.getContentManager().extractContent(request);
            Search search = (Search) aExpr.getAction();
            SearchConstraints constraints = search.getConstraints();
            int maxResult = theDF.getActualMaxResults(constraints);
           
            // If this is the first REQUEST, create the Iterator
            if (iterator == null) {
              if (logger.isLoggable(Logger.FINER)) {
                logger.log(Logger.FINER, "DF "+myAgent.getName()+": Iterated-search "+request.getConversationId()+". Initializing KBIterator");
              }
              iterator = theDF.iteratedSearchAction(search, request.getSender());
              if (logger.isLoggable(Logger.FINEST)) {
                logger.log(Logger.FINEST, "DF "+myAgent.getName()+": Iterated-search "+request.getConversationId()+". KBIterator correctly initialized");
              }
            }
           
            // Get the requested number of results
            List ll = new ArrayList();
            for (int i = 0; i < maxResult; ++i) {
              if (iterator.hasNext()) {
                ll.add(iterator.next());
              }
              else {
                if (logger.isLoggable(Logger.FINER)) {
                  logger.log(Logger.FINER, "DF "+myAgent.getName()+": Iterated-search "+request.getConversationId()+". Closing KBIterator");
                }
                iterator.close();
                // FIXME: properly handle recursive search
                closeSessionOnNextReply();
                break;
              }
            }
            if (logger.isLoggable(Logger.FINE)) {
              logger.log(Logger.FINE, "DF "+myAgent.getName()+": Iterated-search "+request.getConversationId()+". Sending back "+ll.size()+" results");
            }
           
            // Fill the reply
            reply = request.createReply();
            try {
              Result result = new Result(aExpr, ll);
              theDF.getContentManager().fillContent(reply, result);
              reply.setPerformative(ACLMessage.INFORM);
            }
            catch (Exception e) {
              // Unexpected error encoding the reply
              e.printStackTrace();
              throw new FailureException(ExceptionVocabulary.INTERNALERROR+" \""+e.getMessage()+"\"");
            }
          }
          catch (OntologyException oe) {
            throw new NotUnderstoodException(ExceptionVocabulary.UNRECOGNISEDVALUE+" content");
         
          catch (CodecException ce) {
            throw new NotUnderstoodException(ExceptionVocabulary.UNRECOGNISEDVALUE+" content");
         
          catch (FailureException fe) {
            throw fe;
          }
          catch (Throwable t) {
            // Unexpected error
            t.printStackTrace();
            throw new FailureException(ExceptionVocabulary.INTERNALERROR+" \""+t.getMessage()+"\"");
          }
         
          return reply;
        }
       
        protected void handleCancel(ACLMessage cancel) {
          if (logger.isLoggable(Logger.FINE)) {
            logger.log(Logger.FINE, "DF "+myAgent.getName()+": Iterated-search "+cancel.getConversationId()+". Serving cancel");
          }
          if (iterator != null) {
            if (logger.isLoggable(Logger.FINER)) {
              logger.log(Logger.FINER, "DF "+myAgent.getName()+": Iterated-search "+cancel.getConversationId()+". Closing KBIterator");
            }
            iterator.close();
          }
        }
       
        /**
         Avoid conflicts between the main MessageTemplate and that used
         internally by this IteratedFipaRequestResponder.
         */
        protected void afterReply(ACLMessage reply) {
          if (reply != null) {
            myConversationId = reply.getConversationId();
            conversations.registerConversation(myConversationId);
          }
        }
       
        /**
 
View Full Code Here

    }
   
    if (!asynchNotificationRequired) {
      theDF.removePendingRequest(action);
      // The requested action has been completed. Prepare the notification
      ACLMessage notification = request.createReply();
      notification.setPerformative(ACLMessage.INFORM);
      Predicate p = null;
      if (result != null) {
        // The action produced a result
        p = new Result(slAction, result);
      }
View Full Code Here

TOP

Related Classes of jade.lang.acl.ACLMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.