Java Code Examples for io.grpc.ServerBuilder

The following are top voted examples for showing how to use io.grpc.ServerBuilder. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: neo_grpc   File: RegistergRPCExtensionFactory.java   Source Code and License 7 votes vote down vote up
@Override
public Lifecycle newInstance(KernelContext kernelContext, final Dependencies dependencies) throws Throwable {
    return new LifecycleAdapter() {

        private Server server;

        @Override
        public void start() throws Throwable {
            server  = ServerBuilder.forPort(9999).addService(new Neo4jGRPCService(dependencies.getGraphDatabaseService())).build();
            server.start();
            System.out.println("Started gRPC Server.");
        }

        @Override
        public void shutdown() throws Throwable {
            server.shutdown();
        }
    };
}
 
Example 2
Project: rejoiner   File: HelloWorldServer.java   Source Code and License 6 votes vote down vote up
private void start() throws IOException {
  /* The port on which the server should run */
  int port = 50051;
  server = ServerBuilder.forPort(port).addService(new GreeterImpl()).build().start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime()
      .addShutdownHook(
          new Thread() {
            @Override
            public void run() {
              // Use stderr here since the logger may have been reset by its JVM shutdown hook.
              System.err.println("*** shutting down gRPC server since JVM is shutting down");
              HelloWorldServer.this.stop();
              System.err.println("*** server shut down");
            }
          });
}
 
Example 3
Project: rejoiner   File: GraphQlGrpcServer.java   Source Code and License 6 votes vote down vote up
private void start() throws IOException {
  /* The port on which the server should run */
  int port = 8888;
  server = ServerBuilder.forPort(port).addService(new GraphQlServiceImpl()).build().start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime()
      .addShutdownHook(
          new Thread() {
            @Override
            public void run() {
              // Use stderr here since the logger may have been reset by its JVM shutdown hook.
              System.err.println("*** shutting down gRPC server since JVM is shutting down");
              GraphQlGrpcServer.this.stop();
              System.err.println("*** server shut down");
            }
          });
}
 
Example 4
Project: rejoiner   File: HelloWorldServer.java   Source Code and License 6 votes vote down vote up
private void start() throws IOException {
  /* The port on which the server should run */
  int port = 50051;
  server = ServerBuilder.forPort(port).addService(new GreeterImpl()).build().start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime()
      .addShutdownHook(
          new Thread() {
            @Override
            public void run() {
              // Use stderr here since the logger may have been reset by its JVM shutdown hook.
              System.err.println("*** shutting down gRPC server since JVM is shutting down");
              HelloWorldServer.this.stop();
              System.err.println("*** server shut down");
            }
          });
}
 
Example 5
Project: graphflow   File: GraphflowServer.java   Source Code and License 6 votes vote down vote up
public void start() throws IOException {
    System.err.println("*** starting gRPC server...");
    grpcServer = ServerBuilder.forPort(GRPC_PORT).addService(new GraphflowQueryImpl()).build().
        start();
    System.err.println("*** gRPC server running.");

    System.err.println("*** starting http server...");
    final PlanViewerHttpServer graphflowUIHttpServer = new PlanViewerHttpServer(GRPC_HOST,
        GRPC_PORT);
    graphflowUIHttpServer.start();
    System.err.println("*** http server running.");

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            System.err.println("*** shutting down gRPC grpcServer...");
            GraphflowServer.this.stop();
            System.err.println("*** grpcServer shut down.");
        }
    });
}
 
Example 6
Project: devicehub   File: DeviceHubServer.java   Source Code and License 6 votes vote down vote up
/**
 * Starts the server
 * @param port the port that the server listens to
 * @throws IOException
 * @throws IllegalStateException
 */
private void start(int port) throws IOException {

  deviceHubImpl = new DeviceHubImpl();
  try {
    server = ServerBuilder.forPort(port).addService(deviceHubImpl).build().start();
  } catch (IOException | IllegalStateException e) {
    stop();
    throw e;
  }
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime()
      .addShutdownHook(
          new Thread() {
            @Override
            public void run() {
              // Use stderr here since the logger may have been reset by its JVM shutdown hook.
              System.err.println("*** shutting down gRPC server since JVM is shutting down");
              DeviceHubServer.this.stop();
              System.err.println("*** server shut down");
            }
          });
}
 
