Class TrafficMessageReceiver

java.lang.Object
eu.bandm.tools.message.TrafficMessageReceiver
All Implemented Interfaces:
MessageReceiver<Message>

public class TrafficMessageReceiver extends Object implements MessageReceiver<Message>
Graphic indication of received messages.

One or more 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!).
As long as no message arrives, the intial state is left unchanged.
  • Constructor Details

    • TrafficMessageReceiver

      public TrafficMessageReceiver()
  • Method Details

    • addLight

      public void addLight(TrafficLight light)
      Adds light as a listener to state changes.
    • removeLight

      public void removeLight(TrafficLight light)
      Removes light as a listener to state changes.
    • createLight

      public TrafficLight createLight()
      Convenience: constructs a new TrafficLight and adds it.
    • clear

      public void clear()
      Convenience: set state of all currently added traffic lights to "green".
    • receive

      public void receive(Message msg)
      Sets state to TrafficLight.State.red if the received message is critcal, otherwise to yellow, if it is not already red.
      Specified by:
      receive in interface MessageReceiver<Message>
      See Also:
    • getState

      public TrafficLight.State getState()
      Return the current state.
    • setState

      protected void setState(TrafficLight.State state)
      Convenience: set state of all currently added traffic lights to state.