WHEN clause
The when clause (later also referred to as WHEN (s)) allows
an object to
respond to unsolicited state changes of other objects.
There are two kinds of WHENs. The first kind are those that are declared
following the declaration of state (sometime referred to as
'state WHENs')
and the second kind are those specified within WAIT_FOR instruction
( sometime referred to as WF WHENs,
see here). Both of these kinds are
enabling an object to respond to unsolicited state
changes of other objects
and they even have the same syntax. However,
there are some differences between them.
In this section we will be talking only about 'state WHENs', but will be
referring to them simply as WHENs.
The WHEN(s) is(are) declared immediately following the declaration of state. The WHEN is relevant only to the state in which it is declared. Roughly speaking, while the object is in this state and one or more of the conditions in declared WHENs become true, the object initiates execution of the response specified in the first WHEN whose condition is true. See below for more details of When Handling.
Syntax
when
where
- do
action-name
or
- move_to
state-name
or
- stay_in_state
NB:
Example
Let's have a hypothetical scenario: We have an object called RUN and one of it's states is called RUNNING. When the object RUN is in this state, it is important to make sure that none of the objects in object set SUBSYSTEMS goes to state ERROR. We can achieve this by declaring a when clause in state RUNNING (see below). It's effect will be that as soon as any of the objects in object set SUBSYSTEMS goes to ERROR, the action RECOVER will be scheduled for execution. The action will then make sure that a proper recovery is achieved
When Handling
In every state of a SMI object we can declare a number of WHENs (so called WHEN Sequence). Every when is therefore identified by its object, by its state and by the position in the WHEN Sequence. When the object is in one of its possible states, the WHENs declared in this state will respond to events.
Event
As far as WHENs are concerned, events are of two kinds:
- after a transition, an object in the domain reaches one of its states or
- the contents of an object set in the domain changes.
In the following we shall call the object that caused an event
Oev
and in case of object set OSev.
NB: the change of a parameter value is not an event. Therefore,
the type 4 simple condition should be regarded as only
a supplementary condition. It, on its own, will not make
its WHEN to respond to an event.
Client WHEN
A WHEN is called client of Oev or OSev when its object is in
the state where the WHEN was declared and the associated condition
depends on Oev or OSev.
A WHEN is considered to be client of Oev even when this
dependence is only indirect through OSev.
Client Object
An Object is called client object when it is in one of its states and there are client WHENs present.
Every time an Oev event arises, the State Manager (SM) processes
the WHEN Sequence of the object Oev that is declared in
the state which the Oev just reached. In the case of either
Oev or OSev events, the SM then takes the client Objects
one by one and for each it executes the WHEN Sequence
declared in its present state. These WHENs are executed in the order
in which they were declared. The first WHEN, whose condition
evaluates as TRUE, causes its response to be executed and
processing the WHEN Sequence is terminated.
NB: This procedure is in practice more complicated, but for
the purposes of understanding how it works this description
is sufficient.
WHEN processing
An individual WHEN is processed as part of a WHEN Sequence as follows:
- if any of the objects on whose state the WHEN condition depends, is either in transition or has actions waiting, the associated condition is declared to be non-evaluable and therefore the WHEN processing is at the end. In this case the SM will carry on with processing the next WHEN in the WHEN Sequence.
- if the associated condition is evaluable and is FALSE, the WHEN processing is also at the end and SM will behave as above.
-
if the associated condition is evaluable and is TRUE,
the associated response is executed.
In this case the SM also interrupts and terminates processing the WHEN Sequence. This means that even if some of the WHENs following in the Sequence had conditions which would evaluate TRUE, they would not have any effect.