Class PriorityServerQueue<QS extends QueueServer>

All Implemented Interfaces:
QueueStatus, NamedObjectOps

public class PriorityServerQueue<QS extends QueueServer> extends ServerQueue<PriorityTaskQueue.PriorityParam,QS>
Priority server queue. This implements a ServerQueue in which the entries are processed in FIFO (First In, First Out) order for each priority. Lower priority values are used first.
See Also:
  • Constructor Details

    • PriorityServerQueue

      public PriorityServerQueue(Simulation sim, boolean intern, QS... servers)
      Constructor for unnamed priority-server-queues. If interned, a name will be automatically generated.
      Parameters:
      sim - the simulation
      intern - true of the queue should be interned in the simulation's name table; false otherwise
      servers - the queue's servers
    • PriorityServerQueue

      public PriorityServerQueue(Simulation sim, String name, boolean intern, QS... servers) throws IllegalArgumentException
      Constructor for named priority-server queues.
      Parameters:
      sim - the simulation
      name - the name of the queue
      intern - true if the queue name should be interned in the simulation tables; false otherwise
      servers - the queue's servers
      Throws:
      IllegalArgumentException - typically means a name is already in use
  • Method Details

    • add

      public SimulationEvent add(QueueCallable<QS> callable, int priority, long delay)
      Add a QueueCallable to the queue. When the QueueCallable is scheduled and the corresponding event is processed, its call() method will be executed.
      Parameters:
      callable - the QueueCallable to add
      priority - the priority for the Callable to be added
      delay - the interval between when callable is scheduled to be called and when it is actually called, representing the service time for this queue entry.
      Returns:
      the SimulationEvent created; null if the QueueCallable cannot be queued
    • add

      public SimulationEvent add(SimObjQueueCallable<QS> callable, int priority, long delay)
      Add a SimObjQueueCallable to the queue. When the SimObjQueueCallable is scheduled and the corresponding event is processed, its call() method will be executed.
      Parameters:
      callable - the QueueCallable to add
      priority - the priority for the Callable to be added
      delay - the interval between when callable is scheduled to be called and when it is actually called, representing the service time for this queue entry.
      Returns:
      the SimulationEvent created; null if the QueueCallable cannot be queued
    • addCallScriptObject

      public SimulationEvent addCallScriptObject(Object scriptObject, int priority, long delay)
      Queue an event given a script object that implements the QueueCallable interface. The method's first argument is an object defined in the simulation's scripting language that implements two methods: an interactWith method that takes a server as an argument (the server's type is set by the type parameter QS) and a call method that has no arguments. The interactWith method will be called first, followed by the call method.
      Parameters:
      scriptObject - the object specifying the task to be queued
      priority - the priority for the Runnable to be added
      delay - the interval between when runnable is scheduled to be started and when it is actually started, representing the service time for this queue entry.
      Returns:
      the SimulationEvent created; null if the QueueCallable cannot be queued
    • add

      public SimulationEvent add(QueueRunnable<QS> runnable, int priority, long delay)
      Add a QueueRunnable to the queue. When the QueueRunnable is scheduled and the corresponding event is processed, a task thread will be started executing the Runnable. Task threads and the simulation's thread run one at a time, including on a multiprocessor.
      Parameters:
      runnable - the QueueRunnable to add to the queue
      priority - the priority for the Runnable to be added
      delay - the interval between when runnable is scheduled to be started and when it is actually started, representing the service time for this queue entry.
      Returns:
      the SimulationEvent created; null if the QueueRunnable cannot be queued
    • add

      public SimulationEvent add(SimObjQueueRunnable<QS> runnable, int priority, long delay)
      Add a SimObjQueueRunnable to the queue. When the SimObjQueueRunnable is scheduled and the corresponding event is processed, a task thread will be started executing the Runnable. Task threads and the simulation's thread run one at a time, including on a multiprocessor.
      Parameters:
      runnable - the SimObjQueueRunnable to add to the queue
      priority - the priority for the Runnable to be added
      delay - the interval between when runnable is scheduled to be started and when it is actually started, representing the service time for this queue entry.
      Returns:
      the SimulationEvent created; null if the QueueRunnable cannot be queued
    • addTaskScriptObject

      public SimulationEvent addTaskScriptObject(Object scriptObject, int priority, long delay)
      Queue an event given a script object that provides QueueRunnable interface. The script object must implement a method named interactWith that takes a QueueServer as its argument and a method with no arguments named run, which will be executed in that order in a task thread. This should be called by a subclass to add an event to a queue, as the currently scheduled event is handled specially. The subclass is responsible for using its "add" method's arguments to construct an instance of type T.
      Parameters:
      scriptObject - the script object specifying the task to be queued.
      priority - the priority for the task to be added
      delay - the delay to wait before the task is restarted once scheduled.
      Returns:
      the SimulationEvent created; null if the QueueRunnable cannot be queued
    • addCurrentTask

      public boolean addCurrentTask(QueueServerHandler<QS> handler, int priority, long delay)
      Add the currently running task thread to a queue.
      Parameters:
      handler - the handler whose interactWith method will be called with a queue server as its argument when the queue server handles the queue entry being processed
      priority - the priority for the task to be added
      delay - the delay to wait before the task is restarted once scheduled.
      Returns:
      true on success; false if the task cannot be placed on the queue
    • addCurrentTaskScriptObject

      public boolean addCurrentTaskScriptObject(Object scriptObject, int priority, long delay)
      Add the currently running task thread to a queue, specifying a script object to implement the QueueServerHandler interface. The script object must implement a method named interactWith that takes a single argument, a QueueServer, and this method will be called before the task resumes.
      Parameters:
      scriptObject - the script object specifying the task to be queued.
      priority - the priority for the task to be added
      delay - the delay to wait before the task is restarted once scheduled.
      Returns:
      A simulation event on success; null on failure in which case the current thread will continue to run
    • addCurrentTaskScriptObject

      public boolean addCurrentTaskScriptObject(Object scriptObject, int priority, long delay, Object scriptSimEventCallable)
      Add the currently running task thread to a queue, specifying a script object to implement the QueueServerHandler interface. The script object must implement a method named interactWith that takes a single argument, a QueueServer, and this method will be called before the task resumes. The scriptSimEventCallable argument is an object that implements a method named call that takes a single argument, a SimulationEvent. Typically this argument will be stored in case it is necessary to remove the task from the queue and restart it.
      Parameters:
      scriptObject - the script object specifying the task to be queued.
      priority - the priority for the task to be added
      delay - the delay to wait before the task is restarted once scheduled.
      scriptSimEventCallable - the script object that obtains a SimulationEvent that can be used to remove the task from the queue
      Returns:
      A simulation event on success; null on failure in which case the current thread will continue to run
    • addCurrentTask

      public boolean addCurrentTask(QueueServerHandler<QS> handler, int priority, long delay, SimEventCallable callable)
      Add the currently running task thread to a queue.
      Parameters:
      handler - the handler whose interactWith method will be called with a queue server as its argument when the queue server handles the queue entry being processed
      priority - the priority for the task to be added
      delay - the delay to wait before the task is restarted once scheduled.
      callable - this argument's call method will be run when the event is scheduled and will be passed a simulation event (e.g., to store the event to allow the event to be canceled)
      Returns:
      true on success; false if the task cannot be placed on the queue
    • clone

      protected Object clone() throws CloneNotSupportedException
      Creates and returns a copy of this object. This method will throw the exception CloneNotSupportedException if the object is interned.
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException - a clone could not be created
      See Also:
    • isInterned

      public boolean isInterned()
      Determine if an object is interned in a object namer's tables.
      Specified by:
      isInterned in interface NamedObjectOps
      Returns:
      true if the object is interned; false if not
    • getObjectNamer

      protected Simulation getObjectNamer()
      Get the object namer for a named object.
      Returns:
      the object namer for this named object
    • getName

      public final String getName()
      Get an object's name.
      Specified by:
      getName in interface NamedObjectOps
      Returns:
      the name of the object
    • delete

      public final boolean delete()
      Delete an object. An object can only be deleted once. If this method returns true, the object (if interned) will have been removed from the object namer tables.

      The implementations provided by DefaultNamedObect and generated because of a @NamedObject annotation provide a protected method named onDelete. A subclass that overrides onDelete() must call the onDelete method of its superclass after it's onDelete method has been called and any cleanup actions performed. In some cases, this may happen at a later time (e.g., if a thread is used for some of the cleanup operations or if it is otherwise necessary to wait).

      Specified by:
      delete in interface NamedObjectOps
      Returns:
      true if the deletion request was accepted; false otherwise
    • isDeleted

      public final boolean isDeleted()
      Determine if an object has been deleted. An object is deleted if the method delete() has been called and returned true.
      Specified by:
      isDeleted in interface NamedObjectOps
      Returns:
      true if deleted; false otherwise
    • deletePending

      public final boolean deletePending()
      Determine if an object is being deleted. An deletion is pending if the method delete() has been called and returned true but the deletion has not been completed.
      Specified by:
      deletePending in interface NamedObjectOps
      Returns:
      true if deletion is pending; false otherwise