Skip to content

Commit

Permalink
Rebases on top of gRPC server branch. Cleans up API annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
spericas committed Jul 22, 2024
1 parent c426862 commit 9667454
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 64 deletions.
4 changes: 2 additions & 2 deletions microprofile/grpc/client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
<artifactId>helidon-grpc-core</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.grpc</groupId>
<artifactId>helidon-microprofile-grpc-api</artifactId>
<groupId>io.helidon.grpc</groupId>
<artifactId>helidon-grpc-api</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.grpc</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class ChannelProducer {
* @return a gRPC {@link io.grpc.Channel}
*/
@Produces
@GrpcChannel(name = GrpcChannelsProvider.DEFAULT_CHANNEL_NAME)
@GrpcChannel(value = GrpcChannelsProvider.DEFAULT_CHANNEL_NAME)
public Channel get(InjectionPoint injectionPoint) {
GrpcChannel qualifier = injectionPoint.getQualifiers()
.stream()
Expand All @@ -65,7 +65,7 @@ public Channel get(InjectionPoint injectionPoint) {
.findFirst()
.orElse(null);

String name = (qualifier == null) ? GrpcChannelsProvider.DEFAULT_CHANNEL_NAME : qualifier.name();
String name = (qualifier == null) ? GrpcChannelsProvider.DEFAULT_CHANNEL_NAME : qualifier.value();
return findChannel(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@

package io.helidon.microprofile.grpc.client;

import java.io.Serial;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.enterprise.util.Nonbinding;
import jakarta.inject.Qualifier;

Expand All @@ -36,7 +34,7 @@
*
* <pre>
* &#064;Inject
* &#064;GrpcChannel(name = "foo")
* &#064;GrpcChannel("foo")
* private Channel channel;
* </pre>
*
Expand All @@ -45,7 +43,7 @@
*
* <pre>
* &#064;Inject
* &#064;GrpcChannel(name = "foo")
* &#064;GrpcChannel("foo")
* &#064;GrpcProxy
* private FooServiceClient client;
* </pre>
Expand All @@ -55,7 +53,7 @@
*
* <pre>
* &#064;Grpc(name = "FooService")
* &#064;GrpcChannel(name = "foo")
* &#064;GrpcChannel("foo")
* public interface FooServiceClient {
* ...
* };
Expand All @@ -66,30 +64,11 @@
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface GrpcChannel {

/**
* The name of the configured channel or gRPC server host.
*
* @return name of the channel
*/
@Nonbinding String name();

/**
* An {@link jakarta.enterprise.util.AnnotationLiteral} for the
* {@link GrpcChannel} annotation.
*/
class Literal extends AnnotationLiteral<GrpcChannel> implements GrpcChannel {

/**
* The singleton instance of {@link io.helidon.microprofile.grpc.client.GrpcChannel.Literal}.
*/
public static final Literal INSTANCE = new Literal();

@Serial
private static final long serialVersionUID = 1L;

@Override
public String name() {
return "";
}
}
@Nonbinding String value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import java.util.function.Supplier;

import io.helidon.common.Builder;
import io.helidon.grpc.api.GrpcMarshaller;
import io.helidon.grpc.api.GrpcMethod;
import io.helidon.grpc.core.MethodHandler;
import io.helidon.microprofile.grpc.api.GrpcMarshaller;
import io.helidon.microprofile.grpc.api.GrpcMethod;
import io.helidon.microprofile.grpc.core.AbstractServiceBuilder;
import io.helidon.microprofile.grpc.core.AnnotatedMethod;
import io.helidon.microprofile.grpc.core.AnnotatedMethodList;
Expand Down Expand Up @@ -139,7 +139,7 @@ private void addServiceMethod(ClientServiceDescriptor.Builder builder, Annotated
Class<?> responseType = handler.getResponseType();
AnnotatedMethodConfigurer configurer = new AnnotatedMethodConfigurer(method, requestType, responseType, handler);

switch (annotation.type()) {
switch (annotation.value()) {
case UNARY:
builder.unary(name, configurer);
break;
Expand All @@ -154,7 +154,7 @@ private void addServiceMethod(ClientServiceDescriptor.Builder builder, Annotated
break;
case UNKNOWN:
default:
LOGGER.log(Level.ERROR, () -> "Unrecognized method type " + annotation.type());
LOGGER.log(Level.ERROR, () -> "Unrecognized method type " + annotation.value());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@

package io.helidon.microprofile.grpc.client;

import java.io.Serial;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.inject.Qualifier;

/**
Expand All @@ -33,19 +31,4 @@
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface GrpcProxy {

/**
* An {@link jakarta.enterprise.util.AnnotationLiteral} for the
* {@link io.helidon.microprofile.grpc.client.GrpcProxy} annotation.
*/
class Literal extends AnnotationLiteral<GrpcProxy> implements GrpcProxy {

/**
* The singleton instance of {@link io.helidon.microprofile.grpc.client.GrpcProxy.Literal}.
*/
public static final Literal INSTANCE = new Literal();

@Serial
private static final long serialVersionUID = 1L;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ private GrpcProxyBuilder(GrpcServiceClient client, Class<T> type) {
* for a given gRPC service interface.
* <p>
* The class passed to this method should be properly annotated with
* {@link io.helidon.microprofile.grpc.api.Grpc} and
* {@link io.helidon.microprofile.grpc.api.GrpcMethod} annotations
* {@link io.helidon.grpc.api.Grpc} and
* {@link io.helidon.grpc.api.GrpcMethod} annotations
* so that the proxy can properly route calls to the server.
*
* @param channel the {@link io.grpc.Channel} to connect to the server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ private GrpcProxyProducer() {
* @return a gRPC client proxy
*/
@GrpcProxy
@GrpcChannel(name = GrpcChannelsProvider.DEFAULT_CHANNEL_NAME)
@GrpcChannel(value = GrpcChannelsProvider.DEFAULT_CHANNEL_NAME)
static Object proxyUsingNamedChannel(InjectionPoint injectionPoint, ChannelProducer producer) {
Class<?> type = ModelHelper.getGenericType(injectionPoint.getType());

String channelName;
if (injectionPoint.getAnnotated().isAnnotationPresent(GrpcChannel.class)) {
channelName = injectionPoint.getAnnotated().getAnnotation(GrpcChannel.class).name();
channelName = injectionPoint.getAnnotated().getAnnotation(GrpcChannel.class).value();
} else {
channelName = type.isAnnotationPresent(GrpcChannel.class)
? type.getAnnotation(GrpcChannel.class).name()
? type.getAnnotation(GrpcChannel.class).value()
: GrpcChannelsProvider.DEFAULT_CHANNEL_NAME;
}

Expand Down
2 changes: 1 addition & 1 deletion microprofile/grpc/client/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
requires io.helidon.tracing;
requires io.helidon.config;
requires io.helidon.webclient.grpc;
requires io.helidon.microprofile.grpc.api;
requires io.helidon.grpc.api;
requires io.helidon.microprofile.grpc.core;

requires io.grpc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

import io.helidon.common.configurable.Resource;
import io.helidon.common.tls.Tls;
import io.helidon.microprofile.grpc.api.Grpc;
import io.helidon.microprofile.grpc.api.GrpcMarshaller;
import io.helidon.microprofile.grpc.api.Unary;
import io.helidon.grpc.api.Grpc;
import io.helidon.grpc.api.GrpcMarshaller;
import io.helidon.grpc.api.Unary;
import io.helidon.microprofile.grpc.server.GrpcMpCdiExtension;
import io.helidon.microprofile.testing.junit5.AddBean;
import io.helidon.microprofile.testing.junit5.AddExtension;
Expand Down Expand Up @@ -120,7 +120,7 @@ public void onCompleted() {
@GrpcMarshaller("java")
public static class EchoService {

@Unary(name = "Echo")
@Unary("Echo")
public void echo(String request, StreamObserver<String> observer) {
try {
complete(observer, request);
Expand All @@ -130,12 +130,12 @@ public void echo(String request, StreamObserver<String> observer) {
}
}

@Grpc(name = "EchoService")
@Grpc("EchoService")
@GrpcMarshaller("java")
@GrpcChannel(name = "echo-channel")
@GrpcChannel(value = "echo-channel")
public interface EchoServiceClient {

@Unary(name = "Echo")
@Unary("Echo")
void echo(String request, StreamObserver<String> observer);
}
}

0 comments on commit 9667454

Please sign in to comment.