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"); })); }
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"); })); }
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"); } }); }
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"); } }); }
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"); } }); }
@Override public void run(String... args) throws Exception { log.info("Starting gRPC Server ..."); Collection<ServerInterceptor> globalInterceptors = getBeanNamesByTypeWithAnnotation(GRpcGlobalInterceptor.class, ServerInterceptor.class) .map(name -> applicationContext.getBeanFactory().getBean(name, ServerInterceptor.class)) .collect(Collectors.toList()); // Adding health service serverBuilder.addService(healthStatusManager.getHealthService()); // find and register all GRpcService-enabled beans getBeanNamesByTypeWithAnnotation(GRpcService.class, BindableService.class) .forEach(name -> { BindableService srv = applicationContext.getBeanFactory().getBean(name, BindableService.class); ServerServiceDefinition serviceDefinition = srv.bindService(); GRpcService gRpcServiceAnn = applicationContext.findAnnotationOnBean(name, GRpcService.class); serviceDefinition = bindInterceptors(serviceDefinition, gRpcServiceAnn, globalInterceptors); serverBuilder.addService(serviceDefinition); String serviceName = serviceDefinition.getServiceDescriptor().getName(); healthStatusManager.setStatus(serviceName, HealthCheckResponse.ServingStatus.SERVING); log.info("'{}' service has been registered.", srv.getClass().getName()); }); if (gRpcServerProperties.isEnableReflection()) { serverBuilder.addService(ProtoReflectionService.newInstance()); log.info("'{}' service has been registered.", ProtoReflectionService.class.getName()); } configurer.configure(serverBuilder); server = serverBuilder.build().start(); applicationContext.publishEvent(new GRpcServerInitializedEvent(server)); log.info("gRPC Server started, listening on port {}.", server.getPort()); startDaemonAwaitThread(); }
public void start() throws Exception { Server server = ServerBuilder.forPort(port) .addService(new LanguageIdServiceImpl()) .addService(new PreprocessingServiceImpl()) .addService(new NormalizationServiceImpl(context)) .addService(new MorphologyServiceImpl(context)) .build() .start(); Log.info("Zemberek grpc server started at port: " + port); server.awaitTermination(); }
/** * 启动服务 */ private void start() throws IOException { System.out.println("service start..."); server = ServerBuilder.forPort(port) .addService(new GreeterImpl()) .build() .start(); System.out.println("service started"); //程序正常退出,系统调用 System.exit方法或虚拟机被关闭时执行该调用 Runtime.getRuntime().addShutdownHook(new Thread(() -> { System.err.println("*** shutting down gRPC server since JVM is shutting down"); HelloWorldServer.this.stop(); System.err.println("*** server shut down"); })); }
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"); } }); }
/** * 启动服务 * @throws IOException */ private void start() throws IOException { System.out.println("service start..."); server = ServerBuilder.forPort(port) .addService(ServerInterceptors.intercept(new GreeterImpl(),new ServerInterruptImpl())) .build() .start(); System.out.println("service started"); //程序正常退出,系统调用 System.exit方法或虚拟机被关闭时执行该调用 Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { System.err.println("*** shutting down gRPC server since JVM is shutting down"); HelloWorldServerProcess.this.stop(); System.err.println("*** server shut down"); } }); }
/** * Configures the services that should be served by the server. * * @param builder The server builder to configure. */ protected void configureServices(final T builder) { // support health check if (this.properties.isHealthServiceEnabled()) { builder.addService(this.healthStatusManager.getHealthService()); } if (this.properties.isReflectionServiceEnabled()) { builder.addService(ProtoReflectionService.newInstance()); } for (final GrpcServiceDefinition service : this.serviceList) { final String serviceName = service.getDefinition().getServiceDescriptor().getName(); log.info("Registered gRPC service: " + serviceName + ", bean: " + service.getBeanName() + ", class: " + service.getBeanClazz().getName()); builder.addService(service.getDefinition()); this.healthStatusManager.setStatus(serviceName, HealthCheckResponse.ServingStatus.SERVING); } }
private void start(int port, BookstoreData data) throws IOException { server = ServerBuilder.forPort(port) .addService(new BookstoreService(data)) .build().start(); }
public RouteGuideServer(int port) throws IOException { this.port = port; //获取初始化数据 List<Feature> features = RouteGuideUtil.parseFeatures(RouteGuideUtil.getDefaultFeaturesFile()); //初始化Server参数 server = ServerBuilder.forPort(port) //添加指定服务 .addService(new RouteGuideService(features)) .build(); }
/** * Override this method to override how a {@link BindableService} is added to the {@link ServerBuilder}. */ protected void registerService(ServerBuilder builder, BindableService service) { builder.addService(service); }
public GrpcServer(FeatureRpcResource featureRpcResource, int port) throws IOException { log.info("starting grpc server on port {}", port); server = ServerBuilder.forPort(port) .addService(featureRpcResource).build().start(); Runtime.getRuntime().addShutdownHook(new Thread(() -> { log.info("Shutting down grpc server on port {}" + port); server.shutdown(); })); } }
@PostConfigured public void init() throws IOException { log.info("starting grpc server on port {}", port); server = ServerBuilder.forPort(port) .addService(featureRpcResource).build().start(); Runtime.getRuntime().addShutdownHook(new Thread(() -> { log.info("Shutting down grpc server on port {}" + port); server.shutdown(); })); } }
public void start() throws IOException { LOG.info("Version: {}", VERSION); LOG.info("Starting gateway with configuration {}", gatewayCfg.toJson()); brokerClient = buildBrokerClient(); server = serverBuilderFactory .apply(gatewayCfg) .addService(new EndpointManager(brokerClient)) .build(); server.start(); }
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(); } }
private static void startGRPCServer(MessageDispatcher messageDispatcher) throws IOException, InterruptedException { Server server; LspServer lspServer = new LspServer(messageDispatcher); server = ServerBuilder.forPort(0).addService(lspServer).build(); lspServer.addServer(server); server.start(); int port = server.getPort(); System.out.println("Listening on port:" + port); server.awaitTermination(); }
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(); }