use of org.ballerinalang.net.grpc.config.ServiceConfiguration 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());
}
}
use of org.ballerinalang.net.grpc.config.ServiceConfiguration in project ballerina by ballerina-lang.
the class ServiceProtoUtils method getServiceConfiguration.
static ServiceConfiguration getServiceConfiguration(ServiceNode serviceNode) {
String rpcEndpoint = null;
boolean clientStreaming = false;
boolean serverStreaming = false;
boolean generateClientConnector = false;
for (AnnotationAttachmentNode annotationNode : serviceNode.getAnnotationAttachments()) {
if (!ServiceProtoConstants.ANN_SERVICE_CONFIG.equals(annotationNode.getAnnotationName().getValue())) {
continue;
}
if (annotationNode.getExpression() instanceof BLangRecordLiteral) {
List<BLangRecordLiteral.BLangRecordKeyValue> attributes = ((BLangRecordLiteral) annotationNode.getExpression()).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue attributeNode : attributes) {
String attributeName = attributeNode.getKey().toString();
String attributeValue = attributeNode.getValue() != null ? attributeNode.getValue().toString() : null;
switch(attributeName) {
case ServiceProtoConstants.SERVICE_CONFIG_RPC_ENDPOINT:
{
rpcEndpoint = attributeValue != null ? attributeValue : null;
break;
}
case ServiceProtoConstants.SERVICE_CONFIG_CLIENT_STREAMING:
{
clientStreaming = attributeValue != null && Boolean.parseBoolean(attributeValue);
break;
}
case ServiceProtoConstants.SERVICE_CONFIG_SERVER_STREAMING:
{
serverStreaming = attributeValue != null && Boolean.parseBoolean(attributeValue);
break;
}
case ServiceProtoConstants.SERVICE_CONFIG_GENERATE_CLIENT:
{
generateClientConnector = attributeValue != null && Boolean.parseBoolean(attributeValue);
break;
}
default:
{
break;
}
}
}
}
}
return new ServiceConfiguration(rpcEndpoint, clientStreaming, serverStreaming, generateClientConnector);
}
use of org.ballerinalang.net.grpc.config.ServiceConfiguration 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();
}
Aggregations