mirror of https://github.com/grpc/grpc-java.git
Use Providers in examples
This commit is contained in:
parent
bccaf07497
commit
41d93cfd59
|
|
@ -32,11 +32,11 @@
|
|||
package io.grpc.examples.header;
|
||||
|
||||
import io.grpc.Server;
|
||||
import io.grpc.ServerBuilder;
|
||||
import io.grpc.ServerInterceptors;
|
||||
import io.grpc.examples.helloworld.GreeterGrpc;
|
||||
import io.grpc.examples.helloworld.HelloRequest;
|
||||
import io.grpc.examples.helloworld.HelloResponse;
|
||||
import io.grpc.netty.NettyServerBuilder;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
|
@ -53,9 +53,11 @@ public class CustomHeaderServer {
|
|||
private Server server;
|
||||
|
||||
private void start() throws Exception {
|
||||
server = NettyServerBuilder.forPort(port).addService(ServerInterceptors
|
||||
.intercept(GreeterGrpc.bindService(new GreeterImpl()), new HeaderServerInterceptor()))
|
||||
.build().start();
|
||||
server = ServerBuilder.forPort(port)
|
||||
.addService(ServerInterceptors.intercept(
|
||||
GreeterGrpc.bindService(new GreeterImpl()), new HeaderServerInterceptor()))
|
||||
.build()
|
||||
.start();
|
||||
logger.info("Server started, listening on " + port);
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
package io.grpc.examples.helloworld;
|
||||
|
||||
import io.grpc.Server;
|
||||
import io.grpc.netty.NettyServerBuilder;
|
||||
import io.grpc.ServerBuilder;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
|
@ -48,9 +48,10 @@ public class HelloWorldServer {
|
|||
private Server server;
|
||||
|
||||
private void start() throws Exception {
|
||||
server = NettyServerBuilder.forPort(port)
|
||||
server = ServerBuilder.forPort(port)
|
||||
.addService(GreeterGrpc.bindService(new GreeterImpl()))
|
||||
.build().start();
|
||||
.build()
|
||||
.start();
|
||||
logger.info("Server started, listening on " + port);
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ import static java.lang.Math.toRadians;
|
|||
import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
||||
|
||||
import io.grpc.Server;
|
||||
import io.grpc.netty.NettyServerBuilder;
|
||||
import io.grpc.ServerBuilder;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -63,7 +63,7 @@ public class RouteGuideServer {
|
|||
|
||||
private final int port;
|
||||
private final Collection<Feature> features;
|
||||
private Server grpcServer;
|
||||
private Server server;
|
||||
|
||||
public RouteGuideServer(int port) {
|
||||
this(port, RouteGuideUtil.getDefaultFeaturesFile());
|
||||
|
|
@ -81,9 +81,10 @@ public class RouteGuideServer {
|
|||
|
||||
/** Start serving requests. */
|
||||
public void start() throws IOException {
|
||||
grpcServer = NettyServerBuilder.forPort(port)
|
||||
server = ServerBuilder.forPort(port)
|
||||
.addService(RouteGuideGrpc.bindService(new RouteGuideService(features)))
|
||||
.build().start();
|
||||
.build()
|
||||
.start();
|
||||
logger.info("Server started, listening on " + port);
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
|
|
@ -98,8 +99,8 @@ public class RouteGuideServer {
|
|||
|
||||
/** Stop serving requests and shutdown resources. */
|
||||
public void stop() {
|
||||
if (grpcServer != null) {
|
||||
grpcServer.shutdown();
|
||||
if (server != null) {
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -107,8 +108,8 @@ public class RouteGuideServer {
|
|||
* Await termination on the main thread since the grpc library uses daemon threads.
|
||||
*/
|
||||
private void blockUntilShutdown() throws InterruptedException {
|
||||
if (grpcServer != null) {
|
||||
grpcServer.awaitTermination();
|
||||
if (server != null) {
|
||||
server.awaitTermination();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -181,7 +181,6 @@ public final class NettyChannelBuilder
|
|||
}
|
||||
|
||||
private ProtocolNegotiator createProtocolNegotiator() {
|
||||
ProtocolNegotiator negotiator;
|
||||
switch (negotiationType) {
|
||||
case PLAINTEXT:
|
||||
return ProtocolNegotiators.plaintext();
|
||||
|
|
|
|||
Loading…
Reference in New Issue