Apama Documentation : Developing Apama Applications : Developing Apama Applications in EPL : Using EPL Plug-ins : About the chunk type
About the chunk type
The chunk type allows data to be referenced from EPL that has no equivalent EPL type. It is not possible to perform operations on data of type chunk from EPL directly; the chunk type exists purely to allow data output by one external library function to pass through to another function. Apama does not modify the internal structure of chunk values in any way. As long as a receiving function expects the same type as that output by the original function, any complex data structure can be passed around using this mechanism.
To use chunks with plug-ins, you must first declare a variable of type chunk. You can then assign the chunk to the return value of an external function or use the chunk as the value of the out parameter in the function call.
The following example illustrates this. The functions setRealVal and setImagVal set internal values of the chunk, while the functions getRealVal and getImagVal retrieve values from the chunk. The function addComplexNumber adds the second chunk to the first chunk. The source code for complex_plugin is in the samples\correlator_plugin\cpp directory of your Apama installation directory.
Monitor ComplexPlugin {
import "complex_plugin" as plugin;

action onload {
// Creates a first complex number chunk
chunk complexNumberFull := plugin.makeComplexNumberFull(4.0, -1.4);
printComplexNumber(complexNumberFull);

// Creates a second complex number chunk
chunk complexNumberEmpty := plugin.makeComplexNumberEmpty();

// Get the real and imaginary values of the number
plugin.setRealVal(complexNumberEmpty, 2.0);
plugin.setImagVal(complexNumberEmpty, 3.0);
printComplexNumber(complexNumberEmpty);

// Add the second complex number to the first complex number
plugin.addComplexNumber(complexNumberFull, complexNumberEmpty);
printComplexNumber(complexNumberFull);
}

action printComplexNumber(chunk complexNumber)
{
float real := plugin.getRealVal(complexNumber);
float imag := plugin.getImagVal(complexNumber);
string sign := "";
if(imag >= 0.0) {
sign := "+";
}
log real.toString() + sign + imag.toString() + "i";
}
}
Although the chunk type was designed to support unknown data types, it is also a useful mechanism to improve performance. Where data returned by external plug-in functions does not need to be accessed from EPL, using a chunk can cut down on unnecessary type conversion. For example, suppose the output of a localtime() method is a 9-element array of type float. While you could declare this output to be of type sequence<float>, there is no need to do so because the EPL never accesses the value. Consequently, you can declare the output to be of type chunk and avoid an unnecessary conversion from native array to EPL sequence and back again.
Copyright © 2013-2017 Software AG, Darmstadt, Germany. (Innovation Release)

Product LogoContact Support   |   Community   |   Feedback