Example 7
Project: africastalking-java   File: Server.java   Source Code and License 6 votes vote down vote up
public void start(File certChainFile, File privateKeyFile, int port) throws IOException {
    ServerBuilder builder = ServerBuilder.forPort(port).useTransportSecurity(certChainFile, privateKeyFile);
    if (mAuthenticator != null) {
        builder.addService(ServerInterceptors.intercept(
            mSdkService, new AuthenticationInterceptor(this.mAuthenticator)));
    } else {
        builder.addService(mSdkService);
    }
    mGrpc = builder.build();
    mGrpc.start();
}
 
Example 8
Project: grpc-java-contrib   File: CompletableFutureEndToEndTest.java   Source Code and License 6 votes vote down vote up
@Test
public void serverRunsAndRespondsCorrectly() throws ExecutionException,
        IOException,
        InterruptedException,
        TimeoutException {
    final String name = UUID.randomUUID().toString();

    Server server = ServerBuilder.forPort(9999)
            .addService(new GreeterImpl())
            .build();

    server.start();

    ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", server.getPort())
            .usePlaintext(true)
            .build();

    GreeterGrpc8.GreeterCompletableFutureStub stub = GreeterGrpc8.newCompletableFutureStub(channel);

    CompletableFuture<HelloResponse> response = stub.sayHello(HelloRequest.newBuilder().setName(name).build());

    await().atMost(3, TimeUnit.SECONDS).until(() -> response.isDone() && response.get().getMessage().contains(name));

    channel.shutdown();
    channel.awaitTermination(1, TimeUnit.MINUTES);
    channel.shutdownNow();

    server.shutdown();
    server.awaitTermination(1, TimeUnit.MINUTES);
    server.shutdownNow();
}
 
Example 9
Project: seldon-core   File: SeldonGrpcServer.java   Source Code and License 6 votes vote down vote up
@Autowired
public SeldonGrpcServer(PredictionService predictionService)
{
    { // setup the server port using the env vars
        String engineServerPortString = System.getenv().get(ENGINE_SERVER_PORT_KEY);
        if (engineServerPortString == null) {
            logger.error("FAILED to find env var [{}], will use defaults for engine server port {}", ENGINE_SERVER_PORT_KEY,SERVER_PORT);
            port = SERVER_PORT;
        } else {
            port = Integer.parseInt(engineServerPortString);
            logger.info("FOUND env var [{}], will use engine server port {}", ENGINE_SERVER_PORT_KEY,port);
        }
    }
    this.predictionService = predictionService;
    server = ServerBuilder
            .forPort(port)
            .addService(new SeldonService(this))
      .build();
}
 
Example 10
Project: grpcx   File: Provider.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
	
	Server server=ServerBuilder.forPort(Config.getLocalPortProvider())
					.addService(new AddService())
					.build();
	try {
		server.start();
		
		ProviderBootstrap.init();
		
		server.awaitTermination();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
Example 11
Project: book_ldrtc   File: HelloJsonServer.java   Source Code and License 6 votes vote down vote up
private void start() throws IOException {
  server = ServerBuilder.forPort(port)
      .addService(bindService(new GreeterImpl()))
      .build()
      .start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      HelloJsonServer.this.stop();
      System.err.println("*** server shut down");
    }
  });
}
 
Example 12
Project: book_ldrtc   File: CustomHeaderServer.java   Source Code and License 6 votes vote down vote up
private void start() throws IOException {
  server = ServerBuilder.forPort(port)
      .addService(ServerInterceptors.intercept(new GreeterImpl(), new HeaderServerInterceptor()))
      .build()
      .start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      CustomHeaderServer.this.stop();
      System.err.println("*** server shut down");
    }
  });
}
 
Example 13
Project: whatsmars   File: HelloWorldServer.java   Source Code and License 6 votes vote down vote up
private void start() throws IOException {
    server = ServerBuilder.forPort(port)
            .addService(new HelloServiceImpl())
            .build()
            .start();

    System.out.println("service start...");

    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {

            System.err.println("*** shutting down gRPC server since JVM is shutting down");
            HelloWorldServer.this.stop();
            System.err.println("*** server shut down");
        }
    });
}
 
