use of org.ballerinalang.util.codegen.PackageInfo in project ballerina by ballerina-lang.
the class BLangFunctions method invokeEntrypointCallable.
/**
* This method calls a program callable, considering it as an entry point callable. Which means, this callable will
* be invoked as the first callable in a program, and after it is called, all the cleanup will be done for it to
* exit from the program. That is, this callable will wait for the response to be fully available, and it will wait
* till all the workers in the system to finish executing.
* @param bLangProgram the program file
* @param packageName the package the callable is residing
* @param callableName the callable name
* @param args the callable arguments
* @return
*/
public static BValue[] invokeEntrypointCallable(ProgramFile bLangProgram, String packageName, String callableName, BValue[] args) {
PackageInfo packageInfo = bLangProgram.getPackageInfo(packageName);
FunctionInfo functionInfo = packageInfo.getFunctionInfo(callableName);
if (functionInfo == null) {
throw new RuntimeException("Function '" + callableName + "' is not defined");
}
return invokeEntrypointCallable(bLangProgram, packageInfo, functionInfo, args);
}
use of org.ballerinalang.util.codegen.PackageInfo in project ballerina by ballerina-lang.
the class TransactionUtils method checkTransactionCoordinatorError.
private static void checkTransactionCoordinatorError(BValue value, WorkerExecutionContext ctx, String errMsg) {
if (value.getType().getTag() == TypeTags.STRUCT_TAG) {
PackageInfo errorPackageInfo = ctx.programFile.getPackageInfo(PACKAGE_BUILTIN);
StructInfo errorStructInfo = errorPackageInfo.getStructInfo(STRUCT_GENERIC_ERROR);
if (((BStruct) value).getType().structInfo.equals(errorStructInfo)) {
throw new BallerinaException(errMsg + ((BStruct) value).getStringField(0));
}
}
}
use of org.ballerinalang.util.codegen.PackageInfo in project ballerina by ballerina-lang.
the class OpenSecureSocket method createReturnStruct.
private BStruct createReturnStruct(Context context, SSLSocket sslSocket, ByteChannel channel) throws IOException {
PackageInfo ioPackageInfo = context.getProgramFile().getPackageInfo(SOCKET_PACKAGE);
// Create ByteChannel Struct
StructInfo channelStructInfo = ioPackageInfo.getStructInfo(BYTE_CHANNEL_STRUCT_TYPE);
Channel ballerinaSocketChannel = new SocketIOChannel(channel, 0);
BStruct channelStruct = BLangVMStructs.createBStruct(channelStructInfo, ballerinaSocketChannel);
channelStruct.addNativeData(IOConstants.BYTE_CHANNEL_NAME, ballerinaSocketChannel);
// Create Socket Struct
StructInfo socketStructInfo = ioPackageInfo.getStructInfo(SOCKET_STRUCT_TYPE);
BStruct socketStruct = BLangVMStructs.createBStruct(socketStructInfo);
socketStruct.setRefField(0, channelStruct);
socketStruct.setIntField(0, sslSocket.getPort());
socketStruct.setIntField(1, sslSocket.getLocalPort());
socketStruct.setStringField(0, sslSocket.getInetAddress().getHostAddress());
socketStruct.setStringField(1, sslSocket.getLocalAddress().getHostAddress());
socketStruct.addNativeData(IOConstants.CLIENT_SOCKET_NAME, channel);
return socketStruct;
}
use of org.ballerinalang.util.codegen.PackageInfo in project ballerina by ballerina-lang.
the class ClientSocketTest method testOpenWithProperties.
@Test(dependsOnMethods = "testClosure", description = "Test connection open with properties")
public void testOpenWithProperties() {
int port = ThreadLocalRandom.current().nextInt(33000, 46000);
PackageInfo ioPackageInfo = socketClient.getProgFile().getPackageInfo("ballerina.io");
StructInfo socketProperties = ioPackageInfo.getStructInfo("SocketProperties");
BStruct propertyStruct = BLangVMStructs.createBStruct(socketProperties, port);
BValue[] args = { new BString("localhost"), new BInteger(MockSocketServer.SERVER_PORT), propertyStruct };
final BValue[] returns = BRunUtil.invoke(socketClient, "openSocketConnectionWithProps", args);
final BStruct socket = (BStruct) returns[0];
Assert.assertEquals(socket.getIntField(1), port, "Client port didn't bind to assign port.");
args = new BValue[] { socket };
BRunUtil.invoke(socketClient, "close", args);
}
use of org.ballerinalang.util.codegen.PackageInfo in project ballerina by ballerina-lang.
the class BLangVMErrors method createNullRefException.
/* Type Specific Errors */
public static BStruct createNullRefException(Context context) {
PackageInfo errorPackageInfo = context.getProgramFile().getPackageInfo(PACKAGE_RUNTIME);
StructInfo errorStructInfo = errorPackageInfo.getStructInfo(STRUCT_NULL_REF_EXCEPTION);
return generateError(context.getCallableUnitInfo(), true, errorStructInfo, "");
}
Aggregations