Apama 10.3 | Apama Documentation | Developing Apama Applications | Developing EPL Plug-ins | EPL Plug-ins in C and C++ Written Prior to 10.0 | Advanced plug-in functionality in C++ and C | The chunk type
The chunk type
Apama's plug-in support mechanism assumes that the functions called are stateless, that is they do not retain state between calls. However, it is recognized that in some circumstances a developer might need to retain complex state in between function calls and in order to assist in this, the opaque type chunk is provided. Furthermore, 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 code directly; it exists purely to allow "pass-through" of data output by one external plug-in function to another function. The correlator does not modify the internal structure of chunk values in any way, so 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.
Note: Chunks cannot be routed, emitted or enqueued. Also note that passing a chunk created by one plug-in to a second plug-in in the same monitor is not permitted. If one plug-in returns a chunk and a second plug-in tries to read it, a C++ exception will be thrown within the second plug-in and, unless it is caught, the exception will terminate the correlator instance.
To use chunks with plug-ins first requires declaring a variable of type chunk. It can then be assigned the return value from an external function or used as a parameter in the function call.
The following example illustrates this. Monitor printTime prints out the current time when it is loaded. To generate timeString the monitor uses an external time plug-in. In this plug-in, the time() function returns a float representing the time in seconds; localtime() returns a structure containing year, month, day and time data which the asctime() function formats into a string of the form: "Friday February 1 15:00:07 GMT 2002".

import "apama_time" as time;
monitor printTime {
  float millis;
  chunk timeData;
  string timeString;
  action onload() {
    millis := time.time();
    timeData := time.localtime(millis);
    timeString := time.asctime(timeData);
    print "The time is " + timeString;
It can be seen that the timeDatachunk is used to store output from localtime() and pass it to asctime(); the value is not inspected from EPL code directly.
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 library functions does not need to be accessed from the EPL code, using a chunk can cut down on unnecessary type conversion. For example, in the above example the output of localtime() is actually a 9-element array of float. The fact that the value is never accessed by the EPL code means that it can be declared as a chunk and an unnecessary conversion from native array to an EPL sequence and back again is removed.

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.