Example 14
Project: grpc-java-by-example   File: RxMetricsServer.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException {
  RxMetricsServiceGrpc.MetricsServiceImplBase service = new RxMetricsServiceGrpc.MetricsServiceImplBase() {

    @Override
    public Single<Streaming.Average> collect(Flowable<Streaming.Metric> request) {
      return request.map(m -> m.getMetric())
          .map(m -> new State(m, 1))
          .reduce((a, b) -> new State(a.sum + b.sum, a.count + b.count))
          .map(s -> Streaming.Average.newBuilder().setVal(s.sum / s.count).build())
          .toSingle();
    }
  };

  Server server = ServerBuilder.forPort(8080)
      .addService(service)
      .build();

  server.start();
  server.awaitTermination();
}
 
Example 15
Project: grpc-java-gradle-hello-world   File: HelloWorldServer.java   Source Code and License 6 votes vote down vote up
private void start() throws Exception {
    logger.info("Starting the grpc server");

    server = ServerBuilder.forPort(port)
            .addService(new GreeterImpl())
            .build()
            .start();

    logger.info("Server started. Listening on port " + port);

    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        System.err.println("*** JVM is shutting down. Turning off grpc server as well ***");
        HelloWorldServer.this.stop();
        System.err.println("*** shutdown complete ***");
    }));
}
 
Example 16
Project: grpc   File: Backend.java   Source Code and License 6 votes vote down vote up
private void start(int id) throws IOException {
    server = ServerBuilder.forPort((port + id))
            .addService(new GoogleImpl(id))
            .build()
            .start();
    logger.info("Server started, listening on " + (port + id));
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            // Use stderr here since the logger may have been reset by its JVM shutdown hook.
            System.err.println("*** shutting down gRPC server since JVM is shutting down");
            Backend.this.stop();
            System.err.println("*** server shut down");
        }
    });
}
 
Example 17
Project: yarpc-java   File: EchoServer.java   Source Code and License 6 votes vote down vote up
/** Starts the server. */
public void start() throws IOException {
  /* The port on which the server should run */
  int port = 8089;
  server = ServerBuilder.forPort(port).addService(new EchoProtoHandler()).build().start();
  log.info("Server started, listening on " + port);
  Runtime.getRuntime()
      .addShutdownHook(
          new Thread() {
            @Override
            public void run() {
              log.error("*** shutting down gRPC server since JVM is shutting down");
              EchoServer.this.stop();
              log.error("*** server shut down");
            }
          });
}
 
Example 18
Project: java-docs-samples   File: HelloWorldServer.java   Source Code and License 6 votes vote down vote up
private void start() throws IOException {
  server = ServerBuilder.forPort(port)
      .addService(new GreeterImpl())
      .build()
      .start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      HelloWorldServer.this.stop();
      System.err.println("*** server shut down");
    }
  });
}
 
Example 19
Project: h2o-3   File: GrpcExtension.java   Source Code and License 6 votes vote down vote up
@Override
public void onLocalNodeStarted() {
  if (grpcPort != 0) {
    ServerBuilder sb = ServerBuilder.forPort(grpcPort);
    RegisterGrpcApi.registerWithServer(sb);
    netty = sb.build();
    try {
      netty.start();
      Log.info("Started GRPC server on localhost:" + grpcPort);
    } catch (IOException e) {
      netty = null;
      throw new RuntimeException("Failed to start the GRPC server on port " + grpcPort, e);
    }
    Runtime.getRuntime().addShutdownHook(new Thread() {
      @Override
      public void run() {
        if (netty != null) {
          // Use stderr here since the logger may have been reset by its JVM shutdown hook.
          System.err.println("*** shutting down gRPC server since JVM is shutting down");
          netty.shutdown();
          System.err.println("*** server shut down");
        }
      }
    });
  }
}
 
Example 20
Project: grpc-java   File: HelloWorldServer.java   Source Code and License 6 votes vote down vote up
private void start() throws IOException {
  /* The port on which the server should run */
  int port = 50051;
  server = ServerBuilder.forPort(port)
      .addService(new GreeterImpl())
      .build()
      .start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      HelloWorldServer.this.stop();
      System.err.println("*** server shut down");
    }
  });
}
 
