private void invokeCommittedFunction(String transactionId, String transactionBlockId) { BFunctionPointer fp = committedFuncRegistry.get(transactionBlockId); BValue[] args = {new BString(transactionId + ":" + transactionBlockId)}; if (fp != null) { BVMExecutor.executeFunction(fp.value().getPackageInfo().getProgramFile(), fp.value(), args); } }
/** * Invokes a callable function pointer. * * @param functionPointer function pointer * @return return values */ protected BValue[] invokeFunction(BFunctionPointer functionPointer) { List<BValue> lambdaFunctionArgs = new ArrayList<>(); for (BClosure closure : functionPointer.getClosureVars()) { lambdaFunctionArgs.add(closure.value()); } return BVMExecutor.executeFunction(functionPointer.value().getPackageInfo().getProgramFile(), functionPointer.value(), lambdaFunctionArgs.toArray(new BValue[0])); }
/** * Method to register a subscription to the underlying topic representing the stream in the broker. * * @param functionPointer represents the function pointer reference for the function to be invoked on receiving * messages */ public void subscribe(BFunctionPointer functionPointer) { BType[] parameters = functionPointer.value().getParamTypes(); int lastArrayIndex = parameters.length - 1; if (!BVM.isAssignable(constraintType, parameters[lastArrayIndex], new ArrayList<>())) { throw new BallerinaException("incompatible function: subscription function needs to be a function" + " accepting:" + this.constraintType); } String queueName = String.valueOf(System.currentTimeMillis()) + UUID.randomUUID().toString(); brokerInstance.addSubscription(topicName, new StreamSubscriber(queueName, functionPointer)); }
@Override protected void send(Message message) { try { BValue data = ((BallerinaBrokerByteBuf) (message.getContentChunks().get(0).getByteBuf()).unwrap()).getValue(); List<BValue> argsList = new ArrayList<>(closureArgs); argsList.add(data); BVMExecutor.executeFunction(functionPointer.value().getPackageInfo().getProgramFile(), functionPointer.value(), argsList.toArray(new BValue[0])); } catch (Exception e) { throw new BallerinaException("Error delivering event to subscriber: ", e); } }
@Override public void receive(Event[] events) { BValueArray outputArray = new BValueArray(new BMapType(structType)); int j = 0; for (Event event : events) { // Here it is assumed that an event data will contain all the fields // of the record. Otherwise, some fields will be missing from the record value. BMap<String, BValue> output = new BMap<String, BValue>(structType); Iterator<String> fieldNamesIterator = structType.getFields().keySet().iterator(); for (Object field : event.getData()) { if (field instanceof Long || field instanceof Integer) { output.put(fieldNamesIterator.next(), new BInteger(((Number) field).longValue())); } else if (field instanceof Double || field instanceof Float) { output.put(fieldNamesIterator.next(), new BFloat(((Number) field).doubleValue())); } else if (field instanceof Boolean) { output.put(fieldNamesIterator.next(), new BBoolean(((Boolean) field))); } else if (field instanceof String) { output.put(fieldNamesIterator.next(), new BString((String) field)); } } outputArray.add(j, output); j++; } List<BValue> argsList = new ArrayList<>(); argsList.addAll(closureArgs); argsList.add(outputArray); BVMExecutor.executeFunction(functionPointer.value().getPackageInfo().getProgramFile(), functionPointer.value(), argsList.toArray(new BValue[0])); } });
public void addCallback(String streamId, BFunctionPointer functionPointer, SiddhiAppRuntime siddhiAppRuntime) { BType[] parameters = functionPointer.value().getParamTypes();
for (int i = 0; i < functionPointerArray.size(); i++) { BFunctionPointer functionPointer = (BFunctionPointer) functionPointerArray.getRefValue(i); String functionName = functionPointer.value().getName(); String streamId = "stream" + functionName.replaceAll("\\$", "_"); StreamingRuntimeManager.getInstance().addCallback(streamId, functionPointer, siddhiAppRuntime);
BType functionInputType = lambdaFunction.value().getParamTypes()[0]; if (functionInputType != this.constraintType) { throw new BallerinaException("incompatible types: function with record type:" BValue[] returns = BVMExecutor.executeFunction(lambdaFunction.value().getPackageInfo() .getProgramFile(), lambdaFunction.value(), args); if (((BBoolean) returns[0]).booleanValue()) { ++deletedCount;
functionInfo = ((BFunctionPointer) sf.refRegs[i]).value(); strand = invokeCallable(strand, (BFunctionPointer) sf.refRegs[i], funcCallCPEntry, functionInfo, sf, funcCallCPEntry.getFlags());