Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

desmoj
Class Res  view Res download Res.java

java.lang.Object
  extended bydesmoj.NamedObject
      extended bydesmoj.ModelComponent
          extended bydesmoj.Reportable
              extended bydesmoj.QueueBased
                  extended bydesmoj.Res

public class Res
extends QueueBased

Res is the place where resources are stored in a pool. Processes can come by and the resource pool will 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 criteria of the queue is always highest priorities first, the second queueing discipline of the underlying queue and the capacity limit can be determined by the user (default is Fifo and unlimited capacity). Under certain circumstances a deadlock might block some waiting entities. Be aware of this fact when using the Res.

Version:
DESMO-J, Ver. 1.5 copyright (c) 2001 licensed under GNU GPL

Nested Class Summary
(package private)  class Res.UsedResources
          UsedResources is an inner class of Res to encapsulate the pairs of: SimProcess and an array of resources it holds.
 
Field Summary
private  java.util.Vector arrayOfUsedResources
          The vector holding all the pairs (used resources of this Res, the SimProcess which holds the resources at the moment).
private  int avail
          Number of resources available at the moment
private  boolean deadlockCheck
          To indicate whether the check for deadlocks is active or not.
private  boolean deadlockDetected
          Is set to true if a deadlock is detected where this Res is involved in.
private  long idNumber
          The ID number of this Res object.
private  SimTime lastUsage
          The last time the Res has been used
private  int limit
          The number of resources in the Res (capacity)
private  int minimum
          The minimum number of resources being available
private  boolean passBy
          Flag to indicate whether an entity can pass by other entities in the queue which are enqueued before that entity in the queue.
private  QueueList queue
          The queue, actually storing the processes waiting for resources
private  long refused
          Counter for the SimProcesses which are refused to be enqueued, because the queue capacity is full.
private static long resNumber
          The number identifying a Res object.
private  ResourceDB resourceDB
          The resource database keeping track of which SimProcesses holding which resources and SimPorcesses requesting resources.
private  java.util.Vector unUsedResources
          The vector holding all the resources of this resource pool not used at the moment.
private  long users
          Number of processes having acquired and released one or more resources
private  java.lang.String where
          Indicates the method where something has gone wrong.
private  double wSumAvail
          Weighted sum of available resources (in the Res over the time)
 
Fields inherited from class desmoj.QueueBased
FIFO, LIFO, queueingStrategy, queueLimit, UNDEFINED
 
Fields inherited from class desmoj.Reportable
 
Fields inherited from class desmoj.ModelComponent
 
Fields inherited from class desmoj.NamedObject
 
Constructor Summary
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.
 
Method Summary
protected  void activateAsNext(SimProcess process)
          Activates the SimProcess process, given as a parameter of this method, as the next process.
protected  void activateFirst()
          Activates the first process waiting in the queue.
 double avgUsage()
          Returns the average usage of the Res.
 void changeLimit(int m)
          Changes the limit of the available resources in the Res.
protected  boolean checkProcess(SimProcess p, java.lang.String where)
          Checks whether the process using the Res is a valid process.
 desmoj.report.Reporter createReporter()
          Returns a Reporter to produce a report about this Res.
 void deadlockCheckOff()
          Turns the deadlock check off.
 void deadlockCheckOn()
          Turns the deadlock check on.
private  Resource[] deliver(int n)
          Takes a number of n resources from the Res pool and delivers this array of resources to the Simprocess to use them.
 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.
protected  QueueList 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.
protected  int heldResources(SimProcess sProc)
          Returns the number of resources held by the given SimProcess at this time.
 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 SimProcess to use them.
 void reset()
          Resets the statistics of this Res.
protected  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.
protected  void updateProvidedRes(SimProcess crntProcess, Resource[] providedRes)
          Updates the arrayOfUsedResources for this Res whenever resources are provided.
protected  void updateStatistics(int n)
          Updates the statistics for the Res whenever resources are provided or "takenBack".
protected  void updateTakenBackRes(SimProcess crntProcess, Resource[] returnedRes)
          Updates the arrayOfUsedResources for this Res whenever resources are taken back.
 
Methods inherited from class desmoj.QueueBased
addItem, averageLength, averageWaitTime, deleteItem, getQueueLimit, length, maxLength, maxLengthAt, maxWaitTime, maxWaitTimeAt, minLength, minLengthAt, qImpWarn, setQueueImpWarning, stdDevLength, stdDevWaitTime, updateStatistics, zeroWaits
 
Methods inherited from class desmoj.Reportable
getObservations, incrementObservations, incrementObservations, reportIsOn, reportOff, reportOn, resetAt
 
Methods inherited from class desmoj.ModelComponent
current, currentEntity, currentEvent, currentModel, currentSimProcess, currentTime, debugIsOn, debugOff, debugOn, epsilon, getModel, isExperimentCompatible, isModelCompatible, sendDebugNote, sendMessage, sendTraceNote, sendWarning, setOwner, skipTraceNote, skipTraceNote, traceIsOn, traceOff, traceOn
 
Methods inherited from class desmoj.NamedObject
getName, getQuotedName, rename, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

resNumber

private static long resNumber
The number identifying a Res object. Because it is a class variable each Res will get its own ID number starting by zero.


idNumber

private long idNumber
The ID number of this Res object.


queue

private QueueList queue
The queue, actually storing the processes waiting for resources


arrayOfUsedResources

private java.util.Vector arrayOfUsedResources
The vector holding all the pairs (used resources of this Res, the SimProcess which holds the resources at the moment). See: inner class UsedResources


unUsedResources

private java.util.Vector unUsedResources
The vector holding all the resources of this resource pool not used at the moment.


resourceDB

private ResourceDB resourceDB
The resource database keeping track of which SimProcesses holding which resources and SimPorcesses requesting resources.