Example 21
Project: grpc-java   File: CustomHeaderServer.java   Source Code and License 6 votes vote down vote up
private void start() throws IOException {
  server = ServerBuilder.forPort(PORT)
      .addService(ServerInterceptors.intercept(new GreeterImpl(), new HeaderServerInterceptor()))
      .build()
      .start();
  logger.info("Server started, listening on " + PORT);
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      CustomHeaderServer.this.stop();
      System.err.println("*** server shut down");
    }
  });
}
 
Example 22
Project: grpc-java   File: HelloJsonServer.java   Source Code and License 6 votes vote down vote up
private void start() throws IOException {
  /* The port on which the server should run */
  int port = 50051;
  server = ServerBuilder.forPort(port)
      .addService(new GreeterImpl())
      .build()
      .start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      HelloJsonServer.this.stop();
      System.err.println("*** server shut down");
    }
  });
}
 
Example 23
Project: grpc-java   File: ErrorHandlingClient.java   Source Code and License 6 votes vote down vote up
void run() throws Exception {
  // Port 0 means that the operating system will pick an available port to use.
  Server server = ServerBuilder.forPort(0).addService(new GreeterGrpc.GreeterImplBase() {
    @Override
    public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
      responseObserver.onError(Status.INTERNAL
          .withDescription("Eggplant Xerxes Crybaby Overbite Narwhal").asRuntimeException());
    }
  }).build().start();
  channel =
      ManagedChannelBuilder.forAddress("localhost", server.getPort()).usePlaintext(true).build();

  blockingCall();
  futureCallDirect();
  futureCallCallback();
  asyncCall();
  advancedAsyncCall();

  channel.shutdown();
  server.shutdown();
  channel.awaitTermination(1, TimeUnit.SECONDS);
  server.awaitTermination();
}
 
Example 24
Project: grpc-java   File: DetailErrorSample.java   Source Code and License 6 votes vote down vote up
void run() throws Exception {
  Server server = ServerBuilder.forPort(0).addService(new GreeterGrpc.GreeterImplBase() {
    @Override
    public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
      Metadata trailers = new Metadata();
      trailers.put(DEBUG_INFO_TRAILER_KEY, DEBUG_INFO);
      responseObserver.onError(Status.INTERNAL.withDescription(DEBUG_DESC)
          .asRuntimeException(trailers));
    }
  }).build().start();
  channel =
      ManagedChannelBuilder.forAddress("localhost", server.getPort()).usePlaintext(true).build();

  blockingCall();
  futureCallDirect();
  futureCallCallback();
  asyncCall();
  advancedAsyncCall();

  channel.shutdown();
  server.shutdown();
  channel.awaitTermination(1, TimeUnit.SECONDS);
  server.awaitTermination();
}
 
Example 25
Project: muckery   File: GrpcTest.java   Source Code and License 6 votes vote down vote up
@Before
public void setUp() throws Exception {

    final int port = NetUtil.findUnusedPort();
    this.server = ServerBuilder.forPort(port)
                               .executor(this.exec)
                               .addService(new HelloService())
                               .build()
                               .start();


    this.channel = ManagedChannelBuilder.forAddress("127.0.0.1", port)
                                        .executor(this.exec)
                                        .usePlaintext(true)
                                        .build();
}
 
Example 26
Project: grpc-samples-java   File: ChatServer.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException, IOException {

        // Build server
        Server server = ServerBuilder.forPort(SERVER_PORT)
                .addService(new ChatServiceImpl())
                .build();

        // Start server
        System.out.println("Starting server on port " + SERVER_PORT);
        server.start();

        // Keep it running
        System.out.println("Server started!");
        server.awaitTermination();
    }
 
Example 27
Project: grpc-samples-java   File: GreeterServer.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException {

        // Build server
        Server server = ServerBuilder.forPort(SERVER_PORT)
                .addService(new GreetingServiceImpl())
                .build();

        // Start server
        System.out.println("Starting GreeterServer on port " + SERVER_PORT);
        server.start();

        // Keep it running
        System.out.println("GreeterServer started!");
        server.awaitTermination();
    }
 
Example 28
Project: rejoiner   File: ShelfServer.java   Source Code and License 5 votes vote down vote up
private void start() throws IOException {
  /* The port on which the server should run */
  int port = 50052;
  server = ServerBuilder.forPort(port).addService(new ShelfService()).build().start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime()
      .addShutdownHook(
          new Thread(
              () -> {
                // Use stderr here since the logger may have been reset by its JVM shutdown hook.
                System.err.println("*** shutting down gRPC server since JVM is shutting down");
                ShelfServer.this.stop();
                System.err.println("*** server shut down");
              }));
}
 
