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.proto.states
Class MsgReceiver
java.lang.Object
  sajas.core.behaviours.Behaviour
      sajas.core.behaviours.SimpleBehaviour
          sajas.proto.states.MsgReceiver
All Implemented Interfaces:
jade.util.leap.Serializable, Serializable

public class MsgReceiver
extends SimpleBehaviour
Note: this class has been re-implemented to redirect the use of the agent and behaviour classes to SAJaS versions.
Author:
hlc
See Also:
jade.proto.states.MsgReceiver

Nested classes/interfaces inherited from class sajas.core.behaviours.Behaviour
Behaviour.RunnableChangedEvent
Field Summary
protected long
deadline
static int
INFINITE
          A numeric constant to mean that the deadline for the receive operation will never expire.
static int
INTERRUPTED
          A numeric constant to mean that the receive operation was interrupted.
protected Object
receivedMsgKey
protected jade.lang.acl.MessageTemplate
template
static int
TIMEOUT_EXPIRED
          A numeric constant to mean that a timeout expired.
Fields inherited from class sajas.core.behaviours.Behaviour
myAgent, myEvent, NOTIFY_DOWN, NOTIFY_UP, parent, STATE_BLOCKED, STATE_READY, STATE_RUNNING
Constructor Summary
protected
MsgReceiver()
MsgReceiver(Agent a, jade.lang.acl.MessageTemplate mt, long deadline, DataStore s, Object msgKey)
          Constructor.
Method Summary
void
action()
          Runs the behaviour.
boolean
done()
          Check if this behaviour is done.
protected void
handleMessage(jade.lang.acl.ACLMessage msg)
          This is invoked when a message matching the specified template is received or the timeout has expired (the msg parameter is null in this case).
void
interrupt()
          Signal an interruption to this receiver, and cause the ongoing receive operation to abort.
int
onEnd()
          This method is just an empty placeholder for subclasses.
void
reset(jade.lang.acl.MessageTemplate mt, long deadline, DataStore s, Object msgKey)
          Reset this behaviour, possibly replacing the receive templatt and other data.
void
setDeadline(long deadline)
          This method allows modifying the deadline
void
setReceivedKey(Object key)
          This method allows modifying the key in the DS where to put the received message
void
setTemplate(jade.lang.acl.MessageTemplate mt)
          This method allows modifying the template
Methods inherited from class sajas.core.behaviours.SimpleBehaviour
reset
Methods inherited from class sajas.core.behaviours.Behaviour
actionWrapper, block, block, getAgent, getBehaviourName, getDataStore, getExecutionState, getParent, getRestartCounter, handle, handleBlockEvent, handleRestartEvent, isRunnable, 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
Field Detail
deadline
protected long deadline

INFINITE
public static final int INFINITE
A numeric constant to mean that the deadline for the receive operation will never expire.
See Also:
Constant Field Values

INTERRUPTED
public static final int INTERRUPTED
A numeric constant to mean that the receive operation was interrupted.
See Also:
Constant Field Values

receivedMsgKey
protected Object receivedMsgKey

template
protected jade.lang.acl.MessageTemplate template

TIMEOUT_EXPIRED
public static final int TIMEOUT_EXPIRED
A numeric constant to mean that a timeout expired.
See Also:
Constant Field Values
Constructor Detail
MsgReceiver
public MsgReceiver(Agent a,
                   jade.lang.acl.MessageTemplate mt,
                   long deadline,
                   DataStore s,
                   Object msgKey)
Constructor.
Parameters:
a - a reference to the Agent
mt - the MessageTemplate of the message to be received, if null the first received message is returned by this behaviour
deadline - a timeout for waiting until a message arrives. It must be expressed as an absolute time, as it would be returned by System.currentTimeMillisec()
s - the dataStore for this bheaviour
msgKey - the key where the beahviour must put the received message into the DataStore.

MsgReceiver
protected MsgReceiver()
Method Detail
action
public void action()
Description copied from class: Behaviour
Runs the behaviour. This abstract method must be implemented by Behavioursubclasses to perform ordinary behaviour duty. An agent schedules its behaviours calling their action() method; since all the behaviours belonging to the same agent are scheduled cooperatively, this method must not enter in an endless loop and should return as soon as possible to preserve agent responsiveness. To split a long and slow task into smaller section, recursive behaviour aggregation may be used.
Overrides:
action in class Behaviour

done
public boolean done()
Description copied from class: Behaviour
Check if this behaviour is done. The agent scheduler calls this method to see whether a Behaviour still need to be run or it has completed its task. Concrete behaviours must implement this method to return their completion state. Finished behaviours are removed from the scheduling queue, while others are kept within to be run again when their turn comes again.
Overrides:
done in class Behaviour
Returns:
true if the behaviour has completely executed.

onEnd
public int onEnd()
Description copied from class: Behaviour
This method is just an empty placeholder for subclasses. It is invoked just once after this behaviour has ended. Therefore, it acts as an epilog for the task represented by this Behaviour.
Note that onEnd is called after the behaviour has been removed from the pool of behaviours to be executed by an agent. Therefore calling reset() is not sufficient to cyclically repeat the task represented by this Behaviour. In order to achieve that, this Behaviour must be added again to the agent (using myAgent.addBehaviour(this)). The same applies to in the case of a Behaviour that is a child of a ParallelBehaviour.
Overrides:
onEnd in class Behaviour
Returns:
the performative if a message arrived, TIMEOUT_EXPIRED if the timeout expired or INTERRUPTED if this MsgReceiver was interrupted calling the interrupt() method.

handleMessage
protected void handleMessage(jade.lang.acl.ACLMessage msg)
This is invoked when a message matching the specified template is received or the timeout has expired (the msg parameter is null in this case). Users may redefine this method to react to this event. The default implementation of does nothing.

reset
public void reset(jade.lang.acl.MessageTemplate mt,
                  long deadline,
                  DataStore s,
                  Object msgKey)
Reset this behaviour, possibly replacing the receive templatt and other data.
Parameters:
mt - The template to match ACL messages against during the receive operation.
deadline - The relative timeout of the receive operation. If the INFINITE constant is used, then no deadline is set and the operation will wait until a matching ACL message arrives.
s - The datastore where the received ACL message is to be put.
msgKey - The key to use to put the received message into the selected datastore.

setDeadline
public void setDeadline(long deadline)
This method allows modifying the deadline

setTemplate
public void setTemplate(jade.lang.acl.MessageTemplate mt)
This method allows modifying the template

setReceivedKey
public void setReceivedKey(Object key)
This method allows modifying the key in the DS where to put the received message

interrupt
public void interrupt()
Signal an interruption to this receiver, and cause the ongoing receive operation to abort.

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