Overview  Package   Class  Tree  Deprecated  Index  Help 
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES    All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

sajas.core.behaviours
Class ReceiverBehaviour
java.lang.Object
  sajas.core.behaviours.Behaviour
      sajas.core.behaviours.ReceiverBehaviour
All Implemented Interfaces:
jade.util.leap.Serializable, Serializable

public final class ReceiverBehaviour
extends Behaviour
Author:
hlc
See Also:
jade.core.behaviours.ReceiverBehaviour

Nested Class Summary
static interface
ReceiverBehaviour.Handle
          An interface representing ACL messages due to arrive within a time limit.
static class
ReceiverBehaviour.NotYetReady
          Exception class for timeouts.
static class
ReceiverBehaviour.TimedOut
          Exception class for timeouts.
Nested classes/interfaces inherited from class sajas.core.behaviours.Behaviour
Behaviour.RunnableChangedEvent
Fields inherited from class sajas.core.behaviours.Behaviour
myAgent, myEvent, NOTIFY_DOWN, NOTIFY_UP, parent, STATE_BLOCKED, STATE_READY, STATE_RUNNING
Constructor Summary
ReceiverBehaviour(Agent a, long millis, jade.lang.acl.MessageTemplate mt)
          This constructor creates a ReceiverBehaviour object that ends as soon as an ACL message matching a given MessageTemplate arrives or the passed millis timeout expires.
ReceiverBehaviour(Agent a, ReceiverBehaviour.Handle h, long millis)
          Receive any ACL message, waiting at most millis milliseconds (infinite time if millis 1).
ReceiverBehaviour(Agent a, ReceiverBehaviour.Handle h, long millis, jade.lang.acl.MessageTemplate mt)
          Receive any ACL message matching the given template, witing at most millis milliseconds (infinite time if millis 1.
Method Summary
void
action()
          Actual behaviour implementation.
boolean
done()
          Checks whether this behaviour ended.
jade.lang.acl.ACLMessage
getMessage()
          This method allows the caller to get the received message.
newHandle()
          Factory method for message handles.
void
reset()
          Resets this behaviour.
Methods inherited from class sajas.core.behaviours.Behaviour
actionWrapper, block, block, getAgent, getBehaviourName, getDataStore, getExecutionState, getParent, getRestartCounter, handle, handleBlockEvent, handleRestartEvent, isRunnable, onEnd, onStart, restart, root, setAgent, setBehaviourName, setDataStore, setExecutionState
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail
ReceiverBehaviour
public ReceiverBehaviour(Agent a,
                         long millis,
                         jade.lang.acl.MessageTemplate mt)
This constructor creates a ReceiverBehaviour object that ends as soon as an ACL message matching a given MessageTemplate arrives or the passed millis timeout expires. The received message can then be got via the method getMessage.
Parameters:
a - The agent this behaviour belongs to, and that will receive() the message.
millis - The timeout expressed in milliseconds, an infinite timeout can be expressed by a value < 0.
mt - A Message template to match incoming messages against, null to indicate no template and receive any message that arrives.

ReceiverBehaviour
public ReceiverBehaviour(Agent a,
                         ReceiverBehaviour.Handle h,
                         long millis)
Receive any ACL message, waiting at most millis milliseconds (infinite time if millis < 1). When calling this constructor, a suitable Handle must be created and passed to it. When this behaviour ends, some other behaviour will try to get the ACL message out of the handle, and an exception will be thrown in case of a time out. The following example code explains this:
       // ReceiverBehaviour creation, e.g. in agent setup() method
       h = ReceiverBehaviour.newHandle(); // h is an agent instance variable
       addBehaviour(new ReceiverBehaviour(this, h, 10000); // Wait 10 seconds

       ...

       // Some other behaviour, later, tries to read the ACL message
       // in its action() method
       try {
         ACLMessage msg = h.getMessage();
	 // OK. Message received within timeout.
       }
       catch(ReceiverBehaviour.TimedOut rbte) {
         // Receive timed out
       }
       catch(ReceiverBehaviour.NotYetReady rbnyr) {
         // Message not yet ready, but timeout still active
       }
     
Parameters:
a - The agent this behaviour belongs to.
h - An Handle representing the message to receive.
millis - The maximum amount of time to wait for the message, in milliseconds.
See Also:
jade.core.behaviours.ReceiverBehaviour.Handle, jade.core.behaviours.ReceiverBehaviour.newHandle()

ReceiverBehaviour
public ReceiverBehaviour(Agent a,
                         ReceiverBehaviour.Handle h,
                         long millis,
                         jade.lang.acl.MessageTemplate mt)
Receive any ACL message matching the given template, witing at most millis milliseconds (infinite time if millis < 1. When calling this constructor, a suitable Handle must be created and passed to it.
Parameters:
a - The agent this behaviour belongs to.
h - An Handle representing the message to receive.
millis - The maximum amount of time to wait for the message, in milliseconds.
mt - A Message template to match incoming messages against, null to indicate no template and receive any message that arrives.
See Also:
jade.core.behaviours.ReceiverBehaviour.ReceiverBehaviour(Agent a, Handle h, long millis)
Method Detail
newHandle
public static ReceiverBehaviour.Handle newHandle()
Factory method for message handles. This method returns a new Handle object, which can be used to retrieve an ACL message out of a ReceiverBehaviour object.
Returns:
A new Handle object.
See Also:
jade.core.behaviours.ReceiverBehaviour.Handle

action
public void action()
Actual behaviour implementation. This method receives a suitable ACL message and copies it into the message provided by the behaviour creator. It blocks the current behaviour if no suitable message is available.
Overrides:
action in class Behaviour

done
public boolean done()
Checks whether this behaviour ended.
Overrides:
done in class Behaviour
Returns:
true when an ACL message has been received.

reset
public void reset()
Resets this behaviour. This method allows to receive another ACLMessage with the same ReceiverBehaviour without creating a new object.
Overrides:
reset in class Behaviour

getMessage
public jade.lang.acl.ACLMessage getMessage()
                                    throws ReceiverBehaviour.TimedOut,
                                           ReceiverBehaviour.NotYetReady
This method allows the caller to get the received message.
Returns:
the received message
Throws:
ReceiverBehaviour.TimedOut - if the timeout passed in the constructor of this class expired before any message (that eventually matched the passed message template) arrived
ReceiverBehaviour.NotYetReady - if the message is not yet arrived and the timeout is not yet expired.

Overview  Package   Class  Tree  Deprecated  Index  Help 
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES    All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

Java API documentation generated with DocFlex/Doclet 1.6.1 using JavadocPro template set.
DocFlex/Doclet is both a multi-format Javadoc doclet and a free edition of DocFlex/Javadoc, which is a template-driven programming tool for rapid development of any Javadoc-based Java API documentation generators (i.e. doclets). If you need to customize your Javadoc without writing a full-blown doclet from scratch, DocFlex/Javadoc may be the only tool able to help you! Find out more at www.docflex.com