Accessing call graph nodes. Annotations.

This is an advanced topic. In order to understand it, you should read about the Operational model first.

here variable

If you’re working with any script node capable of containing normal Scala code (such as “normal code” {} or “threaded code” {* *}), you can access the current node from the Scala code using the here variable that is available in scope. The current node is the node that contains this code.

Here is an example:

  script live = {println(here)}

This will output something like 4 {} – a string representation of this normal code node.


Annotations allow you to work with the call graph nodes in a general fashion – you can reuse annotations for different nodes. Annotations are unary operators. On their activation, a normal Scala code is executed that has an access to an operand of the annotation, which is a call graph node. Hence, you have a direct access to the operand node before it is activated.

The syntax for the annotation is as follows:

@{normalScalaCode}: annotatedOperand

normalScalaCode is a Scala code that has an access to the annotatedOperand node via there variable that is available in scope.

A simple example of an annotation is the following:

  script live = @{println(there)}: {println("Hello")}

When the annotation node is activated, a string representation of its operand node is printed. A little bit more useful example is the following:

  script live =
      there onActivate   {println(s"$there was activated"  )}
      there onSuccess    {println(s"$there had a success"  )}
      there onDeactivate {println(s"$there was deactivated")}
    }: {println("Hello")}

From the annotation, we register the callbacks within the operand node, so that they notify us of the node activation, success and deactivation.

Leave a Reply