Search in sources :

Example 6 with BTypeDescValue

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

the class RetrieveSecret method execute.

@Override
public void execute(Context context) {
    String secret = ((BStruct) BLangConnectorSPIUtil.getService(context.getProgramFile(), ((BServiceType) ((BTypeDescValue) (context).getLocalWorkerData().refRegs[0]).value())).getAnnotationList(WebSubSubscriberConstants.WEBSUB_PACKAGE_PATH, WebSubSubscriberConstants.ANN_NAME_WEBSUB_SUBSCRIBER_SERVICE_CONFIG).get(0).getValue().getVMValue()).getStringField(3);
    context.setReturnValues(new BString(secret));
}
Also used : BTypeDescValue(org.ballerinalang.model.values.BTypeDescValue) BStruct(org.ballerinalang.model.values.BStruct) BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString)

Example 7 with BTypeDescValue

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

the class NonBlockingExecute 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) {
        BValue payloadBValue = context.getRefArgument(1);
        Message requestMsg = MessageUtils.generateProtoMessage(payloadBValue, methodDescriptor.getInputType());
        GrpcNonBlockingStub grpcNonBlockingStub = (GrpcNonBlockingStub) connectionStub;
        BTypeDescValue serviceType = (BTypeDescValue) context.getRefArgument(2);
        Service callbackService = BLangConnectorSPIUtil.getServiceFromType(context.getProgramFile(), getTypeField(serviceType));
        try {
            MethodDescriptor.MethodType methodType = getMethodType(methodDescriptor);
            if (methodType.equals(MethodDescriptor.MethodType.UNARY)) {
                grpcNonBlockingStub.executeUnary(requestMsg, new DefaultStreamObserver(callbackService), methodName);
            } else if (methodType.equals(MethodDescriptor.MethodType.SERVER_STREAMING)) {
                grpcNonBlockingStub.executeServerStreaming(requestMsg, new DefaultStreamObserver(callbackService), methodName);
            } else {
                notifyErrorReply(context, "Error while executing the client call. Method type " + methodType.name() + " not supported");
                return;
            }
            context.setReturnValues();
            return;
        } catch (RuntimeException | GrpcClientException e) {
            notifyErrorReply(context, "gRPC Client Connector Error :" + e.getMessage());
            return;
        }
    }
    notifyErrorReply(context, "Error while processing the request message. Connection Sub " + "type not supported");
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Message(org.ballerinalang.net.grpc.Message) DefaultStreamObserver(org.ballerinalang.net.grpc.stubs.DefaultStreamObserver) BValue(org.ballerinalang.model.values.BValue) 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 8 with BTypeDescValue

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

the class BallerinaHTTPConnectorListener method getRequestFilterContext.

private BValue getRequestFilterContext(HttpResource httpResource) {
    BStruct filterCtxtStruct = BLangConnectorSPIUtil.createBStruct(httpResource.getBalResource().getResourceInfo().getServiceInfo().getPackageInfo().getProgramFile(), PROTOCOL_PACKAGE_HTTP, "FilterContext");
    filterCtxtStruct.setRefField(0, new BTypeDescValue(httpResource.getBalResource().getResourceInfo().getServiceInfo().getType()));
    filterCtxtStruct.setStringField(0, httpResource.getParentService().getName());
    filterCtxtStruct.setStringField(1, httpResource.getName());
    return filterCtxtStruct;
}
Also used : BTypeDescValue(org.ballerinalang.model.values.BTypeDescValue) BStruct(org.ballerinalang.model.values.BStruct)

Example 9 with BTypeDescValue

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

the class AbstractSQLAction method getStructType.

protected BStructType getStructType(Context context) {
    BStructType structType = null;
    BTypeDescValue type = (BTypeDescValue) context.getNullableRefArgument(2);
    if (type != null) {
        structType = (BStructType) type.value();
    }
    return structType;
}
Also used : BStructType(org.ballerinalang.model.types.BStructType) BTypeDescValue(org.ballerinalang.model.values.BTypeDescValue)

Example 10 with BTypeDescValue

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

the class ServiceTypeTest method testServiceType.

@Test
public void testServiceType() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testServiceType");
    Assert.assertTrue(returns[0] instanceof BTypeDescValue);
    Assert.assertEquals(returns[0].stringValue(), "HelloWorld");
    final BTypeDescValue value = (BTypeDescValue) returns[0];
    Assert.assertTrue(value.value() instanceof BServiceType);
}
Also used : BTypeDescValue(org.ballerinalang.model.values.BTypeDescValue) BValue(org.ballerinalang.model.values.BValue) BServiceType(org.ballerinalang.model.types.BServiceType) Test(org.testng.annotations.Test)

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