public class ProcessQueue<P extends SimProcess> extends QueueBased implements java.lang.Iterable<P>
SimProcess
es in. The sort order of the ProcessQueue is
determined first by the priorities of the enqueued SimProcesses and second by
the given sort order. The default sort order is FIFO (first in, first out)
but others like LIFO (last in, first out) can be chosen, too. See the
constants in class QueueBased
and the derived classes from
QueueList
. The capacity of the ProcessQueue, that is the
maximum number of SimProcesses enqueued, can be chosen, too. Note that in
contrast to the 'plain' queue, this ProcessQueue always expects and returns
objects that are derived from class SimProcess
. When
modelling using the process-, activity-, or transaction-oriented paradigm
where SimProcesses are used to represent the model's entities, this
ProcessQueue can be used instead of the standard Queue to reduce the amount
of casts needed otherwise.QueueBased
,
QueueList
,
QueueListFifo
,
QueueListLifo
QueueBased.QueueAction
FIFO, LIFO, RANDOM, UNDEFINED
Constructor and Description |
---|
ProcessQueue(Model owner,
java.lang.String name,
boolean showInReport,
boolean showInTrace)
Constructs a simple priority and FIFO based waiting-queue for
SimProcesses with a maximum capacity of 2,147,483,647 waiting
processes, which should serve as an approximation of infinite
queues sufficiently well for most purposes.
|
ProcessQueue(Model owner,
java.lang.String name,
int sortOrder,
int qCapacity,
boolean showInReport,
boolean showInTrace)
Constructs a simple priority based waiting-queue for SimProcesses, the
kind of queue implementation (FIFO or LIFO) and the capacity of the queue
can be chosen.
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(P p)
Returns
true if the given SimProcess is
contained in the queue; false otherwise. |
Reporter |
createDefaultReporter()
Returns a process-queue-reporter to produce a report about this
process-queue.
|
P |
first()
Returns the first SimProcess queued in this process-queue or
null in case the queue is empty. |
P |
first(Condition<P> c)
Returns the first SimProcess queued in this process-queue that applies to
the given condition.
|
P |
get(int index)
Returns the
SimProcess queued at the named position. |
int |
get(P p)
Returns the queue index of a given
SimProcess . |
QueueList<P> |
getQueueList()
Returns the underlying queue implementation, providing access to the
QueueList implementation, e.g. to add PropertyChangeListeners.
|
java.lang.String |
getQueueStrategy()
Returns the implemented queueing discipline of the underlying queue as a
String, so it can be displayed in the report.
|
long |
getRefused()
Returns the number of entities refused to be enqueued in the queue,
because the capacity limit is reached.
|
boolean |
insert(P p)
Enters a new SimProcess into the ProcessQueue.
|
boolean |
insertAfter(P p,
P after)
Enters a new SimProcess into the process-queue and places it after the
given SimProcess.
|
boolean |
insertBefore(P p,
P before)
Enters a new SimProcess into the ProcessQueue and places it in front of
the given SimProcess.
|
boolean |
isEmpty()
Returns a boolean value indicating if the process-queue is empty or if any
number of SimProcess is currently enqueued in it.
|
java.util.Iterator<P> |
iterator()
Returns an iterator over the processes enqueued.
|
P |
last()
Returns the last SimProcess queued in this process-queue or
null in case the process-queue is empty. |
P |
last(Condition<P> c)
Returns the last SimProcess queued in this process-queue that applies to
the given condition.
|
P |
pred(P p)
Returns the SimProcess enqueued directly before the given SimProcess in
the process-queue.
|
P |
pred(P p,
Condition<P> c)
Returns the SimProcess enqueued before the given SimProcess in the
process-queue that also fulfills the condition given.
|
boolean |
remove(int index)
Removes the process queued at the given position.
|
void |
remove(SimProcess p)
Removes the given SimProcess from the process-queue.
|
void |
removeAll()
Removes all processes from the Queue.
|
P |
removeFirst()
Removes the first process from the queue and provides a reference to
this process.
|
P |
removeFirst(Condition<P> c)
Removes the first process from the queue that fulfills to the given
condition.
|
P |
removeLast()
Removes the last process from the queue and provides a reference to
this process.
|
P |
removeLast(Condition<P> c)
Removes the last process from the queue that fulfills to the given
condition, determined by traversing the queue from last to first until
a process fulfilling the condition is found.
|
void |
reset()
Resets all statistical counters to their default values.
|
void |
setQueueCapacity(int newCapacity)
Sets the queue capacity to a new value.
|
void |
setQueueStrategy(int sortOrder)
Sets the sort order of this ProcessQueue to a new value and makes this
ProcessQueue use another
QueueList with the specified
queueing discipline. |
void |
setRefused(long n)
Sets the number of entities refused to be enqueued in the queue because
the capacity limit is reached to a new value.
|
int |
size()
Returns the current length of the Queue.
|
P |
succ(P p)
Returns the SimProcess enqueued directly after the given SimProcess in
the process-queue.
|
P |
succ(P p,
Condition<P> c)
Returns the SimProcess enqueued after the given SimProcess in the
process-queue that also fulfills the condition given.
|
addObserver, averageLength, averageWaitTime, deleteObserver, getQueueLimit, length, maxLength, maxLengthAt, maxWaitTime, maxWaitTimeAt, minLength, minLengthAt, notifyObservers, setQueueImpWarning, stdDevLength, stdDevWaitTime, zeroWaits
getCorrespondingSchedulable, getDescription, getObservations, getReporter, incrementObservations, incrementObservations, reportIsOn, reportOff, reportOn, resetAt, setCorrespondingSchedulable, setDescription, setReporter
current, currentEntity, currentEntityAll, currentEvent, currentModel, currentSimProcess, debugIsOn, debugOff, debugOn, getModel, isExperimentCompatible, isModelCompatible, presentTime, sendDebugNote, sendMessage, sendTraceNote, sendWarning, skipTraceNote, skipTraceNote, traceIsOn, traceOff, traceOn
getName, getQuotedName, toString
public ProcessQueue(Model owner, java.lang.String name, int sortOrder, int qCapacity, boolean showInReport, boolean showInTrace)
The usage of the generic version ProcessQueue<Type>
where
Type
is derived from SimProcess
is recommended
for type safety. Using the raw type ProcessQueue
yields a queue
in which any SimProcess
can be enqueued, potentially requiring
type casting on accessing processes enqueued.
owner
- Model : The model this ProcessQueue is associated toname
- java.lang.String : The process-queue's namesortOrder
- int : determines the sort order of the underlying queue
implementation. Choose a constant from QueueBased
:
QueueBased.FIFO
, QueueBased.LIFO
or
QueueBased.Random.qCapacity
- int : The capacity of the Queue, that is how many processes can
be enqueued. Zero (0) can be used as shortcut for
for a capacity of Integer.MAX_VALUE
= 2,147,483,647,
which should approximate an infinite queue sufficiently well
for most purposes.showInReport
- boolean : Flag if process-queue should produce a reportshowInTrace
- boolean : Flag for process-queue to produce trace messagespublic ProcessQueue(Model owner, java.lang.String name, boolean showInReport, boolean showInTrace)
The usage of the generic version ProcessQueue<Type>
where
Type
is derived from SimProcess
is recommended
for type safety. Using the raw type ProcessQueue
yields a queue
in which any SimProcess
can be enqueued, potentially requiring
type casting on accessing processes enqueued.
owner
- Model : The model this process-queue is associated toname
- java.lang.String : The process-queue's nameshowInReport
- boolean : Flag if process-queue should produce a reportshowInTrace
- boolean : Flag for process-queue to produce trace messagespublic Reporter createDefaultReporter()
public P first()
null
in case the queue is empty.null
if the process-queue is emptypublic P first(Condition<P> c)
true
when the condition
is applied to it is returned by this method. If no SimProcess applies to
the given condition or the process-queue is empty, null
will be returned.c
- Condition : The condition that the SimProcess returned must
confirmnull
public boolean contains(P p)
true
if the given SimProcess
is
contained in the queue; false
otherwise.e
- E : The Entity
we are looking for
in the queue.True
if the given
SimProcess
is contained in the queue;
false
otherwise.public int size()
public int get(P p)
SimProcess
.int
.
Returns -1 if no such position exists.public P get(int index)
SimProcess
queued at the named position.
The first position is 0, the last one size()-1.SimProcess
at the position of
int
or null
if no such position exists.public QueueList<P> getQueueList()
public java.lang.String getQueueStrategy()
public long getRefused()
public boolean insert(P p)
false
will be returned. The SimProcess will be stored in
the ProcessQueue until method remove(SimProcess p)
is
called with this specific SimProcess. Simprocesses are ordered according
to their priority. Higher priorities are sorted in front of lower
priorities. Simprocesses with same priority are orderer according to the
strategy specified in the constructor. The first SimProcess inside the
process-queue will always be the one with the highest priority.P
- p : The SimProcess to be added to the
ProcessQueuetrue
if insertion was successful,
false
otherwise (i.e. capacity limit is reached).public boolean insertAfter(P p, P after)
false
will be returned. Make sure
that the SimProcess given as reference is already queued inside the
process-queue, else the SimProcess will not be enqueued and
false
will be returned. The SimProcess will be stored in
the ProcessQueue until method remove(SimProcess p)
is
called with this specific SimProcess.p
- P :The SimProcess to be added to the process-queueafter
- P :The SimProcess after which SimProcess 'p' is to
be insertedtrue
if insertion was successful,
false
otherwise (i.e. capacity limit is reached).public boolean insertBefore(P p, P before)
false
will be returned.
Make sure that the SimProcess given as reference is already queued inside
the ProcessQueue, else the SimProcess will not be enqueued and
false
will be returned. The SimProcess will be stored in
the ProcessQueue until method remove(SimProcess p)
is
called with this specific SimProcess.p
- P : The SimProcess to be added to the processqQueuebefore
- P : The SimProcess before which the SimProcess 'p' is
to be insertedtrue
if insertion was successful,
false
otherwise (i.e. capacity limit is reached).public boolean isEmpty()
true
if the process-queue is empty,
false
otherwisepublic P last()
null
in case the process-queue is empty.null
if the process-queue is emptypublic P last(Condition<P> c)
true
when the condition
is applied to it is returned by this method. If no SimProcess applies to
the given condition or the process-queue is empty, null
will be returned.c
- Condition : The condition that the SimProcess returned must
fulfillnull
public P pred(P p)
null
is returned.p
- P : An SimProcess in the process-queuenull
.public P pred(P p, Condition<P> c)
null
is
returned. If no other SimProcess before the given one fulfills the
condition, null
is returned, too.p
- P : A SimProcess in the process-queuec
- Condition : The condition that the preceeding SimProcess has
to fulfillnull
.public void remove(SimProcess p)
p
- P :The SimProcess to be removed from the
process-queuepublic void removeAll()
public P removeFirst()
null
in case the queue was emptypublic P removeFirst(Condition<P> c)
c
- Condition : The condition that the process returned must fulfillNull
in case no process
fulfills the condition.public P removeLast()
null
is returned.null
in case the queue was emptypublic P removeLast(Condition<P> c)
null
is returned.c
- Condition : The condition that the entity returned must fulfillNull
in case no process
fulfills the condition.public boolean remove(int index)
true
if a SimProcess
exists at the given position or false>
if otherwise.public void reset()
reset
in class QueueBased
public void setQueueCapacity(int newCapacity)
newCapacity
- int : The new capacity of this ProcessQueue.public void setQueueStrategy(int sortOrder)
QueueList
with the specified
queueing discipline. Please choose a constant from
QueueBased
(QueueBased.FIFO
,
QueueBased.FIFO
or QueueBased.Random
)
The sort order of a ProcessQueue can only be changed if the queue is empty.sortOrder
- int : determines the sort order of the underlying
QueueList
implementation (QueueBased.FIFO
,
QueueBased.FIFO
or QueueBased.Random
)public void setRefused(long n)
n
- long : the new number of entities refused to be enqueued in
the queue because the capacity limit is reached.public P succ(P p)
null
is returned.p
- P : A SimProcess in the process-queuenull
public P succ(P p, Condition<P> c)
null
is
returned. If no other SimProcess after the given one fulfills the
condition, null
is returned, too.p
- P : A SimProcess in the process-queuec
- Condition : The condition that the succeeding SimProcess has
to fulfillnull
.public java.util.Iterator<P> iterator()
iterator
in interface java.lang.Iterable<P extends SimProcess>