public GRPCServer(int port, BindableService... services) { ServerBuilder<?> builder = ServerBuilder.forPort(port); Arrays.stream(services).forEach(builder::addService); server = builder.build(); }
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"); } }); }
@SuppressWarnings("rawtypes") public void init() throws Exception{ if(!init){ synchronized (this) { if(!init){ registry = new MotanHandlerRegistry(); serviceDefinetions = new HashMap<URL, ServerServiceDefinition>(); io.grpc.ServerBuilder builder = ServerBuilder.forPort(port); builder.fallbackHandlerRegistry(registry); if(executor != null){ builder.executor(executor); } if(builder instanceof NettyServerBuilder){ httpHandler = new NettyHttpRequestHandler(executor); ((NettyServerBuilder)builder).protocolNegotiator(new HttpProtocolNegotiator(httpHandler)); } server = builder.build(); server.start(); init = true; } } } }
@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(); }
@Override public Server createServer() { final T builder = newServerBuilder(); configure(builder); return builder.build(); }
/** * 启动服务 */ 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"); } }); }
public GrpcStartable(GrpcServerConfig serverConfig, BindableService... services) { ServerBuilder<?> serverBuilder; if (serverConfig.isSslEnable()){ serverBuilder = NettyServerBuilder.forAddress( new InetSocketAddress(serverConfig.getHost(), serverConfig.getPort())); try { ((NettyServerBuilder) serverBuilder).sslContext(getSslContextBuilder(serverConfig).build()); } catch (SSLException e) { throw new IllegalStateException("Unable to setup grpc to use SSL.", e); } } else { serverBuilder = ServerBuilder.forPort(serverConfig.getPort()); } Arrays.stream(services).forEach(serverBuilder::addService); server = serverBuilder.build(); }
/** * 启动服务 * @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"); } }); }
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(); }
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(); }
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(); })); } }
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(); }