Java Reference
In-Depth Information
PieceSource : nutsS
PieceSource : screwS
Runnable
Machine : drill
DiscreteClock
DiscreteProcess
Machine : cutter
Transport : agv
WorkCellGUI
WorkCell
main()
Assembler : ass
PieceSink : boltsS
Figure 9.12
The relationships between the work cell simulator and the graphical
user interface
package
workcell;
public class
PieceSource
extends
DiscreteProcess {
int
numPieces
#
0;
// the total number of loaded pieces
String pieceType;
// type of piece (nut or screw)
double
maxRate;
// maximum number of pieces per minute
boolean
working
#
true
;
// true if it is generating new pieces
public
PieceSource(String name, String type,
DiscreteClock clock,
double
rate) {
super
(name, clock);
this
.pieceType
#
type;
this
.maxRate
#
rate/60000;
// the rate is expressed in milliseconds
attachTo("LOADED",
this
);
// it listens to its LOADED event
long
lifetime
#
Math.round( (1.0
!
0.5*Math.random()) /
maxRate);
// activates the first event
activateEvent("LOADED", lifetime, pieceType);
}