diff --git a/grpc/api/src/main/java/io/helidon/grpc/api/Grpc.java b/grpc/api/src/main/java/io/helidon/grpc/api/Grpc.java index 4b763f4ec22..281a5bd44f1 100644 --- a/grpc/api/src/main/java/io/helidon/grpc/api/Grpc.java +++ b/grpc/api/src/main/java/io/helidon/grpc/api/Grpc.java @@ -293,4 +293,28 @@ public interface Grpc { */ Class> value(); } + + /** + * An annotation that can be used to specify the name of a configured gRPC channel. + * channel to inject, or the name of the host to connect to, as described in + */ + @Target({TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PARAMETER}) + @Retention(RUNTIME) + @interface GrpcChannel { + + /** + * The name of the configured channel. + * + * @return name of the channel + */ + String value(); + } + + /** + * An annotation used to mark an injection point for a gRPC service client proxy. + */ + @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) + @Retention(RUNTIME) + @interface GrpcProxy { + } } diff --git a/grpc/api/src/main/java/io/helidon/grpc/api/GrpcChannel.java b/grpc/api/src/main/java/io/helidon/grpc/api/GrpcChannel.java deleted file mode 100644 index 4ecfc12264d..00000000000 --- a/grpc/api/src/main/java/io/helidon/grpc/api/GrpcChannel.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2024 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.helidon.grpc.api; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * An annotation that can be used to specify the name of a configured gRPC channel. - * channel to inject, or the name of the host to connect to, as described in - */ -@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PARAMETER}) -@Retention(RetentionPolicy.RUNTIME) -public @interface GrpcChannel { - - /** - * The name of the configured channel. - * - * @return name of the channel - */ - String value(); -} diff --git a/grpc/api/src/main/java/io/helidon/grpc/api/GrpcProxy.java b/grpc/api/src/main/java/io/helidon/grpc/api/GrpcProxy.java deleted file mode 100644 index d32a8ed9cbf..00000000000 --- a/grpc/api/src/main/java/io/helidon/grpc/api/GrpcProxy.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2024 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.helidon.grpc.api; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * An annotation used to mark an injection point for a gRPC service client proxy. - */ -@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) -@Retention(RetentionPolicy.RUNTIME) -public @interface GrpcProxy { -} diff --git a/microprofile/grpc/client/src/main/java/io/helidon/microprofile/grpc/client/ChannelProducer.java b/microprofile/grpc/client/src/main/java/io/helidon/microprofile/grpc/client/ChannelProducer.java index bd1fa73b209..bcfc6d675ac 100644 --- a/microprofile/grpc/client/src/main/java/io/helidon/microprofile/grpc/client/ChannelProducer.java +++ b/microprofile/grpc/client/src/main/java/io/helidon/microprofile/grpc/client/ChannelProducer.java @@ -21,7 +21,7 @@ import java.util.concurrent.locks.ReentrantLock; import io.helidon.config.Config; -import io.helidon.grpc.api.GrpcChannel; +import io.helidon.grpc.api.Grpc; import io.grpc.Channel; import jakarta.enterprise.context.ApplicationScoped; @@ -57,12 +57,12 @@ public class ChannelProducer { * @return a gRPC {@link io.grpc.Channel} */ @Produces - @GrpcChannel(value = GrpcChannelsProvider.DEFAULT_CHANNEL_NAME) + @Grpc.GrpcChannel(value = GrpcChannelsProvider.DEFAULT_CHANNEL_NAME) public Channel get(InjectionPoint injectionPoint) { - GrpcChannel qualifier = injectionPoint.getQualifiers() + Grpc.GrpcChannel qualifier = injectionPoint.getQualifiers() .stream() - .filter(q -> q.annotationType().equals(GrpcChannel.class)) - .map(q -> (GrpcChannel) q) + .filter(q -> q.annotationType().equals(Grpc.GrpcChannel.class)) + .map(q -> (Grpc.GrpcChannel) q) .findFirst() .orElse(null); diff --git a/microprofile/grpc/client/src/main/java/io/helidon/microprofile/grpc/client/GrpcClientBuilder.java b/microprofile/grpc/client/src/main/java/io/helidon/microprofile/grpc/client/GrpcClientBuilder.java index 572609ed4b4..baf4ce5ebaf 100644 --- a/microprofile/grpc/client/src/main/java/io/helidon/microprofile/grpc/client/GrpcClientBuilder.java +++ b/microprofile/grpc/client/src/main/java/io/helidon/microprofile/grpc/client/GrpcClientBuilder.java @@ -21,8 +21,7 @@ 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.api.Grpc; import io.helidon.grpc.core.MethodHandler; import io.helidon.microprofile.grpc.core.AbstractServiceBuilder; import io.helidon.microprofile.grpc.core.AnnotatedMethod; @@ -108,10 +107,10 @@ public ClientServiceDescriptor.Builder build() { * @param methodList the list of methods to add */ private void addServiceMethods(ClientServiceDescriptor.Builder builder, AnnotatedMethodList methodList) { - for (AnnotatedMethod am : methodList.withAnnotation(GrpcMethod.class)) { + for (AnnotatedMethod am : methodList.withAnnotation(Grpc.GrpcMethod.class)) { addServiceMethod(builder, am); } - for (AnnotatedMethod am : methodList.withMetaAnnotation(GrpcMethod.class)) { + for (AnnotatedMethod am : methodList.withMetaAnnotation(Grpc.GrpcMethod.class)) { addServiceMethod(builder, am); } } @@ -126,7 +125,7 @@ private void addServiceMethods(ClientServiceDescriptor.Builder builder, Annotate * @param method the {@link io.helidon.microprofile.grpc.core.AnnotatedMethod} representing the method to add */ private void addServiceMethod(ClientServiceDescriptor.Builder builder, AnnotatedMethod method) { - GrpcMethod annotation = method.firstAnnotationOrMetaAnnotation(GrpcMethod.class); + Grpc.GrpcMethod annotation = method.firstAnnotationOrMetaAnnotation(Grpc.GrpcMethod.class); String name = determineMethodName(method, annotation); MethodHandler handler = handlerSuppliers().stream() @@ -187,8 +186,9 @@ public void accept(ClientMethodDescriptor.Rules config) { .responseType(responseType) .methodHandler(methodHandler); - if (method.isAnnotationPresent(GrpcMarshaller.class)) { - config.marshallerSupplier(ModelHelper.getMarshallerSupplier(method.getAnnotation(GrpcMarshaller.class))); + if (method.isAnnotationPresent(Grpc.GrpcMarshaller.class)) { + config.marshallerSupplier(ModelHelper.getMarshallerSupplier( + method.getAnnotation(Grpc.GrpcMarshaller.class))); } } } diff --git a/microprofile/grpc/client/src/main/java/io/helidon/microprofile/grpc/client/GrpcClientCdiExtension.java b/microprofile/grpc/client/src/main/java/io/helidon/microprofile/grpc/client/GrpcClientCdiExtension.java index 4c2f28210db..d0ec1033a71 100644 --- a/microprofile/grpc/client/src/main/java/io/helidon/microprofile/grpc/client/GrpcClientCdiExtension.java +++ b/microprofile/grpc/client/src/main/java/io/helidon/microprofile/grpc/client/GrpcClientCdiExtension.java @@ -20,8 +20,7 @@ import java.util.HashSet; import java.util.Set; -import io.helidon.grpc.api.GrpcChannel; -import io.helidon.grpc.api.GrpcProxy; +import io.helidon.grpc.api.Grpc; import jakarta.enterprise.event.Observes; import jakarta.enterprise.inject.spi.AfterBeanDiscovery; @@ -54,7 +53,7 @@ public void addBeans(@Observes BeforeBeanDiscovery event) { /** * Process injection points. *
- * In this method injection points that have the {@link GrpcProxy} are processed
+ * In this method injection points that have the {@link io.helidon.grpc.api.Grpc.GrpcProxy} are processed
* and their types are stored so that in the {@link #afterBean(
*jakarta.enterprise.inject.spi.AfterBeanDiscovery, jakarta.enterprise.inject.spi.BeanManager)}
* we can manually create a producer for the correct service proxy type.
@@ -65,16 +64,16 @@ public void addBeans(@Observes BeforeBeanDiscovery event) {
*/
public
- * For each {@link GrpcProxy} injection point we create a producer bean
+ * For each {@link io.helidon.grpc.api.Grpc.GrpcProxy} injection point we create a producer bean
* for the required type.
*
* @param event the {@link jakarta.enterprise.inject.spi.AfterBeanDiscovery} event
@@ -84,8 +83,8 @@ public void afterBean(@Observes AfterBeanDiscovery event, BeanManager beanManage
AnnotatedType
* This is not a real producer method but is used as a stub by the gRPC client
@@ -48,17 +47,17 @@ private GrpcProxyProducer() {
* @param injectionPoint the injection point where the client proxy is to be injected
* @return a gRPC client proxy
*/
- @GrpcProxy
- @GrpcChannel(value = GrpcChannelsProvider.DEFAULT_CHANNEL_NAME)
+ @Grpc.GrpcProxy
+ @Grpc.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).value();
+ if (injectionPoint.getAnnotated().isAnnotationPresent(Grpc.GrpcChannel.class)) {
+ channelName = injectionPoint.getAnnotated().getAnnotation(Grpc.GrpcChannel.class).value();
} else {
- channelName = type.isAnnotationPresent(GrpcChannel.class)
- ? type.getAnnotation(GrpcChannel.class).value()
+ channelName = type.isAnnotationPresent(Grpc.GrpcChannel.class)
+ ? type.getAnnotation(Grpc.GrpcChannel.class).value()
: GrpcChannelsProvider.DEFAULT_CHANNEL_NAME;
}
diff --git a/microprofile/grpc/client/src/test/java/io/helidon/microprofile/grpc/client/EchoServiceTest.java b/microprofile/grpc/client/src/test/java/io/helidon/microprofile/grpc/client/EchoServiceTest.java
index 2584852f0b3..b30420d021f 100644
--- a/microprofile/grpc/client/src/test/java/io/helidon/microprofile/grpc/client/EchoServiceTest.java
+++ b/microprofile/grpc/client/src/test/java/io/helidon/microprofile/grpc/client/EchoServiceTest.java
@@ -24,10 +24,6 @@
import io.helidon.common.configurable.Resource;
import io.helidon.common.tls.Tls;
import io.helidon.grpc.api.Grpc;
-import io.helidon.grpc.api.GrpcChannel;
-import io.helidon.grpc.api.GrpcMarshaller;
-import io.helidon.grpc.api.GrpcProxy;
-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;
@@ -54,7 +50,7 @@ class EchoServiceTest {
private WebTarget webTarget;
@Inject
- @GrpcProxy
+ @Grpc.GrpcProxy
private EchoServiceClient proxyClient;
@Test
@@ -118,11 +114,11 @@ public void onCompleted() {
assertThat(future.get(5, TimeUnit.SECONDS), is("Howdy"));
}
- @Grpc
- @GrpcMarshaller("java")
+ @Grpc.GrpcService
+ @Grpc.GrpcMarshaller("java")
public static class EchoService {
- @Unary("Echo")
+ @Grpc.Unary("Echo")
public void echo(String request, StreamObserver