SSJ
V. 1.2.5.

umontreal.iro.lecuyer.simprocs
Class Bin

java.lang.Object
  extended by umontreal.iro.lecuyer.simprocs.Bin

public class Bin
extends Object

A Bin corresponds to a pile of identical tokens, and a list of processes waiting for the tokens when the list is empty. It is a producer/consumer process synchronization device. Tokens can be added to the pile (i.e., produced) by the method put. A process can request tokens from the pile (i.e., consume) by calling take.

The behavior of a Bin is somewhat similar to that of a Resource. Each Bin has a single queue of waiting processes, with FIFO or LIFO service policy, and which can be accessed via the method waitList. This list actually contains objects of the class UserRecord. Each UserRecord points to a process and contains some additional information.


Constructor Summary
Bin()
          Constructs a new bin, initially empty, with service policy FIFO.
Bin(String name)
          Constructs a new bin, initially empty, with service policy FIFO and identifier name.
 
Method Summary
 int getAvailable()
          Returns the number of available tokens for this bin.
 void init()
          Reinitializes this bin by clearing up its pile of tokens and its waiting list.
 void initStat()
          Reinitializes all the statistical collectors for this bin.
 void put(int n)
          Adds n tokens to this bin.
 String report()
          Returns a string containing a complete statistical report on this bin.
 void setPolicyFIFO()
          Sets the service policy for ordering processes waiting for tokens on the bin to FIFO (first in, first out): the processes are placed in the list (and served) according to their order of arrival.
 void setPolicyLIFO()
          Sets the service policy for ordering processes waiting for tokens on the bin 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 list returned by waitList for this bin.
 Accumulate statOnAvail()
          Returns the statistical collector for the available tokens on the bin as a function of time.
 void take(int n)
          The executing process invoking this method requests n tokens from this bin.
 LinkedListStat waitList()
          Returns the list of UserRecord for the processes waiting for tokens from this bin.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Bin

public Bin()
Constructs a new bin, initially empty, with service policy FIFO.


Bin

public Bin(String name)
Constructs a new bin, initially empty, with service policy FIFO and identifier name.

Parameters:
name - name associated to the bin
Method Detail

init

public void init()
Reinitializes this bin by clearing up its pile of tokens and its waiting list. The processes in this list (if any) remain in the same states.


setStatCollecting

public void setStatCollecting(boolean b)
Starts or stops collecting statistics on the list returned by waitList for this bin. If the statistical collection is turned ON, It also constructs (if not yet done) and initializes an additional statistical collector of class Accumulate for this bin. This collector will be updated automatically. It can be accessed via statOnAvail, and monitors the evolution of the available tokens of the bin as a function of time.

Parameters:
b - true to turn statistical collection ON, false to turn it OFF

initStat

public void initStat()
Reinitializes all the statistical collectors for this bin. These collectors must exist, i.e., setStatCollecting (true) must have been invoked earlier for this bin.


setPolicyFIFO

public void setPolicyFIFO()
Sets the service policy for ordering processes waiting for tokens on the bin to FIFO (first in, first out): the processes are placed in the list (and served) according to their order of arrival.


setPolicyLIFO

public void setPolicyLIFO()
Sets the service policy for ordering processes waiting for tokens on the bin 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.


getAvailable

public int getAvailable()
Returns the number of available tokens for this bin.

Returns:
the number of available tokens

take

public void take(int n)
The executing process invoking this method requests n tokens from this bin. If enough tokens are available, the number of tokens in the bin is reduced by n and the process continues its execution. Otherwise, the executing process is placed into the waitList list (the queue) for this bin and is suspended until it can obtain the requested number of tokens.

Parameters:
n - number of requested tokens

put

public void put(int n)
Adds n tokens to this bin. If there are processes waiting for tokens from this bin and whose requests can now be satisfied, they obtain the tokens and resume their execution.

Parameters:
n - number of tokens to put into the bin

waitList

public LinkedListStat waitList()
Returns the list of UserRecord for the processes waiting for tokens from this bin.

Returns:
the list of waiting process user records

statOnAvail

public Accumulate statOnAvail()
Returns the statistical collector for the available tokens on the bin as a function of time. This collector exists only if setStatCollecting (true) has been invoked previously.

Returns:
the probe for available tokens

report

public String report()
Returns a string containing a complete statistical report on this bin. The method
setStatCollecting (true) must have been invoked previously, otherwise no statistics will have been collected. The report contains statistics on the available tokens, queue size and waiting time for this bin.

Returns:
a statistical report for this bin, represented as a string

SSJ
V. 1.2.5.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.