Example 29
Project: rejoiner   File: BookServer.java   Source Code and License 5 votes vote down vote up
private void start() throws IOException {
  /* The port on which the server should run */
  int port = 50051;
  server = ServerBuilder.forPort(port).addService(new BookService()).build().start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime()
      .addShutdownHook(
          new Thread(
              () -> {
                // Use stderr here since the logger may have been reset by its JVM shutdown hook.
                System.err.println("*** shutting down gRPC server since JVM is shutting down");
                BookServer.this.stop();
                System.err.println("*** server shut down");
              }));
}
 
Example 30
Project: incubator-servicecomb-saga   File: LoadBalancedClusterMessageSenderTest.java   Source Code and License 5 votes vote down vote up
private static void startServerOnPort(int port) {
  ServerBuilder<?> serverBuilder = ServerBuilder.forPort(port);
  serverBuilder.addService(new MyTxEventService(connected.get(port), eventsMap.get(port), delays.get(port)));
  Server server = serverBuilder.build();

  try {
    server.start();
    servers.put(port, server);
  } catch (IOException e) {
    fail(e.getMessage());
  }
}
 
Example 31
Project: spring-remoting-grpc   File: GrpcInvokerServiceExporter.java   Source Code and License 5 votes vote down vote up
private void start() throws IOException {
    server = ServerBuilder.forPort(port).addService(new RemotingServiceImpl(this)).build().start();
    logger.info("Server started on port " + port);

    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            GrpcInvokerServiceExporter.this.stop();
        }
    });
}
 
