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;
}
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());
}
}
}
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;
}
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));
}
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()));
}
Aggregations