Overview | Package | Class | Tree | Deprecated | Index | Help
| SSJ V. 2.1.1.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## umontreal.iro.lecuyer.simprocs
Class Bin

    java.lang.Object
      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 and linked with the default simulator.
`Bin(ProcessSimulator sim)` Constructs a new bin, initially empty, with service policy FIFO and linked with simulator sim.
`Bin(ProcessSimulator sim, String name)` Constructs a new bin, initially empty, with service policy FIFO, identifier `name` and linked with simulator sim.
`Bin(String name)` Constructs a new bin, initially empty, with service policy FIFO, identifier `name` and linked with the default simulator.

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` | `setSimulator(ProcessSimulator sim)` Set the current simulator of this continuous-time variable.
`void` | `setStatCollecting(boolean b)` Starts or stops collecting statistics on the list returned by `waitList` for this bin.
`Simulator` | `simulator()` Returns the current simulator of this continuous-time variable.
`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 and linked with the default simulator.

### Bin

    public Bin(ProcessSimulator sim)

  Constructs a new bin, initially empty, with service policy FIFO and linked with simulator sim.

  Parameters:
    `sim` - Simulator associated to the current variable.

### Bin

    public Bin(String name)

  Constructs a new bin, initially empty, with service policy FIFO, identifier `name` and linked with the default simulator.

  Parameters:
    `name` - name associated to the bin

### Bin

    public Bin(ProcessSimulator sim,
               String name)

  Constructs a new bin, initially empty, with service policy FIFO, identifier `name` and linked with simulator sim.

  Parameters:
    `sim` - Simulator associated to the current variable.
    `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

### simulator

    public Simulator simulator()

  Returns the current simulator of this continuous-time variable.

  Returns:
    the current simulator of the variable

### setSimulator

    public void setSimulator(ProcessSimulator sim)

  Set the current simulator of this continuous-time variable. This method musn't be called while simulator's running.

  Parameters:
    `sim` - the simulator of the current variable

Overview | Package | Class | Tree | Deprecated | Index | Help
| SSJ V. 2.1.1.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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