Example 32
Project: rpc-comparison   File: FunctionTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testSyncFunctions() throws IOException, InterruptedException {
    ServerBuilder.forPort(port);
    AskerServer server = new AskerServer();

    try {
        server.start();

        AskerClient client = new AskerClient();
        AskerBlockingStub blockingStub = client.blockingStub;

        SyncHelper helper = new SyncHelper(collector);

        helper.checkEcho(blockingStub);
        helper.checkCount(blockingStub);
        helper.checkReverse(blockingStub);
        helper.checkUpperCast(blockingStub);
        helper.checkLowerCast(blockingStub);

        helper.checkRandom(blockingStub, 5 + random.nextInt(10));

    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
 
Example 33
Project: rpc-comparison   File: FunctionTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testAsyncFunctions() throws IOException, InterruptedException, ExecutionException {
    ServerBuilder.forPort(port);
    AskerServer server = new AskerServer();

    try {
        server.start();

        AskerClient client = new AskerClient();
        AskerStub stub = client.asyncStub;

        AsyncHelper helper = new AsyncHelper(collector);

        helper.checkEcho(stub);
        helper.checkCount(stub);
        helper.checkReverse(stub);
        helper.checkUpperCast(stub);
        helper.checkLowerCast(stub);

        helper.checkRandom(stub, 5 + random.nextInt(10));

    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
 
Example 34
Project: tikv-client-lib-java   File: PDMockServer.java   Source Code and License 5 votes vote down vote up
public void start(long clusterId) throws IOException {
  try (ServerSocket s = new ServerSocket(0)) {
    port = s.getLocalPort();
  }
  this.clusterId = clusterId;
  server = ServerBuilder.forPort(port).addService(this).build().start();

  Runtime.getRuntime().addShutdownHook(new Thread(PDMockServer.this::stop));
}
 
Example 35
Project: tikv-client-lib-java   File: KVMockServer.java   Source Code and License 5 votes vote down vote up
public int start(TiRegion region) throws IOException {
  try (ServerSocket s = new ServerSocket(0)) {
    port = s.getLocalPort();
  }
  server = ServerBuilder.forPort(port).addService(this).build().start();

  this.region = region;
  Runtime.getRuntime().addShutdownHook(new Thread(KVMockServer.this::stop));
  return port;
}
 
Example 36
Project: africastalking-java   File: Server.java   Source Code and License 5 votes vote down vote up
public void startInsecure(int port) throws IOException {
    ServerBuilder builder = ServerBuilder.forPort(port);
    if (mAuthenticator != null) {
        builder.addService(ServerInterceptors.intercept(
            mSdkService, new AuthenticationInterceptor(this.mAuthenticator)));
    } else {
        builder.addService(mSdkService);
    }
    mGrpc = builder.build();
    mGrpc.start();
}
 
Example 37
Project: grpc-java-contrib   File: SimpleGrpcServerFactory.java   Source Code and License 5 votes vote down vote up
@Override
public Server buildServerForServices(int port, Collection<BindableService> services) {
    ServerBuilder builder = ServerBuilder.forPort(port);
    setupServer(builder);
    services.forEach(service -> registerService(builder, service));
    return builder.build();
}
 
Example 38
Project: seldon-core   File: SeldonGrpcServer.java   Source Code and License 5 votes vote down vote up
public SeldonGrpcServer(AppProperties appProperties,DeploymentStore deploymentStore,TokenStore tokenStore,ServerBuilder<?> serverBuilder,DeploymentsHandler deploymentsHandler, int port) 
{
    this.appProperties = appProperties;
    this.deploymentStore = deploymentStore;
    this.tokenStore = tokenStore;
    this.grpcDeploymentsListener = new grpcDeploymentsListener(this);
    this.deploymentsHandler = deploymentsHandler;
    deploymentsHandler.addListener(this.grpcDeploymentsListener);
    this.port = port;
    server = serverBuilder
          .addService(ServerInterceptors.intercept(new SeldonService(this), new HeaderServerInterceptor(this)))
      .build();
}
 
Example 39
Project: seldon-core   File: FakeEngineServer.java   Source Code and License 5 votes vote down vote up
public FakeEngineServer() 
{
    server = ServerBuilder
                .forPort(PORT)
                .addService(new FakeSeldonEngineService())
                .build();
}
 
Example 40
Project: rpc-thunderdome   File: GrpcServer.java   Source Code and License 5 votes vote down vote up
public static void main(String... args) throws Exception {
  System.out.println("starting server");


  String host = System.getProperty("host", "127.0.0.1");
  int port = Integer.getInteger("port", 8001);

  io.grpc.Server start = ServerBuilder.forPort(port)
                             .addService(new DefaultService())
                             .build()
                             .start();

  System.out.println("server started");
  start.awaitTermination();
}
 
Example 41
Project: bazel-buildfarm   File: BuildFarmServer.java   Source Code and License 5 votes vote down vote up
public BuildFarmServer(ServerBuilder<?> serverBuilder, BuildFarmServerConfig config) {
  this.config = config;
  String defaultInstanceName = config.getDefaultInstanceName();
  instances = new BuildFarmInstances(config.getInstancesList(), defaultInstanceName);
  server = serverBuilder
      .addService(new ActionCacheService(instances))
      .addService(new ContentAddressableStorageService(instances))
      .addService(new ByteStreamService(instances))
      .addService(new ExecutionService(instances))
      .addService(new OperationQueueService(instances))
      .addService(new OperationsService(instances))
      .addService(new WatcherService(instances))
      .build();
}
 
Example 42
Project: smesh   File: GrpcServerFactoryImpl.java   Source Code and License 5 votes vote down vote up
@Override
public Server create(ClusterConfig config) {
    return ServerBuilder
            //TODO
            .forPort(1337)
            .build();
}
 
Example 43
Project: grift   File: HelloWorldServer.java   Source Code and License 5 votes vote down vote up
private void start() throws IOException {
  server = ServerBuilder.forPort(port)
      .addService(new GreeterImpl())
      .build()
      .start();
  logger.info("Server started, listening on "+ port);
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      System.err.println("*** Shutting down gRPC server since JVM is shutting down");
      HelloWorldServer.this.stop();
      System.err.println("*** Server shut down");
    }
  });
}
 
Example 44
Project: iotplatform   File: ClusterGrpcService.java   Source Code and License 5 votes vote down vote up
public void init(RpcMsgListener listener) {
  this.listener = listener;
  log.info("Initializing RPC service!");
  instance = instanceService.getSelf();
  server = ServerBuilder.forPort(instance.getPort()).addService(this).build();
  log.info("Going to start RPC server using port: {}", instance.getPort());
  try {
    server.start();
  } catch (IOException e) {
    log.error("Failed to start RPC server!", e);
    throw new RuntimeException("Failed to start RPC server!");
  }
  log.info("RPC service initialized!");
}
 
Example 45
Project: book_ldrtc   File: HelloWorldServer.java   Source Code and License 5 votes vote down vote up
private void start() throws IOException {
    server = ServerBuilder.forPort(port).addService(new GreeterImpl()).build().start();
    logger.info("Server started, listening on " + port);
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            // Use stderr here since the logger may have been reset by its JVM shutdown hook.
            System.err.println("*** shutting down gRPC server since JVM is shutting down");
            HelloWorldServer.this.stop();
            System.err.println("*** server shut down");
        }
    });
}
 
