|
SSJ V. 2.6. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object umontreal.iro.lecuyer.simprocs.Resource
public class Resource
Objects of this class are resources having limited capacity,
and which can be requested and released by Process
objects.
These resources act indirectly as synchonization devices for
processes.
A resource is created with a finite capacity, specified when
invoking the Resource
constructor, and can be changed
later on. A resource also has an infinite-capacity queue
(waiting line) and a service policy that defaults to FIFO and
can be changed later on.
A process must ask for a certain number of units of the resource
(request
), and obtain it before using it.
When it is done with the resource, the process must release
it so that others can use it (release
).
A process does not have to request [release] all the resource
units that it needs by a single call to the request
[release
] method. It can make several successive requests
or releases, and can also hold different resources simultaneously.
Each resource maintains two lists: one contains the processes
waiting for the resource (the waiting queue) and the other contains
the processes currently holding units of this resource.
The methods waitList
and servList
permit one to
access these two lists.
These lists actually contain objects of the class UserRecord
instead of SimProcess
objects.
Constructor Summary | |
---|---|
Resource(int capacity)
Constructs a new resource linked with the default simulator, with initial capacity capacity, and service policy FIFO. |
|
Resource(int capacity,
String name)
Constructs a new resource linked with the default simulator, with initial capacity capacity, service policy FIFO, and identifier name. |
|
Resource(ProcessSimulator sim,
int capacity)
Constructs a new resource linked with the simulator sim, with initial capacity capacity, and service policy FIFO. |
|
Resource(ProcessSimulator sim,
int capacity,
String name)
Constructs a new resource linked with the simulator sim, with initial capacity capacity, service policy FIFO, and identifier (or name) name. |
Method Summary | |
---|---|
void |
changeCapacity(int diff)
Modifies by diff units (increases if diff > 0, decreases if diff < 0) the capacity (i.e., the number of units) of the resource. |
int |
getAvailable()
Returns the number of available units, i.e., the capacity minus the number of units busy. |
int |
getCapacity()
Returns the current capacity of the resource. |
String |
getName()
Returns the name (or identifier) associated to this resource. |
void |
init()
Reinitializes this resource by clearing up its waiting list and service list. |
void |
initStat()
Reinitializes all the statistical collectors for this resource. |
void |
release(int n)
The executing process that invokes this method releases n units of the resource. |
String |
report()
Returns a string containing a complete statistical report on this resource. |
void |
request(int n)
The executing process invoking this method requests for n units of this resource. |
LinkedListStat |
servList()
Returns the list that contains the UserRecord objects
for the processes in the service list for this resource. |
void |
setCapacity(int newcap)
Sets the capacity to newcap. |
void |
setPolicyFIFO()
Set the service policy to FIFO (first in, first out): the processes are placed in the list (and served) according to their order of arrival. |
void |
setPolicyLIFO()
Set the service policy to LIFO (last in, first out): the processes are placed in the list (and served) according to their inverse order of arrival, the last arrived are served first. |
void |
setStatCollecting(boolean b)
Starts or stops collecting statistics on the lists returned by waitList and servList for this resource. |
Accumulate |
statOnCapacity()
Returns the statistical collector that measures the evolution of the capacity of the resource as a function of time. |
Tally |
statOnSojourn()
Returns the statistical collector for the sojourn times of the UserRecord for this resource. |
Accumulate |
statOnUtil()
Returns the statistical collector for the utilization of the resource (number of units busy) as a function of time. |
LinkedListStat |
waitList()
Returns the list that contains the UserRecord objects
for the processes in the waiting list for this resource. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Resource(int capacity)
capacity
- initial capacity of the resourcepublic Resource(ProcessSimulator sim, int capacity)
sim
- current simulator of the variablecapacity
- initial capacity of the resourcepublic Resource(int capacity, String name)
capacity
- initial capacity of the resourcename
- identifier or name of the resourcepublic Resource(ProcessSimulator sim, int capacity, String name)
sim
- current simulator of the variablecapacity
- initial capacity of the resourcename
- identifier or name of the resourceMethod Detail |
---|
public void setStatCollecting(boolean b)
waitList
and servList
for this resource.
If the statistical collection is turned ON, the method
also constructs (if not yet done)
and initializes three additional statistical
collectors for this resource. These collectors will be updated
automatically. They can be accessed via statOnCapacity
,
statOnUtil
, and statOnSojourn
, respectively.
The first two, of class
Accumulate
,
monitor the evolution of the
capacity and of the utilization (number of units busy) of the resource
as a function of time.
The third one, of class Tally
,
collects statistics on the
processes sojourn times (wait + service); it samples a new value
each time a process releases all the units of this resource that it
holds (i.e., when its UserRecord
disappears).
b
- true to turn statistical collecting ON, false to turn it OFFpublic void initStat()
setStatCollecting
(true) must have been invoked earlier for
this resource.
public void init()
initStat
is invoked as well.
public int getCapacity()
public void setPolicyFIFO()
public void setPolicyLIFO()
public void changeCapacity(int diff)
diff
- number of capacity units to add to the actual capacity,
can be negative to reduce the capacity
IllegalArgumentException
- if diff is negative and
the capacity cannot be reduced as required
IllegalStateException
- if diff is negative and
the capacity could not be reduced due to a lack of available unitspublic void setCapacity(int newcap)
changeCapacity
(newcap - old) if old is the
current capacity.
newcap
- new capacity of the resource
IllegalArgumentException
- if the passed capacity is negative
IllegalStateException
- if diff is negative and
the capacity could not be reduced due to a lack of available unitspublic int getAvailable()
public void request(int n)
release
for this same resource. The process is also inserted into the
servList
list for this resource.
On the other hand, if there are less than n units of this
resource available, the executing process is placed into the
waitList
list (the queue) for this resource and is suspended
until it can obtain the requested number of units of the resource.
n
- number of required unitspublic void release(int n)
UserRecord
object disappears.
If this process is holding less than n units,
the program throws an illegal argument exception.
If there are other processes waiting for this resource whose requests
can now be satisfied, they obtain the resource.
n
- number of released units
IllegalArgumentException
- if the process did not request n
units before releasing thempublic LinkedListStat waitList()
UserRecord
objects
for the processes in the waiting list for this resource.
public LinkedListStat servList()
UserRecord
objects
for the processes in the service list for this resource.
public Accumulate statOnCapacity()
setStatCollecting
(true) has been invoked
previously.
public Accumulate statOnUtil()
setStatCollecting
(true)
has been invoked previously.
The utilization rate of a resource can be obtained as the
time average computed by this collector, divided by the
capacity of the resource.
The collector returned by servList()
.statSize()
tracks the number of UserRecord
in the service list;
it differs from this collector because a process may hold more than one
unit of the resource by given UserRecord
.
public Tally statOnSojourn()
UserRecord
for this resource.
This collector exists only if setStatCollecting
(true) has been invoked
previously.
It gets a new observation each time a process releases all the units
of this resource that it had requested by a single request
call.
public String getName()
public String report()
setStatCollecting
(true) must have been invoked
previously, otherwise no statistics have been collected.
The report contains statistics on the waiting times, service
times, and waiting times for this resource, on the capacity,
number of units busy, and size of the queue as a function of time,
and on the utilization rate.
|
SSJ V. 2.6. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |