use of org.ballerinalang.model.types.BArrayType in project ballerina by ballerina-lang.
the class StreamingRuntimeManager method addCallback.
public void addCallback(String streamId, BFunctionPointer functionPointer, SiddhiAppRuntime siddhiAppRuntime) {
BType[] parameters = functionPointer.value().getFunctionInfo().getParamTypes();
BStructType structType = (BStructType) ((BArrayType) parameters[0]).getElementType();
if (!(parameters[0] instanceof BArrayType)) {
throw new BallerinaException("incompatible function: inline function needs to be a function accepting" + " a struct array");
}
siddhiAppRuntime.addCallback(streamId, new StreamCallback() {
@Override
public void receive(Event[] events) {
for (Event event : events) {
AtomicInteger intVarIndex = new AtomicInteger(-1);
AtomicInteger floatVarIndex = new AtomicInteger(-1);
AtomicInteger boolVarIndex = new AtomicInteger(-1);
AtomicInteger stringVarIndex = new AtomicInteger(-1);
BStruct output = new BStruct(structType);
for (Object field : event.getData()) {
if (field instanceof Long) {
output.setIntField(intVarIndex.incrementAndGet(), (Long) field);
} else if (field instanceof Double) {
output.setFloatField(floatVarIndex.incrementAndGet(), (Double) field);
} else if (field instanceof Boolean) {
output.setBooleanField(boolVarIndex.incrementAndGet(), (Integer) field);
} else if (field instanceof String) {
output.setStringField(stringVarIndex.incrementAndGet(), (String) field);
}
}
BValue[] args = { output };
BLangFunctions.invokeCallable(functionPointer.value().getFunctionInfo(), args);
}
}
});
}
Aggregations