Dynamic Functions(3.3)

Dynamic functions enable you to dynamically call an agent, a plug-in, or a generic APL function by name.

dynamicCall

The dynamicCall function calls a user defined APL function.

any dynamicCall ( any  handler ,
                  string  functionName ,
                  list<any>  arguments  )
ParameterDescription

handler

The handler that is returned by dynamicImport, dynamicPlugin or dynamicCompile. If the handler is set to null, the functions that are defined in the agent are used.

functionName

The name of the function to call

arguments

A list of arguments to pass to the called function. To call a function that requires no argument, use either null or an empty list.

Returns

Either the result of the executed function,or null, if the function returns void

Example - Using dynamicCall to call an agent defined function

consume {                
    //
    // Dynamic Call to call an agent defined function
    //
    list<any> args = listCreate(any);
    dynamicCall(null, "testA", args);

    listAdd(args, "HelloWorld");
    dynamicCall(null, "testB", args);

    listAdd(args, 21);
    int result = (int) dynamicCall(null, "testC", args);
    debug(result);
}

void testA() {
    debug("testA called");
}

void testB(string b) {
    debug("testB("+b+") called");
}

int testC(string b, int c) {
    debug("testC("+b+", "+c+") called");
    return c*2;
}     

Example - Using dynamicCall to call a plugin function

any plugin;

initialize {
    //
    // Initialize DTK plugin - Using ClassName
    //
    plugin = dynamicPlugin(
                     "com.<product>.apl.MyPluginExecutor");     
}

consume {
    //
    // Dynamic Call to call a plugin function
    //
    list<any> arguments;
    listAdd(arguments, 1024);
    dynamicCall(plugin,
                "myPluginExposedFunction",
                arguments);
}

Example - Using dynamicCall to call an APL Code defined function

any aplCode;

initialize {
    //
    // Dynamic Import of generic APL Code
    //
    aplCode = dynamicImport("Default.helloworld");
}

consume {
    //
    // Dynamic Call to call an APL Code defined function
    //
    list<any> arguments;
    listAdd(arguments, "HelloWorld");
    dynamicCall(aplCode,
                "myHelloFunc",
                arguments);

    
}

Example - Using dynamicCall to call a dynamically compiled function

any compiled;
 
initialize {
    compiled = dynamicCompile("""
       void testA() {
          debug("testA called");
       }
   """);
}
 
consume {               
    //
    // Call to a dynamically compiled function
    //
    dynamicCall(compiled, "testA", null);
}

dynamicCompile

The dynamicCompile function dynamically compiles APL Code and returns a handler that is used together with dynamicCall.

any dynamicCompile ( string aplCode )
ParameterDescription
aplCode The APL Code to be compiled
ReturnsHandler to use together with dynamicCall

Example - Using dynamicCompile

any aplCode = dynamicCompile("string helloWorld() { return \"Hello World!\"; }

debug("Compiled function returned "+dynamicCall(aplCode, "helloWorld"));

dynamicImport

The dynamicImport function imports generic APL Code.

The command returns a handler that is used together with dynamicCall.

Note!

Use this function only during initialization of workflow.

any dynamicImport ( string  confName  )
ParameterDescription

confName

The configuration name of APL Code to import.

Returns

Handler to use together with dynamicCall.

Example - Using dynamicImport

any aplCode;
initialize {
    //
    // Dynamic Import of generic APL Code
    //
    aplCode = dynamicImport("Default.helloworld");
}

dynamicPlugin

The dynamicPlugin function initializes a DTK APL plug-in. For further information, see/wiki/spaces/MD/pages/2963650 in the /wiki/spaces/MD/pages/3214984.

The command returns a handler that you use together with dynamicCall.

Note!

Use this function only during initialization of workflow.

any dynamicPlugin ( string classOrFunctionName )
ParameterDescription
classOrFunctionName

The name of plug-inclass implementing DRAPLExecutor, or a function name that is defined by the plug-in

ReturnsA handler that you use together with dynamicCall

Example - Using dynamicPlugin

any plugin1;
any plugin2;
initialize {
    //
    // Initialize DTK plugin - Using ClassName
    //
    plugin1 = dynamicPlugin(
                     "com.<product>.apl.MyPluginExecutor");
    //
    // Initialize DTK plugin - Using exposed function name
    //
    plugin2 = dynamicPlugin("myPluginExposedFunction");
}