@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(); } }; }
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"); } }); }
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."); } }); }
/** * 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"); } }); }
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(); }
@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(); }
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(); } }
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"); } }); }
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"); } }); }
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"); } }); }
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(); }
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 ***"); })); }
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"); } }); }
/** 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"); } }); }
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"); } }); }
@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"); } } }); } }
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 { 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"); } }); }
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"); } }); }
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(); }
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(); }
@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(); }
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(); }
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(); }
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 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()); } }
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(); } }); }
@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(); } } }
@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(); } } }
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)); }
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; }
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(); }
@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(); }
@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(); }
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(); }
public FakeEngineServer() { server = ServerBuilder .forPort(PORT) .addService(new FakeSeldonEngineService()) .build(); }
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(); }