Function Declarations(3.0)

Functions may be declared and called within the APL code using normal Java syntax.

Example - Declaring functions

int addNumbers (int a, int b){
    return a + b;
} consume {
    debug( "1 + 1 = " + addNumbers( 1, 1 ) );
}

To declare functions with no return value, the void keyword should be used.

The Synchronized Keyword

In order to support multi-threading, functions updating global variables within realtime workflows must be made thread-safe. To achieve this, the function name is preceded with the synchronized keyword:

Example - Using the synchronized keyword

synchronized int updateSeqNo(){ 
   seqNo = seqNo +1;
   return seqNo;
}

It is possible to read global variables from any function block. However, to avoid race conditions with functions updating the global variables, they must only be accessed from within synchronized functions.

Note!

The synchronized keyword is ignored when used in batch agents.

To declare functions with no return value, the void keyword is used.