Module org.bzdev.devqsim
Package org.bzdev.devqsim
Class PriorityServerQueue<QS extends QueueServer>
java.lang.Object
org.bzdev.devqsim.SimObject
org.bzdev.devqsim.DefaultSimObject
org.bzdev.devqsim.ServerQueue<PriorityTaskQueue.PriorityParam,QS>
org.bzdev.devqsim.PriorityServerQueue<QS>
- 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 Summary
ConstructorsConstructorDescriptionPriorityServerQueue
(Simulation sim, boolean intern, QS... servers) Constructor for unnamed priority-server-queues.PriorityServerQueue
(Simulation sim, String name, boolean intern, QS... servers) Constructor for named priority-server queues. -
Method Summary
Modifier and TypeMethodDescriptionadd
(QueueCallable<QS> callable, int priority, long delay) Add a QueueCallable to the queue.add
(QueueRunnable<QS> runnable, int priority, long delay) Add a QueueRunnable to the queue.add
(SimObjQueueCallable<QS> callable, int priority, long delay) Add a SimObjQueueCallable to the queue.add
(SimObjQueueRunnable<QS> runnable, int priority, long delay) Add a SimObjQueueRunnable to the queue.addCallScriptObject
(Object scriptObject, int priority, long delay) Queue an event given a script object that implements the QueueCallable interface.boolean
addCurrentTask
(QueueServerHandler<QS> handler, int priority, long delay) Add the currently running task thread to a queue.boolean
addCurrentTask
(QueueServerHandler<QS> handler, int priority, long delay, SimEventCallable callable) Add the currently running task thread to a queue.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.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.addTaskScriptObject
(Object scriptObject, int priority, long delay) Queue an event given a script object that provides QueueRunnable interface.protected Object
clone()
Creates and returns a copy of this object.final boolean
delete()
Delete an object.final boolean
Determine if an object is being deleted.final String
getName()
Get an object's name.protected Simulation
Get the object namer for a named object.final boolean
Determine if an object has been deleted.boolean
Determine if an object is interned in a object namer's tables.Methods inherited from class org.bzdev.devqsim.ServerQueue
addCurrentTask, addCurrentTaskScriptObject, addObserver, canDelete, canFreeze, doAdd, doAdd, doAdd, doAdd, doAddCallObject, doAddTaskObject, freeze, getDeletePolicy, getIdleServer, getTaskQueue, inUseCount, isBusy, isFrozen, onDelete, printConfiguration, printState, putIdleServer, removeObserver, serverCount, setCanFreeze, setDeletePolicy, size
Methods inherited from class org.bzdev.devqsim.DefaultSimObject
getSimulation
Methods inherited from class org.bzdev.devqsim.SimObject
addSimulationListener, addTraceSet, bindCallable, bindCallable, bindCallable, bindCallable, bindRunnable, bindRunnable, bindRunnable, bindRunnable, callableObject, callableScript, callScriptFunction, callScriptMethod, clearTraceSets, evalScript, getEventListenerList, getScriptObject, getTraceSets, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printState, printState, printState, printState, printState, printState, putScriptObject, removeSimulationListener, removeTraceSet, runnableObject, runnableScript, scheduleCall, scheduleCall, scheduleCall, scheduleCall, scheduleCallObject, scheduleScript, scheduleTask, scheduleTask, scheduleTask, scheduleTask, scheduleTaskObject, scheduleTaskScript, startImmediateTask, startImmediateTask, trace, trace, unscheduledTaskThread, unscheduledTaskThread, update, update, usesTraceSet
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.bzdev.obnaming.NamedObjectOps
delete, deletePending, getName, isDeleted, isInterned
Methods inherited from interface org.bzdev.devqsim.QueueStatus
getName, isDeleted, isInterned
-
Constructor Details
-
PriorityServerQueue
Constructor for unnamed priority-server-queues. If interned, a name will be automatically generated.- Parameters:
sim
- the simulationintern
- true of the queue should be interned in the simulation's name table; false otherwiseservers
- 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 simulationname
- the name of the queueintern
- true if the queue name should be interned in the simulation tables; false otherwiseservers
- the queue's servers- Throws:
IllegalArgumentException
- typically means a name is already in use
-
-
Method Details
-
add
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 addpriority
- the priority for the Callable to be addeddelay
- 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
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 addpriority
- the priority for the Callable to be addeddelay
- 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
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: aninteractWith
method that takes a server as an argument (the server's type is set by the type parameter QS) and acall
method that has no arguments. TheinteractWith
method will be called first, followed by thecall
method.- Parameters:
scriptObject
- the object specifying the task to be queuedpriority
- the priority for the Runnable to be addeddelay
- 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
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 queuepriority
- the priority for the Runnable to be addeddelay
- 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
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 queuepriority
- the priority for the Runnable to be addeddelay
- 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
Queue an event given a script object that provides QueueRunnable interface. The script object must implement a method namedinteractWith
that takes a QueueServer as its argument and a method with no arguments namedrun
, 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 addeddelay
- the delay to wait before the task is restarted once scheduled.- Returns:
- the SimulationEvent created; null if the QueueRunnable cannot be queued
-
addCurrentTask
Add the currently running task thread to a queue.- Parameters:
handler
- the handler whoseinteractWith
method will be called with a queue server as its argument when the queue server handles the queue entry being processedpriority
- the priority for the task to be addeddelay
- 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
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 namedinteractWith
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 addeddelay
- 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 namedinteractWith
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 addeddelay
- 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 whoseinteractWith
method will be called with a queue server as its argument when the queue server handles the queue entry being processedpriority
- the priority for the task to be addeddelay
- 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
Creates and returns a copy of this object. This method will throw the exception CloneNotSupportedException if the object is interned.- Overrides:
clone
in classObject
- 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 interfaceNamedObjectOps
- Returns:
- true if the object is interned; false if not
-
getObjectNamer
Get the object namer for a named object.- Returns:
- the object namer for this named object
-
getName
Get an object's name.- Specified by:
getName
in interfaceNamedObjectOps
- 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 interfaceNamedObjectOps
- 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 interfaceNamedObjectOps
- 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 interfaceNamedObjectOps
- Returns:
- true if deletion is pending; false otherwise
-