Tutorial Pedestrian Lights (Java)

Tutorial Pedestrian Lights (Java)

Scope
Setup the model
Why does it work and why is it safe?

Scope

The scope of this tutorial is to demonstrate how to receive model messages from outside the model. Calling methods which are not part of the model is simple and you have already done this within the blinky tutorial (this is the other way round: model => external code). Receiving events from outside the model is a very common problem and a very frequently asked question. Therefore this tutorial shows how an external event (outside the model) can be received by the model.

This tutorial is not like hello world or blinky. Being familiar with the basic tool features is mandatory for this tutorial. The goal is to understand the mechanism not to learn the tool features.

The idea behind the exercise is, to control a Pedestrian crossing light. We will use the same GUI as for the blinky tutorial but now we will use the REQUEST button to start a FSM, which controls the traffic lights.

The REQUEST must lead to a model message which starts the activity of the lights.

There are several possibilities to receive external events (e.g. TCP/UDP Socket, using OS messaging mechanism), but the easiest way is, to make a port usable from outside the model. To do that a few steps are necessary:

  1. specify the messages (within a protocol) which should be sent into the model

  2. model an actor with a port (which uses the specified protocol) and connect the port to the receiver

  3. the external code should know the port (import of the port class)

  4. the external code should provide a registration method, so that the actor is able to allow access to this port

  5. the port can be used from the external code