Juvix preamble
module node_architecture.engines.ticker_behaviour;
import node_architecture.engines.ticker_messages open;
import node_architecture.engines.ticker_environment open;
import prelude open;
import node_architecture.types.basics open;
import node_architecture.types.identities open;
import node_architecture.types.messages open;
import node_architecture.types.engine open;
import node_architecture.types.anoma_message open using {MsgTicker};
Ticker Behaviour¶
Overview¶
The Ticker engine maintains a counter as local state and allows two actions: incrementing the counter and sending the current counter value.
Action labels¶
type TickerActionLabel :=
| DoIncrement
| DoRespond;
DoIncrement
¶
DoIncrement
This action label corresponds to incrementing the counter and is relevant for the Increment
message.
DoIncrement
action effect
This action does the following:
Aspect | Description |
---|---|
State update | The counter value is increased by one. |
Messages to be sent | No messages are added to the send queue. |
Engines to be spawned | No engine is created by this action. |
Timer updates | No timers are set or cancelled. |
DoRespond
¶
DoRespond
This action label corresponds to responding with the current counter value and
is relevant for the Count
message.
DoRespond
action effect
This action does the following:
Aspect | Description |
---|---|
State update | The state remains unchanged. |
Messages to be sent | A message with the current counter value is sent to the requester. |
Engines to be spawned | No engine is created by this action. |
Timer updates | No timers are set or cancelled. |
Matchable arguments¶
type TickerMatchableArgument := ReplyTo (Option EngineID) (Option MailboxID);
ReplyTo
¶
ReplyTo (Option EngineID) (Option MailboxID)
This matchable argument contains the address and mailbox ID of where the response message should be sent.
Precomputation results¶
The Ticker engine does not require any non-trivial pre-computations.
syntax alias TickerPrecomputation := Unit;
Guards¶
Auxiliary Juvix code
Type alias for the guard.
TickerGuard : Type :=
Guard
TickerLocalState
TickerTimerHandle
TickerMailboxState
TickerMatchableArgument
TickerActionLabel
TickerPrecomputation;
TickerGuardOutput : Type :=
GuardOutput TickerMatchableArgument TickerActionLabel TickerPrecomputation;
incrementGuard
¶
incrementGuard
(t : TimestampedTrigger TickerTimerHandle)
(env : TickerEnvironment)
: Option TickerGuardOutput :=
case getMessageFromTimestampedTrigger t of
| some (MsgTicker Increment) :=
some
mkGuardOutput@{
args := [];
label := DoIncrement;
other := unit
}
| _ := none;
countGuard
¶
countGuard
(t : TimestampedTrigger TickerTimerHandle)
(env : TickerEnvironment)
: Option TickerGuardOutput :=
case getMessageFromTimestampedTrigger t of
| some (MsgTicker Count) :=
do {
sender <- getSenderFromTimestampedTrigger t;
pure
mkGuardOutput@{
args := [ReplyTo (some sender) none];
label := DoRespond;
other := unit
};
}
| _ := none;
Action function¶
Auxiliary Juvix code
Type alias for the action function.
TickerActionInput : Type :=
ActionInput
TickerLocalState
TickerMailboxState
TickerTimerHandle
TickerMatchableArgument
TickerActionLabel
TickerPrecomputation;
TickerActionEffect : Type :=
ActionEffect
TickerLocalState
TickerMailboxState
TickerTimerHandle
TickerMatchableArgument
TickerActionLabel
TickerPrecomputation;
tickerAction (input : TickerActionInput) : TickerActionEffect :=
let
env := ActionInput.env input;
out := ActionInput.guardOutput input;
in case GuardOutput.label out of
| DoIncrement :=
let
counterValue :=
TickerLocalState.counter (EngineEnvironment.localState env);
in mkActionEffect@{
newEnv :=
env@EngineEnvironment{localState := mkTickerLocalState@{
counter := counterValue + 1
}};
producedMessages := [];
timers := [];
spawnedEngines := []
}
| DoRespond :=
let
counterValue :=
TickerLocalState.counter (EngineEnvironment.localState env);
in case GuardOutput.args out of
| ReplyTo (some whoAsked) mailbox :: _ :=
mkActionEffect@{
newEnv := env;
producedMessages :=
[ mkEngineMessage@{
sender := getSenderFromActionInput input;
target := whoAsked;
mailbox := some 0;
msg := MsgTicker Count
}
];
timers := [];
spawnedEngines := []
}
| _ :=
mkActionEffect@{
newEnv := env;
producedMessages := [];
timers := [];
spawnedEngines := []
};
Conflict solver¶
tickerConflictSolver
: Set TickerMatchableArgument -> List (Set TickerMatchableArgument) :=
\ {_ := []};
Engine behaviour¶
TickerBehaviour
¶
<pre class="highlight"><code class="juvix"><pre class="src-content"><span id="node_architecture.engines.ticker:1"><span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker.html#node_architecture.engines.ticker:1" class="ju-code-link ju-function"><span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker.html#node_architecture.engines.ticker:1" class="ju-code-link ju-function"><span class="ju-function">TickerBehaviour</span></a></span></a></span></span><br/> <span class="ju-keyword">:</span> <span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/types/engine.html#node_architecture.types.engine:1" class="ju-code-link ju-inductive"><span class="ju-inductive">EngineBehaviour</span></a></span><br/> <span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker_environment.html#node_architecture.engines.ticker_environment:2" class="ju-code-link ju-inductive"><span class="ju-inductive">TickerLocalState</span></a></span><br/> <span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker_environment.html#node_architecture.engines.ticker_environment:1" class="ju-code-link ju-var"><span class="ju-inductive">TickerMailboxState</span></a></span><br/> <span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker_environment.html#node_architecture.engines.ticker_environment:4" class="ju-code-link ju-var"><span class="ju-inductive">TickerTimerHandle</span></a></span><br/> <span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker_behaviour.html#node_architecture.engines.ticker_behaviour:4" class="ju-code-link ju-inductive"><span class="ju-inductive">TickerMatchableArgument</span></a></span><br/> <span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker_behaviour.html#node_architecture.engines.ticker_behaviour:1" class="ju-code-link ju-inductive"><span class="ju-inductive">TickerActionLabel</span></a></span><br/> <span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker_behaviour.html#node_architecture.engines.ticker_behaviour:6" class="ju-code-link ju-var"><span class="ju-inductive">TickerPrecomputation</span></a></span> <span class="ju-keyword">:=</span><br/> <span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/types/engine.html#node_architecture.types.engine:2" class="ju-code-link ju-constructor"><span class="ju-constructor">mkEngineBehaviour</span></a></span><span class="ju-keyword">@</span><span class="ju-delimiter">{</span><br/> <span id="node_architecture.engines.ticker:2"><span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker.html#node_architecture.engines.ticker:2" class="ju-code-link ju-function"><span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker.html#node_architecture.engines.ticker:2" class="ju-code-link ju-function"><span class="ju-function">guards</span></a></span></a></span></span> <span class="ju-keyword">:=</span> <span class="ju-keyword">[</span><span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker_behaviour.html#node_architecture.engines.ticker_behaviour:11" class="ju-code-link ju-function"><span class="ju-function">incrementGuard</span></a></span><span class="ju-delimiter">;</span> <span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker_behaviour.html#node_architecture.engines.ticker_behaviour:12" class="ju-code-link ju-function"><span class="ju-function">countGuard</span></a></span><span class="ju-keyword">]</span><span class="ju-delimiter">;</span><br/> <span id="node_architecture.engines.ticker:3"><span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker.html#node_architecture.engines.ticker:3" class="ju-code-link ju-function"><span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker.html#node_architecture.engines.ticker:3" class="ju-code-link ju-function"><span class="ju-function">action</span></a></span></a></span></span> <span class="ju-keyword">:=</span> <span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker_behaviour.html#node_architecture.engines.ticker_behaviour:15" class="ju-code-link ju-function"><span class="ju-function">tickerAction</span></a></span><span class="ju-delimiter">;</span><br/> <span id="node_architecture.engines.ticker:4"><span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker.html#node_architecture.engines.ticker:4" class="ju-code-link ju-function"><span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker.html#node_architecture.engines.ticker:4" class="ju-code-link ju-function"><span class="ju-function">conflictSolver</span></a></span></a></span></span> <span class="ju-keyword">:=</span> <span class="annot"><a href="https://anoma.github.io/nspec/v2/node_architecture/engines/ticker_behaviour.html#node_architecture.engines.ticker_behaviour:16" class="ju-code-link ju-function"><span class="ju-function">tickerConflictSolver</span></a></span><br/> <span class="ju-delimiter">}</span><span class="ju-delimiter">;</span></pre></code></pre>