Package jade.util

Class InputQueue


  • public class InputQueue
    extends Object
    This class implements a FIFO queue of objects that can be put and got in a synchronized way. This is useful when an external thread, e.g. a GUI, has to communicate with an agent: The external thread puts objects in the queue and the agent gets and processes them. The queue can be associated to a Behaviour. This Behaviour will be restarted each time an object is inserted in the queue. This class can be effectively used in combination with the Event class to support a synchronization between the external therad (posting the event in the InputQueue) and the Agent thread (processing the event).
    Author:
    Giovanni Caire - TILab
    See Also:
    Event
    • Constructor Detail

      • InputQueue

        public InputQueue()
        Default constructor.
    • Method Detail

      • associate

        public void associate​(Behaviour b)
        Associate this InputQueue object with the indicated Behaviour so that it will be restarted each time a new object is inserted.
        Parameters:
        b - The Behaviour to associate.
      • put

        public void put​(Object obj)
        Insert an object into the queue. If there is a Behaviour associated to this InputQueue it will be restarted.
        Parameters:
        obj - The object to insert.
      • get

        public Object get()
        Extract the first object in the queue (if any).
        Returns:
        The first object in the queue or null if the queue is empty.
      • clear

        public void clear()
        Remove all elements from this queue.