Java Reference
In-Depth Information
Class PieceSink represents the automated inventory system that picks up
bolts from the assembler's output buffer. It extends the DiscreteProcess class
and implements the state transitions triggered by the events UNLOADED ,
EMPTY and NOTEMPTY . The first event is raised by the inventory itself, while
the other two are raised by the assembler. The current state is represented
by the variable working that is true when the inventory is consuming bolts
from the assembler output buffer.
package workcell;
public class PieceSink extends DiscreteProcess {
int numPieces # 0; // the number of pieces unloaded
// from the assembler's buffer
double maxRate; // maximum number of pieces per minute
boolean working # false ; // true if the sink is working
public PieceSink(String name, DiscreteClock clock,
double rate) {
super (name, clock);
this .maxRate # rate / 60000;
attachTo("UNLOADED", this );
}
protected void notifyEvent(DiscreteEvent event) {
if (! working && event.name.equals("NOTEMPTY")) {
// the assembler's output buffer is not empty
working # true ;
// activates the event that notifies the completion
// of an unload operation
long unloadTime # Math.round( (1.0 !
0.5 * Math.random()) / maxRate);
this .activateEvent("UNLOADED", unloadTime, null );
}
else if (working && event.name.equals("UNLOADED")) {
// it has completed an unload operation;
// activates the next UNLOADED event
numPieces !! ;
long unloadTime # Math.round( (1.0 !
0.5 * Math.random()) / maxRate);
this .activateEvent("UNLOADED", unloadTime, null );
}
else if (working && event.name.equals("EMPTY")) {
// the assembler output buffer is empty
// (it contains only one piece)
working # false ;
}
else if (! working && event.name.equals("UNLOADED")) {
// it unloads the last piece from the assembler's
// output buffer
Search WWH ::




Custom Search