Search in sources :

Example 1 with BTypeDescValue

use of org.ballerinalang.model.values.BTypeDescValue in project ballerina by ballerina-lang.

the class AbstractSQLAction method getStructType.

private BStructType getStructType(BStruct parameter) {
    BTypeDescValue type = (BTypeDescValue) parameter.getRefField(3);
    BStructType structType = null;
    if (type != null) {
        structType = (BStructType) type.value();
    }
    return structType;
}
Also used : BStructType(org.ballerinalang.model.types.BStructType) BTypeDescValue(org.ballerinalang.model.values.BTypeDescValue)

Example 2 with BTypeDescValue

use of org.ballerinalang.model.values.BTypeDescValue in project ballerina by ballerina-lang.

the class StreamingExecute method execute.

@Override
public void execute(Context context) {
    BStruct serviceStub = (BStruct) context.getRefArgument(SERVICE_STUB_REF_INDEX);
    if (serviceStub == null) {
        notifyErrorReply(context, "Error while getting connector. gRPC Client connector " + "is not initialized properly");
        return;
    }
    Object connectionStub = serviceStub.getNativeData(SERVICE_STUB);
    if (connectionStub == null) {
        notifyErrorReply(context, "Error while getting connection stub. gRPC Client connector " + "is not initialized properly");
        return;
    }
    String methodName = context.getStringArgument(0);
    if (methodName == null) {
        notifyErrorReply(context, "Error while processing the request. RPC endpoint doesn't " + "set properly");
        return;
    }
    com.google.protobuf.Descriptors.MethodDescriptor methodDescriptor = MessageRegistry.getInstance().getMethodDescriptor(methodName);
    if (methodDescriptor == null) {
        notifyErrorReply(context, "No registered method descriptor for '" + methodName + "'");
        return;
    }
    if (connectionStub instanceof GrpcNonBlockingStub) {
        GrpcNonBlockingStub grpcNonBlockingStub = (GrpcNonBlockingStub) connectionStub;
        BTypeDescValue serviceType = (BTypeDescValue) context.getRefArgument(1);
        Service callbackService = BLangConnectorSPIUtil.getServiceFromType(context.getProgramFile(), getTypeField(serviceType));
        try {
            MethodDescriptor.MethodType methodType = getMethodType(methodDescriptor);
            DefaultStreamObserver responseObserver = new DefaultStreamObserver(callbackService);
            StreamObserver<Message> requestSender;
            if (methodType.equals(MethodDescriptor.MethodType.CLIENT_STREAMING)) {
                requestSender = grpcNonBlockingStub.executeClientStreaming(responseObserver, methodName);
            } else if (methodType.equals(MethodDescriptor.MethodType.BIDI_STREAMING)) {
                requestSender = grpcNonBlockingStub.executeBidiStreaming(responseObserver, methodName);
            } else {
                notifyErrorReply(context, "Error while executing the client call. Method type " + methodType.name() + " not supported");
                return;
            }
            BStruct connStruct = createStruct(context, CLIENT_CONNECTION);
            connStruct.addNativeData(REQUEST_SENDER, requestSender);
            connStruct.addNativeData(REQUEST_MESSAGE_DEFINITION, methodDescriptor.getInputType());
            BStruct clientEndpoint = (BStruct) serviceStub.getNativeData(CLIENT_END_POINT);
            clientEndpoint.addNativeData(CLIENT_CONNECTION, connStruct);
            context.setReturnValues(clientEndpoint);
        } catch (RuntimeException | GrpcClientException e) {
            notifyErrorReply(context, "gRPC Client Connector Error :" + e.getMessage());
        }
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Message(org.ballerinalang.net.grpc.Message) DefaultStreamObserver(org.ballerinalang.net.grpc.stubs.DefaultStreamObserver) Service(org.ballerinalang.connector.api.Service) MethodDescriptor(io.grpc.MethodDescriptor) BTypeDescValue(org.ballerinalang.model.values.BTypeDescValue) GrpcClientException(org.ballerinalang.net.grpc.exception.GrpcClientException) GrpcNonBlockingStub(org.ballerinalang.net.grpc.stubs.GrpcNonBlockingStub)

Example 3 with BTypeDescValue

use of org.ballerinalang.model.values.BTypeDescValue in project ballerina by ballerina-lang.

the class LoadToTable method getbTable.

private static BTable getbTable(Context context, List records) throws BallerinaIOException {
    BTypeDescValue type = (BTypeDescValue) context.getRefArgument(0);
    BTable table = new BTable(new BTableType(type.value()));
    BStructType structType = (BStructType) type.value();
    boolean skipHeaderLine = context.getBooleanArgument(0);
    if (skipHeaderLine && !records.isEmpty()) {
        records.remove(0);
    }
    for (Object obj : records) {
        String[] fields = (String[]) obj;
        final BStruct struct = getStruct(fields, structType);
        if (struct != null) {
            table.addData(struct);
        }
    }
    return table;
}
Also used : BStructType(org.ballerinalang.model.types.BStructType) BTypeDescValue(org.ballerinalang.model.values.BTypeDescValue) BTable(org.ballerinalang.model.values.BTable) BStruct(org.ballerinalang.model.values.BStruct) BTableType(org.ballerinalang.model.types.BTableType)

Example 4 with BTypeDescValue

use of org.ballerinalang.model.values.BTypeDescValue in project ballerina by ballerina-lang.

the class GetActionAnnotations method execute.

@Override
public void execute(Context context) {
    BTypeDescValue bTypeValue = (BTypeDescValue) context.getRefArgument(0);
    if (!(bTypeValue.value() instanceof BConnectorType)) {
        context.setReturnValues((BValue) null);
    }
    BConnectorType connectorType = (BConnectorType) bTypeValue.value();
    String key = connectorType.getName() + DOT + context.getStringArgument(0);
    context.setReturnValues(getAnnotationValue(context, connectorType.getPackagePath(), key));
}
Also used : BTypeDescValue(org.ballerinalang.model.values.BTypeDescValue) BConnectorType(org.ballerinalang.model.types.BConnectorType)

Example 5 with BTypeDescValue

use of org.ballerinalang.model.values.BTypeDescValue in project ballerina by ballerina-lang.

the class GetConnectorAnnotations method execute.

@Override
public void execute(Context context) {
    BTypeDescValue bTypeValue = (BTypeDescValue) context.getRefArgument(0);
    if (!(bTypeValue.value() instanceof BConnectorType)) {
        context.setReturnValues((BValue) null);
    }
    BConnectorType connectorType = (BConnectorType) bTypeValue.value();
    context.setReturnValues(getAnnotationValue(context, connectorType.getPackagePath(), connectorType.getName()));
}
Also used : BTypeDescValue(org.ballerinalang.model.values.BTypeDescValue) BConnectorType(org.ballerinalang.model.types.BConnectorType)

Aggregations

BTypeDescValue (org.ballerinalang.model.values.BTypeDescValue)15 BStruct (org.ballerinalang.model.values.BStruct)6 BStructType (org.ballerinalang.model.types.BStructType)5 BServiceType (org.ballerinalang.model.types.BServiceType)3 BValue (org.ballerinalang.model.values.BValue)3 MethodDescriptor (io.grpc.MethodDescriptor)2 Service (org.ballerinalang.connector.api.Service)2 BConnectorType (org.ballerinalang.model.types.BConnectorType)2 BString (org.ballerinalang.model.values.BString)2 BTable (org.ballerinalang.model.values.BTable)2 Message (org.ballerinalang.net.grpc.Message)2 GrpcClientException (org.ballerinalang.net.grpc.exception.GrpcClientException)2 DefaultStreamObserver (org.ballerinalang.net.grpc.stubs.DefaultStreamObserver)2 GrpcNonBlockingStub (org.ballerinalang.net.grpc.stubs.GrpcNonBlockingStub)2 StringJoiner (java.util.StringJoiner)1 BMapType (org.ballerinalang.model.types.BMapType)1 BTableType (org.ballerinalang.model.types.BTableType)1 BBlobArray (org.ballerinalang.model.values.BBlobArray)1 BBooleanArray (org.ballerinalang.model.values.BBooleanArray)1 BFloatArray (org.ballerinalang.model.values.BFloatArray)1