Example 46
Project: polyglot   File: Main.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) {
  logger.info("Starting grpc server on port: " + SERVER_PORT);
  try {
    ServerBuilder.forPort(SERVER_PORT)
        .addService(new HelloServiceImpl())
        .addService(ProtoReflectionService.newInstance())
        .build()
        .start()
        .awaitTermination();
  } catch (InterruptedException | IOException e) {
    logger.info("Caught exception, shutting down", e);
    System.exit(0);
  }
}
 
Example 47
Project: examples-java   File: EventPublisher.java   Source Code and License 5 votes vote down vote up
private EventPublisher(int port) throws IOException {
    this.eventStoreService = new EventStoreService();
    this.server = ServerBuilder.forPort(port)
                               .addService(eventStoreService)
                               .build()
                               .start();
    log().info("Server started at port {}", port);
}
 
Example 48
Project: examples-java   File: EventStoreServer.java   Source Code and License 5 votes vote down vote up
private EventStoreServer(int port) {
    final ServerServiceDefinition service = EventStore.newServiceBuilder()
            .setStreamExecutor(Executors.newFixedThreadPool(5))
            .setStorage(InMemoryStorageFactory.getInstance().createEventStorage())
            .setLogger(log())
            .build();

    this.server = ServerBuilder.forPort(port)
            .addService(service)
            .build();
    this.port = port;
}
 
Example 49
Project: grpc-java-by-example   File: MyGrpcServer.java   Source Code and License 5 votes vote down vote up
static public void main(String [] args) throws IOException, InterruptedException {
  Server server = ServerBuilder.forPort(8080)
      .addService(new GreetingServiceImpl()).build();

  System.out.println("Starting server...");
  server.start();
  System.out.println("Server started!");
  server.awaitTermination();
}
 
Example 50
Project: grpc-java-by-example   File: EchoServer.java   Source Code and License 5 votes vote down vote up
static public void main(String[] args) throws IOException, InterruptedException {

    Server server = ServerBuilder.forPort(8080)
        .addService(new EchoServiceImpl()).build();

    System.out.println("Starting server...");
    server.start();
    System.out.println("Server started!");
    server.awaitTermination();
  }
 
Example 51
Project: grpc-java-by-example   File: GreetingServer.java   Source Code and License 5 votes vote down vote up
static public void main(String [] args) throws IOException, InterruptedException {
  Brave brave = Constant.brave("greeting-service");
  Server greetingServer = ServerBuilder.forPort(8080)
      .addService(ServerInterceptors.intercept(new GreetingServiceImpl(),
          new BraveGrpcServerInterceptor(brave),
          MonitoringServerInterceptor.create(Configuration.allMetrics())))
      .build();
  greetingServer.start();

  System.out.println("Server started!");
  greetingServer.awaitTermination();
}
 
Example 52
Project: grpc-java-by-example   File: ErrorGrpcServer.java   Source Code and License 5 votes vote down vote up
static public void main(String[] args) throws IOException, InterruptedException {
  UnknownStatusDescriptionInterceptor unknownStatusDescriptionInterceptor = new UnknownStatusDescriptionInterceptor(Arrays.asList(
      IllegalArgumentException.class
  ));
  Server server = ServerBuilder.forPort(8080)
      .addService(ServerInterceptors.intercept(new ErrorServiceImpl(), unknownStatusDescriptionInterceptor))
      .build();

  System.out.println("Starting server...");
  server.start();
  System.out.println("Server started!");
  server.awaitTermination();
}
 
