Package jade.core
Class ExtendedMessageQueue
- java.lang.Object
-
- jade.core.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 Summary
Fields Modifier and Type Field Description protected LinkedList<ACLMessage>listprotected intmaxSizeprotected AgentmyAgentprotected LoggermyLoggerprotected MessageTemplatewarningDiscardTemplateprotected intwarningLimit
-
Constructor Summary
Constructors Constructor Description ExtendedMessageQueue()ExtendedMessageQueue(int maxSize, int warningLimit, MessageTemplate warningDiscardTemplate, Agent a)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFirst(ACLMessage msg)Add a message to the front of this queue.voidaddLast(ACLMessage msg)Add a message to the end of this queue.voidcopyTo(List messages)Copy all messages to a given list.Stringdump(int limit)intgetMaxSize()Return the maximum size of this queue.protected voidhandleDiscarded(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.booleanisEmpty()Return true when this queue contains no messages.ACLMessagereceive(MessageTemplate pattern)Return and remove the first message that matches the specified message template.List<ACLMessage>receive(MessageTemplate pattern, int max)Return and remove the first n messages that match the specified message template.voidsetMaxSize(int maxSize)Set the maximum size of this queue.intsize()
-
-
-
Field Detail
-
list
protected LinkedList<ACLMessage> list
-
maxSize
protected int maxSize
-
warningLimit
protected int warningLimit
-
warningDiscardTemplate
protected MessageTemplate warningDiscardTemplate
-
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
-
setMaxSize
public void setMaxSize(int maxSize) throws IllegalArgumentExceptionDescription copied from interface:MessageQueueSet the maximum size of this queue. This queue may remove old messages to prevent exeding the maximum size.- Specified by:
setMaxSizein interfaceMessageQueue- Throws:
IllegalArgumentException
-
getMaxSize
public int getMaxSize()
Description copied from interface:MessageQueueReturn the maximum size of this queue. This queue may remove old messages to prevent exeding the maximum size.- Specified by:
getMaxSizein interfaceMessageQueue
-
size
public int size()
- Specified by:
sizein interfaceMessageQueue- Returns:
- the number of messages currently in the queue
-
isEmpty
public boolean isEmpty()
Description copied from interface:MessageQueueReturn true when this queue contains no messages.- Specified by:
isEmptyin interfaceMessageQueue
-
addFirst
public void addFirst(ACLMessage msg)
Description copied from interface:MessageQueueAdd a message to the front of this queue.- Specified by:
addFirstin interfaceMessageQueue
-
addLast
public void addLast(ACLMessage msg)
Description copied from interface:MessageQueueAdd a message to the end of this queue.- Specified by:
addLastin interfaceMessageQueue
-
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 discardedwarningLimitExceeded- A boolean indication stating that the message was discarded because the warning limit has been exceeded.
-
receive
public ACLMessage receive(MessageTemplate pattern)
Description copied from interface:MessageQueueReturn and remove the first message that matches the specified message template.- Specified by:
receivein interfaceMessageQueue
-
receive
public List<ACLMessage> receive(MessageTemplate pattern, int max)
Description copied from interface:MessageQueueReturn and remove the first n messages that match the specified message template.- Specified by:
receivein interfaceMessageQueue
-
copyTo
public void copyTo(List messages)
Description copied from interface:MessageQueueCopy all messages to a given list.- Specified by:
copyToin interfaceMessageQueue
-
dump
public String dump(int limit)
-
-