Skip to content

Commit 65bd4aa

Browse files
committed
Add javadocs
1 parent 3f42880 commit 65bd4aa

File tree

10 files changed

+154
-6
lines changed

10 files changed

+154
-6
lines changed

examples/cloud-eureka-server/src/main/java/net/devh/boot/grpc/examples/cloud/server/EurekaServerApplication.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,19 @@
2121
import org.springframework.boot.autoconfigure.SpringBootApplication;
2222
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
2323

24+
/**
25+
* Eureka cloud discovery server application.
26+
*/
2427
@EnableEurekaServer
2528
@SpringBootApplication
2629
public class EurekaServerApplication {
2730

28-
public static void main(String[] args) {
31+
/**
32+
* Starts the Eureka cloud discovery server application.
33+
*
34+
* @param args The arguments to pass to the application.
35+
*/
36+
public static void main(final String... args) {
2937
SpringApplication.run(EurekaServerApplication.class, args);
3038
}
3139

examples/cloud-grpc-client/src/main/java/net/devh/boot/grpc/examples/cloud/client/CloudClientApplication.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@
2121
import org.springframework.boot.autoconfigure.SpringBootApplication;
2222
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
2323

24+
/**
25+
* Example grpc client application using cloud discovery.
26+
*/
2427
@EnableDiscoveryClient
2528
@SpringBootApplication
2629
public class CloudClientApplication {
2730

31+
/**
32+
* Starts the grpc cloud discovery client application.
33+
*
34+
* @param args The arguments to pass to the application.
35+
*/
2836
public static void main(final String... args) {
2937
SpringApplication.run(CloudClientApplication.class, args);
3038
}
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,23 @@
1818
package net.devh.boot.grpc.examples.cloud.client;
1919

2020
import org.springframework.context.annotation.Configuration;
21-
import org.springframework.core.Ordered;
22-
import org.springframework.core.annotation.Order;
2321

22+
import io.grpc.ClientInterceptor;
2423
import net.devh.boot.grpc.client.interceptor.GrpcGlobalClientInterceptor;
2524

26-
@Order(Ordered.LOWEST_PRECEDENCE)
25+
/**
26+
* Example configuration class that adds a {@link ClientInterceptor} to the global interceptor list.
27+
*/
2728
@Configuration(proxyBeanMethods = false)
28-
public class GlobalClientInterceptorConfiguration {
29+
public class GlobalInterceptorConfiguration {
2930

31+
/**
32+
* Creates a new {@link LogGrpcInterceptor} bean and adds it to the global interceptor list. As an alternative you
33+
* can directly annotate the {@code LogGrpcInterceptor} class and it will automatically be picked up by spring's
34+
* classpath scanning.
35+
*
36+
* @return The newly created bean.
37+
*/
3038
@GrpcGlobalClientInterceptor
3139
LogGrpcInterceptor logClientInterceptor() {
3240
return new LogGrpcInterceptor();

examples/cloud-grpc-client/src/main/java/net/devh/boot/grpc/examples/cloud/client/GrpcClientController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.springframework.web.bind.annotation.RestController;
2424

2525
/**
26-
* Optional demo controller making the grpc service accessible via browser.
26+
* Optional demo controller making the grpc service accessible via browser requests.
2727
*/
2828
@RestController
2929
public class GrpcClientController {

examples/cloud-grpc-client/src/main/java/net/devh/boot/grpc/examples/cloud/client/GrpcClientService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import net.devh.boot.grpc.examples.lib.HelloRequest;
2727
import net.devh.boot.grpc.examples.lib.SimpleGrpc.SimpleBlockingStub;
2828

29+
/**
30+
* Example class demonstrating the usage of {@link GrpcClient}s inside an application.
31+
*/
2932
@Service
3033
@Slf4j
3134
public class GrpcClientService {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2016-2021 Michael Zhang <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package net.devh.boot.grpc.examples.cloud.client;
19+
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
23+
import io.grpc.CallOptions;
24+
import io.grpc.Channel;
25+
import io.grpc.ClientCall;
26+
import io.grpc.ClientInterceptor;
27+
import io.grpc.MethodDescriptor;
28+
import net.devh.boot.grpc.client.interceptor.GrpcGlobalClientInterceptor;
29+
30+
/**
31+
* Example {@link ClientInterceptor} that logs all called methods. In this example it is added to Spring's application
32+
* context via {@link GlobalInterceptorConfiguration}, but is also possible to directly annotate this class with
33+
* {@link GrpcGlobalClientInterceptor}.
34+
*/
35+
// @GrpcGlobalClientInterceptor
36+
public class LogGrpcInterceptor implements ClientInterceptor {
37+
38+
private static final Logger log = LoggerFactory.getLogger(LogGrpcInterceptor.class);
39+
40+
@Override
41+
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
42+
final MethodDescriptor<ReqT, RespT> method,
43+
final CallOptions callOptions,
44+
final Channel next) {
45+
46+
log.info(method.getFullMethodName());
47+
return next.newCall(method, callOptions);
48+
}
49+
50+
}

examples/cloud-grpc-server/src/main/java/net/devh/boot/grpc/examples/cloud/server/CloudServerApplication.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@
2121
import org.springframework.boot.autoconfigure.SpringBootApplication;
2222
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
2323

24+
/**
25+
* Example grpc service application supporting cloud discovery.
26+
*/
2427
@EnableDiscoveryClient
2528
@SpringBootApplication
2629
public class CloudServerApplication {
2730

31+
/**
32+
* Starts the grpc cloud server application.
33+
*
34+
* @param args The arguments to pass to the application.
35+
*/
2836
public static void main(final String... args) {
2937
SpringApplication.run(CloudServerApplication.class, args);
3038
}

examples/cloud-grpc-server/src/main/java/net/devh/boot/grpc/examples/cloud/server/GlobalInterceptorConfiguration.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,22 @@
1919

2020
import org.springframework.context.annotation.Configuration;
2121

22+
import io.grpc.ServerInterceptor;
2223
import net.devh.boot.grpc.server.interceptor.GrpcGlobalServerInterceptor;
2324

25+
/**
26+
* Example configuration class that adds a {@link ServerInterceptor} to the global interceptor list.
27+
*/
2428
@Configuration(proxyBeanMethods = false)
2529
public class GlobalInterceptorConfiguration {
2630

31+
/**
32+
* Creates a new {@link LogGrpcInterceptor} bean and adds it to the global interceptor list. As an alternative you
33+
* can directly annotate the {@code LogGrpcInterceptor} class and it will automatically be picked up by spring's
34+
* classpath scanning.
35+
*
36+
* @return The newly created bean.
37+
*/
2738
@GrpcGlobalServerInterceptor
2839
LogGrpcInterceptor logServerInterceptor() {
2940
return new LogGrpcInterceptor();

examples/cloud-grpc-server/src/main/java/net/devh/boot/grpc/examples/cloud/server/GrpcServerService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
import net.devh.boot.grpc.examples.lib.SimpleGrpc;
2424
import net.devh.boot.grpc.server.service.GrpcService;
2525

26+
/**
27+
* Example grpc server service implementation class.
28+
*/
2629
@GrpcService
2730
public class GrpcServerService extends SimpleGrpc.SimpleImplBase {
2831

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2016-2021 Michael Zhang <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package net.devh.boot.grpc.examples.cloud.server;
19+
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
23+
import io.grpc.Metadata;
24+
import io.grpc.ServerCall;
25+
import io.grpc.ServerCallHandler;
26+
import io.grpc.ServerInterceptor;
27+
import net.devh.boot.grpc.server.interceptor.GrpcGlobalServerInterceptor;
28+
29+
/**
30+
* Example {@link ServerInterceptor} that logs all called methods. In this example it is added to Spring's application
31+
* context via {@link GlobalInterceptorConfiguration}, but is also possible to directly annotate this class with
32+
* {@link GrpcGlobalServerInterceptor}.
33+
*/
34+
// @GrpcGlobalServerInterceptor
35+
public class LogGrpcInterceptor implements ServerInterceptor {
36+
37+
private static final Logger log = LoggerFactory.getLogger(LogGrpcInterceptor.class);
38+
39+
@Override
40+
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
41+
ServerCall<ReqT, RespT> serverCall,
42+
Metadata metadata,
43+
ServerCallHandler<ReqT, RespT> serverCallHandler) {
44+
45+
log.info(serverCall.getMethodDescriptor().getFullMethodName());
46+
return serverCallHandler.startCall(serverCall, metadata);
47+
}
48+
49+
}

0 commit comments

Comments
 (0)