Search in sources :

Example 1 with File

use of org.ballerinalang.net.grpc.proto.definition.File in project ballerina by ballerina-lang.

the class ServiceProtoBuilder method process.

@Override
public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) {
    for (AnnotationAttachmentNode annotationNode : annotations) {
        if (ANN_MESSAGE_LISTENER.equals(annotationNode.getAnnotationName().getValue())) {
            return;
        }
    }
    try {
        File fileDefinition = ServiceProtoUtils.generateProtoDefinition(serviceNode);
        ServiceConfiguration serviceConfig = ServiceProtoUtils.getServiceConfiguration(serviceNode);
        ServiceProtoUtils.writeServiceFiles(fileDefinition, serviceNode.getName().getValue(), serviceConfig.isGenerateClientConnector());
    } catch (GrpcServerException e) {
        dlog.logDiagnostic(Diagnostic.Kind.WARNING, serviceNode.getPosition(), e.getMessage());
    }
}
Also used : ServiceConfiguration(org.ballerinalang.net.grpc.config.ServiceConfiguration) File(org.ballerinalang.net.grpc.proto.definition.File) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode) GrpcServerException(org.ballerinalang.net.grpc.exception.GrpcServerException)

Example 2 with File

use of org.ballerinalang.net.grpc.proto.definition.File in project ballerina by ballerina-lang.

the class ServiceProtoUtils method generateProtoDefinition.

static File generateProtoDefinition(ServiceNode serviceNode) throws GrpcServerException {
    // Protobuf file definition builder.
    String packageName = serviceNode.getPosition().getSource().getPackageName();
    File.Builder fileBuilder;
    if (!".".equals(packageName)) {
        fileBuilder = File.newBuilder(serviceNode.getName() + ServiceProtoConstants.PROTO_FILE_EXTENSION).setSyntax(ServiceProtoConstants.PROTOCOL_SYNTAX).setPackage(serviceNode.getPosition().getSource().getPackageName());
    } else {
        fileBuilder = File.newBuilder(serviceNode.getName() + ServiceProtoConstants.PROTO_FILE_EXTENSION).setSyntax(ServiceProtoConstants.PROTOCOL_SYNTAX);
    }
    ServiceConfiguration serviceConfig = getServiceConfiguration(serviceNode);
    Service serviceDefinition;
    if (serviceConfig.getRpcEndpoint() != null && (serviceConfig.isClientStreaming())) {
        serviceDefinition = getStreamingServiceDefinition(serviceNode, serviceConfig, fileBuilder);
    } else {
        serviceDefinition = getUnaryServiceDefinition(serviceNode, fileBuilder);
    }
    fileBuilder.setService(serviceDefinition);
    return fileBuilder.build();
}
Also used : ServiceConfiguration(org.ballerinalang.net.grpc.config.ServiceConfiguration) Service(org.ballerinalang.net.grpc.proto.definition.Service) File(org.ballerinalang.net.grpc.proto.definition.File)

Aggregations

ServiceConfiguration (org.ballerinalang.net.grpc.config.ServiceConfiguration)2 File (org.ballerinalang.net.grpc.proto.definition.File)2 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)1 GrpcServerException (org.ballerinalang.net.grpc.exception.GrpcServerException)1 Service (org.ballerinalang.net.grpc.proto.definition.Service)1