Package jade.core

Class ExtendedMessageQueue

  • All Implemented Interfaces:
    MessageQueue
    Direct Known Subclasses:
    TemplateBasedMessageQueue

    public class ExtendedMessageQueue
    extends Object
    implements MessageQueue
    Extended version of the Agent MessageQueue supporting additional features that can be useful when dealing with heavy load of messages. - When message queue max size is exceeded last message is discarded (standard MessageQueue enqueues the incoming message and removes the first in queue - the eldest one) - A warningLimit and a warningTemplate can be defined so that, when the warningLimit is exceeded, incoming messages matching the warningTemplate are discarded - Whenever a message is discarded the handleDiscarded() callback method is invoked. Application agents can redefine this method to provide custom discarding actions
    Author:
    Caire
    • Field Detail

      • maxSize

        protected int maxSize
      • warningLimit

        protected int warningLimit
      • myAgent

        protected Agent myAgent
      • myLogger

        protected Logger myLogger
    • Constructor Detail

      • ExtendedMessageQueue

        public ExtendedMessageQueue​(int maxSize,
                                    int warningLimit,
                                    MessageTemplate warningDiscardTemplate,
                                    Agent a)
      • ExtendedMessageQueue

        public ExtendedMessageQueue()
    • Method Detail

      • getMaxSize

        public int getMaxSize()
        Description copied from interface: MessageQueue
        Return the maximum size of this queue. This queue may remove old messages to prevent exeding the maximum size.
        Specified by:
        getMaxSize in interface MessageQueue
      • size

        public int size()
        Specified by:
        size in interface MessageQueue
        Returns:
        the number of messages currently in the queue
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: MessageQueue
        Return true when this queue contains no messages.
        Specified by:
        isEmpty in interface MessageQueue
      • handleDiscarded

        protected void handleDiscarded​(ACLMessage msg,
                                       boolean warningLimitExceeded)
        This method is invoked when a message is discarded because the queue max size has been reached or the warning limit has been exceeded and the discard-message-template matches. The default implementation just print a WARNING. Subclasses may redefine this method to implement application specific discard actions such as sending back a FAILURE to the sender
        Parameters:
        msg - The message that was discarded
        warningLimitExceeded - A boolean indication stating that the message was discarded because the warning limit has been exceeded.
      • copyTo

        public void copyTo​(List messages)
        Description copied from interface: MessageQueue
        Copy all messages to a given list.
        Specified by:
        copyTo in interface MessageQueue
      • dump

        public String dump​(int limit)