public class Res extends QueueBased
provide()
resources to them. Each
process has to give back the same resources it once has acquired by calling
the takeBack()
method of the Res. Res is used to implement
process synchronization between processes, which are using resources. The
resource pool has a limited capacity. A process can acquire one or more
resources and use them. After usage the process must release this or these
same resources to make them available to other processes. If a process can
not get the number of resources needed, it has to wait in a queue until
enough resources are released by other processes. A process can release its
resources anytime. After the resourcepool has "takenBack"()
the
used resources the waiting-queue is checked for processes waiting for them.
The first sort criterion of the queue is highest queueing priorities first
(i.e. not using scheduling priorities - note that this is a somewhat arbitrary
choice, as the Res
is derived from QueueBased
, which provides all the statistical functionality
for a queue.QueueBased
QueueBased.QueueAction
FIFO, LIFO, RANDOM, UNDEFINED
Constructor and Description |
---|
Res(Model owner,
java.lang.String name,
int capacity,
boolean showInReport,
boolean showInTrace)
Constructor for a Res with a number of initial resources in it.
|
Res(Model owner,
java.lang.String name,
int sortOrder,
int qCapacity,
int capacity,
boolean showInReport,
boolean showInTrace)
Constructor for a Res with a number of initial resources in it.
|
Modifier and Type | Method and Description |
---|---|
double |
avgUsage()
Returns the average usage of the Res.
|
void |
changeLimit(int m)
Changes the limit of the available resources in the Res.
|
Reporter |
createDefaultReporter()
Returns a Reporter to produce a report about this Res.
|
void |
deadlockCheckOff()
Turns the deadlock check off.
|
void |
deadlockCheckOn()
Turns the deadlock check on.
|
int |
getAvail()
Returns the number of resources available in the pool at the moment.
|
boolean |
getDeadlockCheck()
Returns if the deadlock check is enabled (
true ) or not (
false ). |
long |
getidNumber()
Returns the ID number of this
Res object. |
int |
getLimit()
Returns the initial number of resources in the Res pool.
|
int |
getMinimum()
Returns the minimum number of resources in the Res.
|
boolean |
getPassBy()
Returns whether entities can pass by other entities which are enqueued
before them in the queue.
|
QueueList<SimProcess> |
getQueue()
Returns the
QueueList actually storing the
SimProcesses waiting for resources. |
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.
|
long |
getUsers()
Returns the number of users.
|
boolean |
isDeadlockDetected()
Returns
true if a deadlock is detected, false
otherwise. |
boolean |
provide(int n)
Gets a number of n resources from the Res pool and provides them to the
Sim-process to use them.
|
void |
reset()
Resets the statistics of this Res.
|
void |
setDeadlockDetected(boolean dlDetected)
Sets the boolean field
deadlockDetected to the given value. |
void |
setPassBy(boolean newPassBy)
Sets the flag passBy to a new value.
|
void |
takeBack(int n)
A process is using this method to put resources it has used back in the
Res pool.
|
void |
takeBack(Resource[] returnedRes)
A process is using this method to put resources it has used back in the
Res pool.
|
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 Res(Model owner, java.lang.String name, int sortOrder, int qCapacity, int capacity, boolean showInReport, boolean showInTrace)
owner
- Model : The model this Res is associated to.name
- java.lang.String : The Res's namesortOrder
- int : determines the sort order of the underlying queue
implementation. Choose a constant from QueueBased
like QueueBased.FIFO
or
QueueBased.LIFO
or ...qCapacity
- int : The capacity of the queue, that is how many processes
can be enqueued. Zero (0) means unlimited capacity.capacity
- int : The number of resources the Res starts with. Must be
positive and greater than 0.showInReport
- boolean : Flag, if Res should produce a report or not.showInTrace
- boolean : Flag for trace to produce trace messages.public Res(Model owner, java.lang.String name, int capacity, boolean showInReport, boolean showInTrace)
owner
- Model : The model this Res is associated to.name
- java.lang.String : The Res's namecapacity
- int : The number of resources the Res starts with. Must be
positive and greater than 0.showInReport
- boolean : Flag, if Res should produce a report or not.showInTrace
- boolean : Flag for trace to produce trace messages.public double avgUsage()
public void changeLimit(int m)
m
- int : The new limit (capacity) of the Res. Must be positive.public Reporter createDefaultReporter()
public void deadlockCheckOff()
public void deadlockCheckOn()
public int getAvail()
public boolean getDeadlockCheck()
true
) or not (
false
).true
if the deadlock check is enabled,
false
if the deadlock check is not enabledpublic long getidNumber()
Res
object.Res
object.public int getLimit()
public int getMinimum()
public boolean getPassBy()
public QueueList<SimProcess> getQueue()
QueueList
actually storing the
SimProcesses
waiting for resources.SimProcesses
waiting for resources.public java.lang.String getQueueStrategy()
public long getRefused()
public long getUsers()
public boolean isDeadlockDetected()
true
if a deadlock is detected, false
otherwise.true
if a deadlock is detected,
false
otherwise.public boolean provide(int n) throws SuspendExecution
deliver()
. As not enough resources are available at the
moment the SimProcess has to wait in a queue until enough products are
available again.
The order of resource providing (and, thus, process re-activation) depends on the
order of the internal queue, which is based on the processes' queueing
priorities and (if queueing priorities are equal, requiring
a tie-breaker) by FIFO or a different discipline as defined in the
constructor.n
- int : The number of resources the resourcepool will
provide()
to the SimProcess.true
if the specified number of
resources have been provided successfully, false
otherwise (i.e. capacity limit of the queue is reached).SuspendExecution
public void reset()
QueueBased
is
also reset.reset
in class QueueBased
public void setDeadlockDetected(boolean dlDetected)
deadlockDetected
to the given value.
If a deadlock for this Res
is detected when an unsuccessfull
seize statement for a resource has taken place, then the value of
deadlockDetected
will be set to true
. The value
will also been shown in the report of this Res
.dlDetected
- boolean : the new value for the field
deadlockDetected
. Should be true
if
this Res
is involved in a deadlock.public void setPassBy(boolean newPassBy)
newPassBy
- boolean : The new value of passBy. Set it to true
if you want entities to pass by other entities which are
enqueued before them in the queue. Set it to
false
if you don't want entities to overtake
other entities in the queue.public void takeBack(Resource[] returnedRes)
returnResources()
of the class
SimProcess
.returnedRes
- Resource[] : The array of resources a process is returning to
the resource pool. Can't be more resources than it once has
acquired!public void takeBack(int n)
takeBack(Resource[] returnedRes)
in cases that the user does
not want to provide an array of returning resources. This method is also
compatible with older DESMO-J Versions.n
- int : The number of resources which should be returned to the
Res pool. Can't be more than once were acquired!