Example 53
Project: grpc-java-by-example   File: GreetingServer.java   Source Code and License 5 votes vote down vote up
static public void main(String [] args) throws IOException, InterruptedException {
  JwtServerInterceptor jwtInterceptor = new JwtServerInterceptor(Constant.JWT_SECRET);

  Server greetingServer = ServerBuilder.forPort(8080)
      .addService(ServerInterceptors.intercept(new GreetingServiceImpl(), jwtInterceptor, new TraceIdServerInterceptor()))
      .build();
  greetingServer.start();

  System.out.println("Server started!");
  greetingServer.awaitTermination();
}
 
Example 54
Project: ibole-microservice   File: RpcTestServer.java   Source Code and License 5 votes vote down vote up
@Override
public Server buildServer() throws IOException {

  ServerBuilder serverBuilder = ServerBuilder.forPort(0);
  
  serverBuilder = bindService(serverBuilder);
  rpcServer = serverBuilder.build();
  return rpcServer;
}
 
Example 55
Project: java-grpc-prometheus   File: MonitoringServerInterceptorIntegrationTest.java   Source Code and License 5 votes vote down vote up
private void startGrpcServer(Configuration monitoringConfig) {
  MonitoringServerInterceptor interceptor = MonitoringServerInterceptor.create(
      monitoringConfig.withCollectorRegistry(collectorRegistry));
  grpcPort = Utils.pickUnusedPort();
  grpcServer = ServerBuilder.forPort(grpcPort)
      .addService(ServerInterceptors.intercept(new HelloServiceImpl().bindService(), interceptor))
      .build();
  try {
    grpcServer.start();
  } catch (IOException e) {
    throw new RuntimeException("Exception while running grpc server", e);
  }
}
 
Example 56
Project: java-grpc-prometheus   File: MonitoringClientInterceptorIntegrationTest.java   Source Code and License 5 votes vote down vote up
private void startServer() {
  grpcPort = Utils.pickUnusedPort();
  grpcServer = ServerBuilder.forPort(grpcPort)
      .addService(new HelloServiceImpl().bindService())
      .build();
  try {
    grpcServer.start();
  } catch (IOException e) {
    throw new RuntimeException("Exception while running grpc server", e);
  }
}
 
Example 57
Project: pravega   File: GRPCServer.java   Source Code and License 5 votes vote down vote up
/**
 * Create gRPC server on the specified port.
 *
 * @param controllerService The controller service implementation.
 * @param serverConfig      The RPC Server config.
 */
public GRPCServer(ControllerService controllerService, GRPCServerConfig serverConfig) {
    this.objectId = "gRPCServer";
    this.config = serverConfig;
    this.server = ServerBuilder
            .forPort(serverConfig.getPort())
            .addService(new ControllerServiceImpl(controllerService))
            .build();
}
 
Example 58
Project: grpc_greetertimer   File: GreeterTimerServer.java   Source Code and License 5 votes vote down vote up
public void start() throws IOException {
  server = ServerBuilder.forPort(port).addService(new GreeterTimerImpl()).build().start();
  System.out.println("GreeterTimerServer started, listening on port " + port);
  Runtime.getRuntime()
      .addShutdownHook(
          new Thread() {
            @Override
            public void run() {
              GreeterTimerServer.this.stop();
            }
          });
}
 
Example 59
Project: thingsboard   File: ClusterGrpcService.java   Source Code and License 5 votes vote down vote up
public void init(RpcMsgListener listener) {
    this.listener = listener;
    log.info("Initializing RPC service!");
    instance = instanceService.getSelf();
    server = ServerBuilder.forPort(instance.getPort()).addService(this).build();
    log.info("Going to start RPC server using port: {}", instance.getPort());
    try {
        server.start();
    } catch (IOException e) {
        log.error("Failed to start RPC server!", e);
        throw new RuntimeException("Failed to start RPC server!");
    }
    log.info("RPC service initialized!");
}
 
Example 60
Project: undercarriage   File: GrpcApplicationBase.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void onStart() {
    super.onStart();

    ServerBuilder<?> serverBuilder = createServerBuilder(configContext().config().grpc().port());

    for (ServerServiceDefinition serverServiceDefinition : serverServiceDefinitionsWithInterceptors()) {
        serverBuilder.addService(serverServiceDefinition);
    }

    server = serverBuilder.build();

    wrapChecked(() -> server.start());
}