public GRPCServer(int port, BindableService... services) { ServerBuilder<?> builder = ServerBuilder.forPort(port); Arrays.stream(services).forEach(builder::addService); server = builder.build(); }
@Bean @ConditionalOnProperty(value = "grpc.enabled", havingValue = "true", matchIfMissing = true) public GRpcServerRunner grpcServerRunner(GRpcServerBuilderConfigurer configurer) { return new GRpcServerRunner(configurer, ServerBuilder.forPort(port)); }
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; } } } }
/** * 启动服务 */ 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 GRpcServerBuilderConfigure(List<BindServiceAdapter> bindServiceAdapterList, int port) { this.bindServiceAdapterList = bindServiceAdapterList; this.port = port; this.serverBuilder = ServerBuilder.forPort(port); }
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(); }
@Bean @ConditionalOnProperty(value = "grpc.enabled", havingValue = "true", matchIfMissing = true) public GRpcServerRunner grpcServerRunner(GRpcServerBuilderConfigurer configurer) { return new GRpcServerRunner(configurer, ServerBuilder.forPort(grpcServerProperties.getPort())); }
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(); } }
public PServer(int port, int workerNum) { server = ServerBuilder.forPort(port).addService(net.PSGrpc.bindService(this)).build(); store = KVStore.ins(); this.workerNum = workerNum; updateThread.execute(this); }
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(); }