Java Reference
In-Depth Information
}
catch
(Exception e) { e.printStackTrace(); }
}
// the main method
public static void
main(String[] args) {. . . }
}
public class
MixerController
extends
TankController
implements
Runnable, ControllerInterface {
// interfaces to the tank controller
private
ControllerInterface redController
#
null
;
private
ControllerInterface greenController
#
null
;
private
ControllerInterface blueController
#
null
;
public
MixerController(String simAdd, String redContrAdd,
String greenContrAdd, String blueContrAdd)
throws
RemoteException {
super
("Mixer", simAdd);
try
{
// links the controller to the TankControllers
redController
#
(ControllerInterface)
Naming.lookup
("//"
!
redContrAdd
!
"/RedTankController");
greenController
#
(ControllerInterface)
Naming.lookup
("//"
!
greenContrAdd
!
"/GreenTankController");
blueController
#
(ControllerInterface)
Naming.lookup
("//"
!
blueContrAdd
!
"/BlueTankController");
}
catch
(Exception e) { e.printStackTrace(); }
}
// implements the control logic
public void
run() {
try
{
// initializes the state according to the initial
// paint level
tankLevel
#
tank.getLevel();
if
(tankLevel
##
0) tankState
#
EMPTY;
else if
(tankLevel <
#
MEDIUM) tankState
#
NOTEMPTY;
else if
(tankLevel <
#
MAXIMUM) tankState
#
NOTFULL;
else
tankState
#
FULL;
while
(
true
) {
Thread.sleep(100);
tankLevel
#
tank.getLevel();
// states transitions
if
(tankState.equals(EMPTY) && tankLevel > MINIMUM) {
tankState
#
NOTEMPTY;
}
else if
(tankState.equals(NOTEMPTY)
&& tankLevel > MEDIUM) {