Java Reference
In-Depth Information
boolean working # false ;
// true when the machine is working
boolean inputFull # false ;
// true when the input buffer is full
boolean outputFull # false ;
// true when the output buffer is full
public Machine(String name, DiscreteClock clock,
double rate, int in, int out) {
super (name, clock);
this .maxRate # rate / 60000;
this .inputSize # in;
this .outputSize # out;
attachTo("WORKDONE", this );
}
protected void notifyEvent(DiscreteEvent event) {
if (event.name.equals("LOADED")) {
// a raw piece has been loaded in the input buffer
inputBuffer.add(event);
// if the machine is not working and the output buffer
// is not full it starts a new manufacturing operation
if (! working && ! outputFull) {
// extracts a raw piece from the input buffer and
// starts an operation
inputBuffer.remove(0);
working # true ;
// the WORKDONE event will notify the completion of
// this operation
long processingTime # Math.round( (1.0 !
0.5 * Math.random()) / maxRate);
this .activateEvent("WORKDONE", processingTime,
this .name);
}
if (inputBuffer.size() ## inputSize-1) {
// The machine notifies that the input buffer is
// full when only one position remains available.
// In fact, it might happen that the piece
// source has already activated a new LOADED event
// and we do not want to disable it.
inputFull # true ;
activateEvent("FULL", 0, null );
}
}
else if (event.name.equals("WORKDONE")) {
// the current operation has been completed
// it drops the piece in the output buffer
outputBuffer.add(event);
Search WWH ::




Custom Search