public class TrafficMessageReceiver extends Object implements MessageReceiver<Message>
TrafficLight
objects can be linked to this kind of
message receiver.
The state of all these is changed to "red" as soon as a critical
message arrives, and to "yellow" as soon as any other message arrives
(provided the state is not red!).
Constructor and Description |
---|
TrafficMessageReceiver() |
Modifier and Type | Method and Description |
---|---|
void |
addLight(TrafficLight light)
Adds
light as a target to state changes. |
void |
clear()
Convenience: set state of all currently added traffic lights to "green".
|
TrafficLight |
createLight()
Convenience: constructs a new
TrafficLight
and adds it. |
TrafficLight.State |
getState() |
void |
receive(Message msg) |
void |
removeLight(TrafficLight light)
Removes
light as a target to state changes. |
protected void |
setState(TrafficLight.State state)
Convenience: set state of all currently added traffic lights to
state . |
public void addLight(TrafficLight light)
light
as a target to state changes.public void removeLight(TrafficLight light)
light
as a target to state changes.public TrafficLight createLight()
TrafficLight
and adds
it.public void clear()
public void receive(Message msg)
receive
in interface MessageReceiver<Message>
public TrafficLight.State getState()
protected void setState(TrafficLight.State state)
state
.see also the complete user documentation .