Package jade.core

Class Agent

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Agent.Interrupted
      Inner class Interrupted.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int AP_ACTIVE
      Represents the active agent state.
      static int AP_DELETED
      Represents the deleted agent state.
      static int AP_IDLE
      Represents the idle agent state.
      static int AP_INITIATED
      Represents the initiated agent state.
      static int AP_MAX
      Out of band value for Agent Platform Life Cycle states.
      static int AP_MIN
      Out of band value for Agent Platform Life Cycle states.
      static int AP_SUSPENDED
      Represents the suspended agent state.
      static int AP_WAITING
      Represents the waiting agent state.
      static int D_ACTIVE
      Represents the active agent state.
      static int D_MAX
      Out of band value for Domain Life Cycle states.
      static int D_MIN
      Out of band value for Domain Life Cycle states.
      static int D_RETIRED
      Represents the retired agent state.
      static int D_SUSPENDED
      Represents the suspended agent state.
      static int D_UNKNOWN
      Represents the unknown agent state.
      static String MSG_QUEUE_CLASS  
    • Constructor Summary

      Constructors 
      Constructor Description
      Agent()
      Default constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addBehaviour​(Behaviour b)
      This method adds a new behaviour to the agent.
      protected void afterClone()
      Actions to perform after cloning.
      protected void afterMove()
      Actions to perform after moving.
      protected void beforeClone()
      This empty placeholder method shall be overridden by user defined agents to execute some actions before copying an agent to another agent container.
      protected void beforeMove()
      This empty placeholder shall be overridden by user defined agents to execute some actions before the original agent instance on the source container is stopped (e.g.
      ACLMessage blockingReceive()
      Receives an ACL message from the agent message queue.
      ACLMessage blockingReceive​(long millis)
      Receives an ACL message from the agent message queue, waiting at most a specified amount of time.
      ACLMessage blockingReceive​(MessageTemplate pattern)
      Receives an ACL message matching a given message template.
      ACLMessage blockingReceive​(MessageTemplate pattern, long millis)
      Receives an ACL message matching a given message template, waiting at most a specified time.
      void changeStateTo​(LifeCycle newLifeCycle)  
      void clean​(boolean ok)  
      protected MessageQueue createMessageQueue()
      Developer can override this method to provide an alternative message queue creation mechanism
      void doActivate()
      Make a state transition from suspended to active or waiting (whichever state the agent was in when doSuspend() was called) within Agent Platform Life Cycle.
      void doClone​(Location destination, String newName)
      Make this agent be cloned on another location.
      void doDelete()
      Make a state transition from active, suspended or waiting to deleted state within Agent Platform Life Cycle, thereby destroying the agent.
      void doMove​(Location destination)
      Make this agent move to a remote location.
      void doSuspend()
      Make a state transition from active or waiting to suspended within Agent Platform Life Cycle; the original agent state is saved and will be restored by a doActivate() call.
      void doTimeOut​(Timer t)
      Restarts the behaviour associated with t.
      void doWait()
      Make a state transition from active to waiting within Agent Platform Life Cycle.
      void doWait​(long millis)
      Make a state transition from active to waiting within Agent Platform Life Cycle.
      void doWake()
      Make a state transition from waiting to active within Agent Platform Life Cycle.
      AgentState getAgentState()  
      AID getAID()
      Method to query the private Agent ID.
      AID getAID​(String name)
      Method to build a complete agent GUID belonging to the same platform of the current agent
      AID getAMS()
      Get the Agent ID for the platform AMS.
      Object[] getArguments()
      Get the array of arguments passed to this agent.
      int getBehavioursCnt()
      Return the number of behaviours currently included in the agent pool (both runnable and blocked).
      Properties getBootProperties()
      Return the configuration properties exactly as they were passed to the Profile before starting the local JADE container.
      AgentContainer getContainerController()
      Return a controller for the container this agent lives in.
      ContentManager getContentManager()
      Retrieves the agent's content manager
      int getCurQueueSize()
      This method retrieves the current length of the message queue of this agent.
      AID getDefaultDF()
      Get the Agent ID for the platform default DF.
      long getExecutedBehavioursCnt()  
      boolean getGenerateBehaviourEvents()  
      boolean getGenerateMessageEvents()  
      String getHap()
      Method to query the Home Agent Platform.
      ServiceHelper getHelper​(String serviceName)
      Retrieves the agent's service helper
      String getLocalName()
      Method to query the agent local name.
      String getName()
      Method to query the agent complete name (GUID).
      <T> T getO2AInterface​(Class<T> theInterface)
      Used internally by the framework
      Object getO2AObject()
      This method picks an object (if present) from the internal object-to-agent communication queue.
      long getPostedMessagesCnt()  
      String getProperty​(String key, String aDefault)
      Retrieve a configuration property set in the Profile of the local container (first) or as a System property.
      int getQueueSize()
      Reads message queue size.
      long getReceivedMessagesCnt()  
      long getSentMessagesCnt()  
      int getState()
      Read current agent state.
      Location here()
      Method to retrieve the location this agent is currently at.
      boolean isAlive()
      Returns true if the agent implemented by this Agent object is alive (regardless of the actual agent internal state).
      boolean isRestarting()
      This method returns true when this agent is restarting after a crash.
      boolean join()
      This method is used internally by the framework and should NOT be used by programmers.
      void notifyChangeBehaviourState​(Behaviour b, String from, String to)  
      void notifyRestarted​(Behaviour b)
      Notifies this agent that one of its behaviours has been restarted for some reason.
      void postMessage​(ACLMessage msg)
      Put a received message into the agent message queue.
      void putBack​(ACLMessage msg)
      Puts a received ACL message back into the message queue.
      void putO2AObject​(Object o, boolean blocking)
      This method should not be used by application code.
      ACLMessage receive()
      Receives an ACL message from the agent message queue.
      ACLMessage receive​(MessageTemplate pattern)
      Receives an ACL message matching a given template.
      List<ACLMessage> receive​(MessageTemplate pattern, int max)
      Read up to max messages from the agent message queue.
      <T> void registerO2AInterface​(Class<T> theInterface, T implementation)
      Registers an implementation for a given O2A interface.
      void removeBehaviour​(Behaviour b)
      This method removes a given behaviour from the agent.
      void removeTimer​(Behaviour b)  
      void restartLater​(Behaviour b, long millis)
      Schedules a restart for a behaviour, after a certain amount of time has passed.
      void restoreBufferedState()  
      void restoreFields​(InputStream s)
      Reads a previously saved agent state, and restore the agent user-defined fields replacing their current values.
      void run()
      This method is the main body of every agent.
      void send​(ACLMessage msg)
      Send an ACL message to another agent.
      void setArguments​(Object[] args)
      Called by AgentContainerImpl in order to pass arguments to a just created Agent.
      void setEnabledO2ACommunication​(boolean enabled, int queueSize)
      This method declares this agent attitude towards object-to-agent communication, that is, whether the agent accepts to communicate with other non-JADE components living within the same JVM.
      void setGenerateBehaviourEvents​(boolean b)
      Allow enabling/disabling (default: disabled) the generation of message-related events (such as NOTIFY_BEHAVIOUR_ADDED or NOTIFY_CHANGED_BEHAVIOUR_STATE)
      void setGenerateMessageEvents​(boolean b)
      Allow disabling/enabling (default: enabled) the generation of message-related events (such as NOTIFY_POSTED or NOTIFY_RECEIVED)
      void setO2AManager​(Behaviour b)
      Sets the behaviour responsible for managing objects passed to the agent by means of the Object-To-Agent (O2A) communication mechanism.
      void setQueueSize​(int newSize)
      Set message queue size.
      protected void setup()
      This protected method is an empty placeholder for application specific startup code.
      protected void takeDown()
      This protected method is an empty placeholder for application specific cleanup code.
      void waitUntilStarted()
      This method blocks until the agent has finished its start-up phase (i.e.
      void write​(OutputStream s)
      Write this agent to an output stream; this method can be used to record a snapshot of the agent state on a file or to send it through a network connection.
    • Field Detail

      • AP_MIN

        public static final int AP_MIN
        Out of band value for Agent Platform Life Cycle states.
        See Also:
        Constant Field Values
      • AP_INITIATED

        public static final int AP_INITIATED
        Represents the initiated agent state.
        See Also:
        Constant Field Values
      • AP_ACTIVE

        public static final int AP_ACTIVE
        Represents the active agent state.
        See Also:
        Constant Field Values
      • AP_IDLE

        public static final int AP_IDLE
        Represents the idle agent state.
        See Also:
        Constant Field Values
      • AP_SUSPENDED

        public static final int AP_SUSPENDED
        Represents the suspended agent state.
        See Also:
        Constant Field Values
      • AP_WAITING

        public static final int AP_WAITING
        Represents the waiting agent state.
        See Also:
        Constant Field Values
      • AP_DELETED

        public static final int AP_DELETED
        Represents the deleted agent state.
        See Also:
        Constant Field Values
      • AP_MAX

        public static final int AP_MAX
        Out of band value for Agent Platform Life Cycle states.
        See Also:
        Constant Field Values
      • D_MIN

        public static final int D_MIN
        Out of band value for Domain Life Cycle states.
        See Also:
        Constant Field Values
      • D_ACTIVE

        public static final int D_ACTIVE
        Represents the active agent state.
        See Also:
        Constant Field Values
      • D_SUSPENDED

        public static final int D_SUSPENDED
        Represents the suspended agent state.
        See Also:
        Constant Field Values
      • D_RETIRED

        public static final int D_RETIRED
        Represents the retired agent state.
        See Also:
        Constant Field Values
      • D_UNKNOWN

        public static final int D_UNKNOWN
        Represents the unknown agent state.
        See Also:
        Constant Field Values
      • D_MAX

        public static final int D_MAX
        Out of band value for Domain Life Cycle states.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Agent

        public Agent()
        Default constructor.
    • Method Detail

      • restartLater

        public void restartLater​(Behaviour b,
                                 long millis)
        Schedules a restart for a behaviour, after a certain amount of time has passed.
        Parameters:
        b - The behaviour to restart later.
        millis - The amount of time to wait before restarting b.
        See Also:
        Behaviour.block(long millis)
      • doTimeOut

        public void doTimeOut​(Timer t)
        Restarts the behaviour associated with t. This method runs within the time-critical Timer Dispatcher thread and is not intended to be called by users. It is defined public only because is part of the TimerListener interface.
        Specified by:
        doTimeOut in interface TimerListener
      • notifyRestarted

        public void notifyRestarted​(Behaviour b)
        Notifies this agent that one of its behaviours has been restarted for some reason. This method clears any timer associated with behaviour object b, and it is unneeded by application level code. To explicitly schedule behaviours, use block() and restart() methods.
        Parameters:
        b - The behaviour object which was restarted.
        See Also:
        Behaviour.restart()
      • removeTimer

        public void removeTimer​(Behaviour b)
      • createMessageQueue

        protected MessageQueue createMessageQueue()
        Developer can override this method to provide an alternative message queue creation mechanism
        Returns:
        The MessageQueue to be used by this agent or null if the internal message queue must be used
      • getContainerController

        public AgentContainer getContainerController()
        Return a controller for the container this agent lives in.
        NOT available in MIDP
        Returns:
        jade.wrapper.AgentContainer a controller for the container this agent lives in.
      • setArguments

        public final void setArguments​(Object[] args)
        Called by AgentContainerImpl in order to pass arguments to a just created Agent.

        Usually, programmers do not need to call this method in their code.

        See Also:
        how to get the arguments passed to an agent
      • getArguments

        public Object[] getArguments()
        Get the array of arguments passed to this agent.

        Take care that the arguments are transient and they do not migrate with the agent neither are cloned with the agent!

        Returns:
        the array of arguments passed to this agent.
        See Also:
        How to use arguments or properties to configure your agent.
      • isRestarting

        public final boolean isRestarting()
        This method returns true when this agent is restarting after a crash. The restarting indication is automatically reset as soon as the setup() method of this agent terminates.
        Returns:
        true when this agent is restarting after a crash. false otherwise.
      • getAMS

        public final AID getAMS()
        Get the Agent ID for the platform AMS.
        Returns:
        An AID object, that can be used to contact the AMS of this platform.
      • getDefaultDF

        public AID getDefaultDF()
        Get the Agent ID for the platform default DF.
        Returns:
        An AID object, that can be used to contact the default DF of this platform.
      • getLocalName

        public final String getLocalName()
        Method to query the agent local name.
        Returns:
        A String containing the local agent name (e.g. peter).
      • getName

        public final String getName()
        Method to query the agent complete name (GUID).
        Returns:
        A String containing the complete agent name (e.g. peter@fipa.org:50).
      • getHap

        public final String getHap()
        Method to query the Home Agent Platform. This is the name of the platform where the agent has been created, therefore it will never change during the entire lifetime of the agent. In JADE the name of an agent by default is composed by the concatenation (using '@') of the agent local name and the Home Agent Platform name
        Returns:
        A String containing the name of the home agent platform (e.g. myComputerName:1099/JADE).
      • getAID

        public final AID getAID()
        Method to query the private Agent ID. Note that this Agent ID is different from the one that is registered with the platform AMS.
        Returns:
        An Agent ID object, containing the complete agent GUID, addresses and resolvers.
      • getAID

        public final AID getAID​(String name)
        Method to build a complete agent GUID belonging to the same platform of the current agent
        Parameters:
        name - Agent local name.
        Returns:
        An Agent ID object, containing the complete agent GUID, addresses and resolvers.
      • isAlive

        public boolean isAlive()
        Returns true if the agent implemented by this Agent object is alive (regardless of the actual agent internal state). This means that the internal Thread of this Agent object exists and is alive.
        Returns:
        true if the agent implemented by this Agent object is alive
      • here

        public Location here()
        Method to retrieve the location this agent is currently at.
        Returns:
        A Location object, describing the location where this agent is currently running.
      • join

        public boolean join()
        This method is used internally by the framework and should NOT be used by programmers. This is used by the agent container to wait for agent termination. We have already called doDelete on the thread which would have issued an interrupt on it. However, it still may decide not to exit. So we will wait no longer than 5 seconds for it to exit and we do not care of this zombie agent. FIXME: we must further isolate container and agents, for instance by using custom class loader and dynamic proxies and JDK 1.3. FIXME: the timeout value should be got by Profile
      • setQueueSize

        public void setQueueSize​(int newSize)
                          throws IllegalArgumentException
        Set message queue size. This method allows to change the number of ACL messages that can be buffered before being actually read by the agent or discarded.
        Parameters:
        newSize - A non negative integer value to set message queue size to. Passing 0 means unlimited message queue. When the number of buffered messages exceeds this value, older messages are discarded according to a FIFO replacement policy.
        Throws:
        IllegalArgumentException - If newSize is negative.
        See Also:
        getQueueSize()
      • getCurQueueSize

        public int getCurQueueSize()
        This method retrieves the current length of the message queue of this agent.
        Returns:
        The number of messages that are currently stored into the message queue.
      • getQueueSize

        public int getQueueSize()
        Reads message queue size. A zero value means that the message queue is unbounded (its size is limited only by amount of available memory).
        Returns:
        The actual size of the message queue (i.e. the max number of messages that can be stored into the queue)
        See Also:
        setQueueSize(int newSize), getCurQueueSize()
      • getSentMessagesCnt

        public long getSentMessagesCnt()
      • getPostedMessagesCnt

        public long getPostedMessagesCnt()
      • getReceivedMessagesCnt

        public long getReceivedMessagesCnt()
      • getExecutedBehavioursCnt

        public long getExecutedBehavioursCnt()
      • changeStateTo

        public void changeStateTo​(LifeCycle newLifeCycle)
      • restoreBufferedState

        public void restoreBufferedState()
      • getState

        public int getState()
        Read current agent state. This method can be used to query an agent for its state from the outside.
        Returns:
        the Agent Platform Life Cycle state this agent is currently in.
      • getAgentState

        public AgentState getAgentState()
      • doMove

        public void doMove​(Location destination)
        Make this agent move to a remote location. This method is intended to support agent mobility and is called either by the Agent Platform or by the agent itself to start a migration process. It should be noted that this method just changes the agent state to AP_TRANSIT. The actual migration takes place asynchronously.
        NOT available in MIDP
        Parameters:
        destination - The Location to migrate to.
      • doClone

        public void doClone​(Location destination,
                            String newName)
        Make this agent be cloned on another location. This method is intended to support agent mobility and is called either by the Agent Platform or by the agent itself to start a clonation process. It should be noted that this method just changes the agent state to AP_COPY. The actual clonation takes place asynchronously.
        NOT available in MIDP
        Parameters:
        destination - The Location where the copy agent will start.
        newName - The name that will be given to the copy agent.
      • doSuspend

        public void doSuspend()
        Make a state transition from active or waiting to suspended within Agent Platform Life Cycle; the original agent state is saved and will be restored by a doActivate() call. This method can be called from the Agent Platform or from the agent itself and stops all agent activities. Incoming messages for a suspended agent are buffered by the Agent Platform and are delivered as soon as the agent resumes. Calling doSuspend() on a suspended agent has no effect.
        NOT available in MIDP
        See Also:
        doActivate()
      • doActivate

        public void doActivate()
        Make a state transition from suspended to active or waiting (whichever state the agent was in when doSuspend() was called) within Agent Platform Life Cycle. This method is called from the Agent Platform and resumes agent execution. Calling doActivate() when the agent is not suspended has no effect.
        NOT available in MIDP
        See Also:
        doSuspend()
      • doWait

        public void doWait()
        Make a state transition from active to waiting within Agent Platform Life Cycle. This method has only effect when called by the agent thread and causes the agent to block, stopping all its activities until a message arrives or the doWake() method is called.
        See Also:
        doWake()
      • doWait

        public void doWait​(long millis)
        Make a state transition from active to waiting within Agent Platform Life Cycle. This method adds a timeout to the other doWait() version.
        Parameters:
        millis - The timeout value, in milliseconds.
        See Also:
        doWait()
      • doWake

        public void doWake()
        Make a state transition from waiting to active within Agent Platform Life Cycle. This method is called from Agent Platform and resumes agent execution. Calling doWake() when an agent is not waiting has no effect.
        See Also:
        doWait()
      • doDelete

        public void doDelete()
        Make a state transition from active, suspended or waiting to deleted state within Agent Platform Life Cycle, thereby destroying the agent. This method can be called either from the Agent Platform or from the agent itself. Calling doDelete() on an already deleted agent has no effect.
      • write

        public void write​(OutputStream s)
                   throws IOException
        Write this agent to an output stream; this method can be used to record a snapshot of the agent state on a file or to send it through a network connection. Of course, the whole agent must be serializable in order to be written successfully. The saved state of the agent can later be restored via the restoreFields() method
        NOT available in MIDP
        Parameters:
        s - The stream this agent will be sent to. The stream is not closed on exit.
        Throws:
        IOException - Thrown if some I/O error occurs during writing.
        See Also:
        restoreFields(InputStream s)
      • restoreFields

        public void restoreFields​(InputStream s)
                           throws Exception
        Reads a previously saved agent state, and restore the agent user-defined fields replacing their current values. Only non-transient and non-static fields declared in the class of the agent will be restored. Fields declared in super-classes are left unchanged. The jade.core.Restore annotation can be used to skip the restoration of a field or to specify a user-defined method to perform the restoration.
        NOT available in MIDP
        Parameters:
        s - The input stream the agent state will be read from.
        Throws:
        Exception
      • getO2AObject

        public Object getO2AObject()
        This method picks an object (if present) from the internal object-to-agent communication queue. In order for this method to work, the agent must have declared its will to accept objects from other software components running within its JVM. This can be achieved by calling the jade.core.Agent.setEnabledO2ACommunication() method. If the retrieved object was originally inserted by an external component using a blocking call, that call will return during the execution of this method.
        NOT available in MIDP
        Returns:
        the first object in the queue, or null if the queue is empty.
        See Also:
        AgentController.putO2AObject(Object o, boolean blocking), setEnabledO2ACommunication(boolean enabled, int queueSize)
      • setEnabledO2ACommunication

        public void setEnabledO2ACommunication​(boolean enabled,
                                               int queueSize)
        This method declares this agent attitude towards object-to-agent communication, that is, whether the agent accepts to communicate with other non-JADE components living within the same JVM.
        NOT available in MIDP
        Parameters:
        enabled - Tells whether Java objects inserted with putO2AObject() will be accepted.
        queueSize - If the object-to-agent communication is enabled, this parameter specifiies the maximum number of Java objects that will be queued. If the passed value is 0, no maximum limit is set up for the queue.
        See Also:
        AgentController.putO2AObject(Object o, boolean blocking), getO2AObject()
      • setO2AManager

        public void setO2AManager​(Behaviour b)
        Sets the behaviour responsible for managing objects passed to the agent by means of the Object-To-Agent (O2A) communication mechanism. If the O2A manager behaviour is set, whenever an object is inserted in the O2A queue by means of the putO2AObject() method, only the manager is waken up. This improves the efficiency since all behaviours not interested in O2A communication remain sleeping.
        NOTE that this method only declares a behaviour as being responsible for managing objects received by the agent by means of the O2A communication channel; in order to correctly run, the behaviour must be added to the agent by means of the addBehaviour() method as usual.
        NOT available in MIDP
        Parameters:
        b - The behaviour that will act as O2A manager.
        See Also:
        AgentController.putO2AObject(Object o, boolean blocking), getO2AObject()
      • getO2AInterface

        public <T> T getO2AInterface​(Class<T> theInterface)
        Used internally by the framework
      • registerO2AInterface

        public <T> void registerO2AInterface​(Class<T> theInterface,
                                             T implementation)
        Registers an implementation for a given O2A interface. All invocations to methods of the O2A interface will be redirected to the registered implementation object.
        Parameters:
        theInterface - The O2A interface the implementation is registered for.
        implementation - The object providing an implementation for the given O2A interface.
      • run

        public final void run()
        This method is the main body of every agent. It provides startup and cleanup hooks for application programmers to put their specific code into.
        Specified by:
        run in interface Runnable
        See Also:
        setup(), takeDown()
      • clean

        public void clean​(boolean ok)
      • setup

        protected void setup()
        This protected method is an empty placeholder for application specific startup code. Agent developers can override it to provide necessary behaviour. When this method is called the agent has been already registered with the Agent Platform AMS and is able to send and receive messages. However, the agent execution model is still sequential and no behaviour scheduling is active yet. This method can be used for ordinary startup tasks such as DF registration, but is essential to add at least a Behaviour object to the agent, in order for it to be able to do anything.
        See Also:
        addBehaviour(Behaviour b), Behaviour
      • takeDown

        protected void takeDown()
        This protected method is an empty placeholder for application specific cleanup code. Agent developers can override it to provide necessary behaviour. When this method is called the agent has not deregistered itself with the Agent Platform AMS and is still able to exchange messages with other agents. However, no behaviour scheduling is active anymore and the Agent Platform Life Cycle state is already set to deleted. This method can be used for ordinary cleanup tasks such as DF deregistration, but explicit removal of all agent behaviours is not needed.
      • beforeMove

        protected void beforeMove()
        This empty placeholder shall be overridden by user defined agents to execute some actions before the original agent instance on the source container is stopped (e.g. releasing local resources such as a GUI).
        IMPORTANT: At this point, it is ensured that the move process is successful and that a moved agent instance has been created on the destination container Therefore setting the value of a class field in this method will have no impact on the moved agent instance. Such parameters must indeed be set before the doMove() method is called.
        NOT available in MIDP
      • afterMove

        protected void afterMove()
        Actions to perform after moving. This empty placeholder method can be overridden by user defined agents to execute some actions just after arriving to the destination agent container for a migration.
        NOT available in MIDP
      • beforeClone

        protected void beforeClone()
        This empty placeholder method shall be overridden by user defined agents to execute some actions before copying an agent to another agent container.
        NOT available in MIDP
        See Also:
        beforeMove(), afterClone()
      • afterClone

        protected void afterClone()
        Actions to perform after cloning. This empty placeholder method can be overridden by user defined agents to execute some actions just after creating an agent copy to the destination agent container.
        NOT available in MIDP
      • addBehaviour

        public void addBehaviour​(Behaviour b)
        This method adds a new behaviour to the agent. This behaviour will be executed concurrently with all the others, using a cooperative round robin scheduling. This method is typically called from an agent setup() to fire off some initial behaviour, but can also be used to spawn new behaviours dynamically.
        Parameters:
        b - The new behaviour to add to the agent.
        See Also:
        setup(), Behaviour
      • removeBehaviour

        public void removeBehaviour​(Behaviour b)
        This method removes a given behaviour from the agent. This method is called automatically when a top level behaviour terminates, but can also be called from a behaviour to terminate itself or some other behaviour.
        Parameters:
        b - The behaviour to remove.
        See Also:
        Behaviour
      • getBehavioursCnt

        public int getBehavioursCnt()
        Return the number of behaviours currently included in the agent pool (both runnable and blocked).
      • send

        public final void send​(ACLMessage msg)
        Send an ACL message to another agent. This methods sends a message to the agent specified in :receiver message field (more than one agent can be specified as message receiver).
        Parameters:
        msg - An ACL message object containing the actual message to send.
        See Also:
        ACLMessage
      • receive

        public final ACLMessage receive()
        Receives an ACL message from the agent message queue. This method is non-blocking and returns the first message in the queue, if any. Therefore, polling and busy waiting is required to wait for the next message sent using this method.
        Returns:
        A new ACL message, or null if no message is present.
        See Also:
        ACLMessage
      • receive

        public final ACLMessage receive​(MessageTemplate pattern)
        Receives an ACL message matching a given template. This method is non-blocking and returns the first matching message in the queue, if any. Therefore, polling and busy waiting is required to wait for a specific kind of message using this method.
        Parameters:
        pattern - A message template to match received messages against.
        Returns:
        A new ACL message matching the given template, or null if no such message is present.
        See Also:
        ACLMessage, MessageTemplate
      • receive

        public final List<ACLMessage> receive​(MessageTemplate pattern,
                                              int max)
        Read up to max messages from the agent message queue. This can be useful for performance reasons in situations where an agent has to deal with a heavy load of messages.
        Parameters:
        pattern - The MessageTemplate specifying which messages must be read. Setting this to null is equivalent to a MatchAll template
        max - The maximum number of messages to read
        Returns:
        The read messages in form of a List or null if no message matching the specified template is currently present in the agent message queue
      • blockingReceive

        public final ACLMessage blockingReceive()
        Receives an ACL message from the agent message queue. This method is blocking and suspends the whole agent until a message is available in the queue.
        Returns:
        A new ACL message, blocking the agent until one is available.
        See Also:
        receive(), ACLMessage
      • blockingReceive

        public final ACLMessage blockingReceive​(long millis)
        Receives an ACL message from the agent message queue, waiting at most a specified amount of time.
        Parameters:
        millis - The maximum amount of time to wait for the message.
        Returns:
        A new ACL message, or null if the specified amount of time passes without any message reception.
      • blockingReceive

        public final ACLMessage blockingReceive​(MessageTemplate pattern)
        Receives an ACL message matching a given message template. This method is blocking and suspends the whole agent until a message is available in the queue.
        Parameters:
        pattern - A message template to match received messages against.
        Returns:
        A new ACL message matching the given template, blocking until such a message is available.
        See Also:
        receive(MessageTemplate), ACLMessage, MessageTemplate
      • blockingReceive

        public final ACLMessage blockingReceive​(MessageTemplate pattern,
                                                long millis)
        Receives an ACL message matching a given message template, waiting at most a specified time.
        Parameters:
        pattern - A message template to match received messages against.
        millis - The amount of time to wait for the message, in milliseconds.
        Returns:
        A new ACL message matching the given template, or null if no suitable message was received within millis milliseconds.
        See Also:
        blockingReceive()
      • putBack

        public final void putBack​(ACLMessage msg)
        Puts a received ACL message back into the message queue. This method can be used from an agent behaviour when it realizes it read a message of interest for some other behaviour. The message is put in front of the message queue, so it will be the first returned by a receive() call.
        See Also:
        receive()
      • waitUntilStarted

        public void waitUntilStarted()
        This method blocks until the agent has finished its start-up phase (i.e. until just before its setup() method is called. When this method returns, the target agent is registered with the AMS and the JADE platform is aware of it.
      • notifyChangeBehaviourState

        public void notifyChangeBehaviourState​(Behaviour b,
                                               String from,
                                               String to)
      • setGenerateMessageEvents

        public void setGenerateMessageEvents​(boolean b)
        Allow disabling/enabling (default: enabled) the generation of message-related events (such as NOTIFY_POSTED or NOTIFY_RECEIVED)
      • getGenerateMessageEvents

        public boolean getGenerateMessageEvents()
      • setGenerateBehaviourEvents

        public void setGenerateBehaviourEvents​(boolean b)
        Allow enabling/disabling (default: disabled) the generation of message-related events (such as NOTIFY_BEHAVIOUR_ADDED or NOTIFY_CHANGED_BEHAVIOUR_STATE)
      • getGenerateBehaviourEvents

        public boolean getGenerateBehaviourEvents()
      • postMessage

        public final void postMessage​(ACLMessage msg)
        Put a received message into the agent message queue. The message is put at the back end of the queue. This method is called by JADE runtime system when a message arrives, but can also be used by an agent, and is just the same as sending a message to oneself (though slightly faster).
        Parameters:
        msg - The ACL message to put in the queue.
        See Also:
        send(ACLMessage msg)
      • getContentManager

        public ContentManager getContentManager()
        Retrieves the agent's content manager
        Returns:
        The content manager.
      • getProperty

        public String getProperty​(String key,
                                  String aDefault)
        Retrieve a configuration property set in the Profile of the local container (first) or as a System property.
        Parameters:
        key - the key that maps to the property that has to be retrieved.
        aDefault - a default value to be returned if there is no mapping for key
      • getBootProperties

        public Properties getBootProperties()
        Return the configuration properties exactly as they were passed to the Profile before starting the local JADE container.