umontreal.iro.lecuyer.simprocs
Class Bin
- java.lang.Object
-
- umontreal.iro.lecuyer.simprocs.Bin
-
public class Bin extends java.lang.ObjectA 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 methodput. A process can request tokens from the pile (i.e., consume) by callingtake.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 methodwaitList. This list actually contains objects of the classUserRecord. EachUserRecordpoints to a process and contains some additional information.
-
-
Constructor Summary
Constructors Constructor and Description 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, java.lang.String name)Constructs a new bin, initially empty, with service policy FIFO, identifier name and linked with simulator sim.Bin(java.lang.String name)Constructs a new bin, initially empty, with service policy FIFO, identifier name and linked with the default simulator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description intgetAvailable()Returns the number of available tokens for this bin.voidinit()Reinitializes this bin by clearing up its pile of tokens and its waiting list.voidinitStat()Reinitializes all the statistical collectors for this bin.voidput(int n)Adds n tokens to this bin.java.lang.Stringreport()Returns a string containing a complete statistical report on this bin.voidsetPolicyFIFO()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.voidsetPolicyLIFO()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.voidsetSimulator(ProcessSimulator sim)Set the current simulator of this continuous-time variable.voidsetStatCollecting(boolean b)Starts or stops collecting statistics on the list returned bywaitListfor this bin.Simulatorsimulator()Returns the current simulator of this continuous-time variable.AccumulatestatOnAvail()Returns the statistical collector for the available tokens on the bin as a function of time.voidtake(int n)The executing process invoking this method requests n tokens from this bin.LinkedListStatwaitList()Returns the list ofUserRecordfor the processes waiting for tokens from this bin.
-
-
-
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(java.lang.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, java.lang.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 bywaitListfor this bin. If the statistical collection is turned ON, It also constructs (if not yet done) and initializes an additional statistical collector of classAccumulatefor this bin. This collector will be updated automatically. It can be accessed viastatOnAvail, 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 thewaitListlist (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 ofUserRecordfor 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 ifsetStatCollecting(true) has been invoked previously.- Returns:
- the probe for available tokens
-
report
public java.lang.String report()
Returns a string containing a complete statistical report on this bin. The methodsetStatCollecting(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 must not be called while a simulator is running.- Parameters:
sim- the simulator of the current variable
-
-
DMelt 3.0 © DataMelt by jWork.ORG