deadlockCheck

private boolean deadlockCheck
To indicate whether the check for deadlocks is active or not. Default is true = deadlock check enabled.


deadlockDetected

private boolean deadlockDetected
Is set to true if a deadlock is detected where this Res is involved in. Otherwise it remains false. Default is false.


limit

private int limit
The number of resources in the Res (capacity)


minimum

private int minimum
The minimum number of resources being available


avail

private int avail
Number of resources available at the moment


users

private long users
Number of processes having acquired and released one or more resources


wSumAvail

private double wSumAvail
Weighted sum of available resources (in the Res over the time)


lastUsage

private SimTime lastUsage
The last time the Res has been used


refused

private long refused
Counter for the SimProcesses which are refused to be enqueued, because the queue capacity is full.


where

private java.lang.String where
Indicates the method where something has gone wrong. Is passed as a parameter to the method checkProcess().


passBy

private boolean passBy
Flag to indicate whether an entity can pass by other entities in the queue which are enqueued before that entity in the queue. Is false as default value.

Constructor Detail

Res

public 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. The queueing discipline and the capacity limit of the underlying queue can be chosen, too.


Res

public 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. The underlying queue has a Fifo queueing discipline and unlimited capacity.

Method Detail

activateAsNext

protected void activateAsNext(SimProcess process)
Activates the SimProcess process, given as a parameter of this method, as the next process. This process should be a SimProcess waiting in the queue for some resources.


activateFirst

protected void activateFirst()
Activates the first process waiting in the queue. That is a process which was trying to acquire resources, but there were not enough left in the Res. Or another process was first in the queue to be served. This method is called every time a process returns resources or when a process in the waiting queue is satisfied.


avgUsage

public double avgUsage()
Returns the average usage of the Res. That means: in average, which percentage of the resources were in use over the time?


changeLimit

public void changeLimit(int m)
Changes the limit of the available resources in the Res. Sets the number of the maximum available resources to m. m must be positive. This is only allowed as long as the Res has not been used or the Res has just been reset.


checkProcess

protected boolean checkProcess(SimProcess p,
                               java.lang.String where)
Checks whether the process using the Res is a valid process.


createReporter

public desmoj.report.Reporter createReporter()
Returns a Reporter to produce a report about this Res.

Specified by:
createReporter in class QueueBased

deadlockCheckOff

public void deadlockCheckOff()
Turns the deadlock check off. So whenever a SimProcess can not get the resources desired, there won't be checked if a deadlock situation might have occured.


deadlockCheckOn

public void deadlockCheckOn()
Turns the deadlock check on. So whenever a SimProcess can not get the resources desired, it will be checked if a deadlock situation might occur.


deliver

private Resource[] deliver(int n)
Takes a number of n resources from the Res pool and delivers this array of resources to the Simprocess to use them. Is called from the method provide (int n).


getAvail

public int getAvail()
Returns the number of resources available in the pool at the moment.


getDeadlockCheck

public boolean getDeadlockCheck()
Returns if the deadlock check is enabled (true) or not (false).


getidNumber

public long getidNumber()
Returns the ID number of this Res object.


getLimit

public int getLimit()
Returns the initial number of resources in the Res pool.


getMinimum

public int getMinimum()
Returns the minimum number of resources in the Res.


getPassBy

public boolean getPassBy()
Returns whether entities can pass by other entities which are enqueued before them in the queue.


getQueue

protected QueueList getQueue()
Returns the QueueList actually storing the SimProcesses waiting for resources.


getQueueStrategy

public java.lang.String getQueueStrategy()
Returns the implemented queueing discipline of the underlying queue as a String, so it can be displayed in the report.


getRefused

public long getRefused()
Returns the number of entities refused to be enqueued in the queue, because the capacity limit is reached.


getUsers

public long getUsers()
Returns the number of users.


heldResources

protected int heldResources(SimProcess sProc)
Returns the number of resources held by the given SimProcess at this time.


isDeadlockDetected

public boolean isDeadlockDetected()
Returns true if a deadlock is detected, false otherwise.


provide

public boolean provide(int n)
Gets a number of n resources from the Res pool and provides them to the SimProcess to use them. Hint for developers: calls the private method deliver(). As not enough resources are available at the moment the SimProcess has to wait in a queue until enough products are available again.


reset

public void reset()
Resets the statistics of this Res. The number of available resources at this moment and the processes waiting in the queue are not changed. But all statistic counters are reset. The parent QueueBased is also reset.

Overrides:
reset in class QueueBased

setDeadlockDetected

protected void setDeadlockDetected(boolean dlDetected)
Sets the boolean field 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.


setPassBy

public void setPassBy(boolean newPassBy)
Sets the flag passBy to a new value. PassBy is indicating whether entities can pass by other entities which are enqueued before them in the queue.


takeBack

public void takeBack(Resource[] returnedRes)
A process is using this method to put resources it has used back in the Res pool. The process can not put more resources back than it has acquired once. The array of returning resources can be provided by the method returnResources() of the class SimProcess.


takeBack

public void takeBack(int n)
A process is using this method to put resources it has used back in the Res pool. The process can not put more resources back than it has acquired once. This method can be used as an alternative to the method 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.


updateProvidedRes

protected void updateProvidedRes(SimProcess crntProcess,
                                 Resource[] providedRes)
Updates the arrayOfUsedResources for this Res whenever resources are provided.


updateStatistics

protected void updateStatistics(int n)
Updates the statistics for the Res whenever resources are provided or "takenBack".


updateTakenBackRes

protected void updateTakenBackRes(SimProcess crntProcess,
                                  Resource[] returnedRes)
Updates the arrayOfUsedResources for this Res whenever resources are taken back.