當前位置: 首頁>>代碼示例>>Java>>正文


Java ServerBuilder類代碼示例

本文整理匯總了Java中io.grpc.ServerBuilder的典型用法代碼示例。如果您正苦於以下問題:Java ServerBuilder類的具體用法?Java ServerBuilder怎麽用?Java ServerBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ServerBuilder類屬於io.grpc包,在下文中一共展示了ServerBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: newInstance

import io.grpc.ServerBuilder; //導入依賴的package包/類
@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();
        }
    };
}
 
開發者ID:maxdemarzi,項目名稱:neo_grpc,代碼行數:20,代碼來源:RegistergRPCExtensionFactory.java

示例2: start

import io.grpc.ServerBuilder; //導入依賴的package包/類
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");
            }
          });
}
 
開發者ID:google,項目名稱:rejoiner,代碼行數:18,代碼來源:HelloWorldServer.java

示例3: start

import io.grpc.ServerBuilder; //導入依賴的package包/類
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");
            }
          });
}
 
開發者ID:google,項目名稱:rejoiner,代碼行數:18,代碼來源:GraphQlGrpcServer.java

示例4: start

import io.grpc.ServerBuilder; //導入依賴的package包/類
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.");
        }
    });
}
 
開發者ID:graphflow,項目名稱:graphflow,代碼行數:22,代碼來源:GraphflowServer.java

示例5: start

import io.grpc.ServerBuilder; //導入依賴的package包/類
/**
 * 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");
            }
          });
}
 
開發者ID:google,項目名稱:devicehub,代碼行數:29,代碼來源:DeviceHubServer.java

示例6: start

import io.grpc.ServerBuilder; //導入依賴的package包/類
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();
}
 
開發者ID:aksalj,項目名稱:africastalking-java,代碼行數:12,代碼來源:Server.java

示例7: serverRunsAndRespondsCorrectly

import io.grpc.ServerBuilder; //導入依賴的package包/類
@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();
}
 
開發者ID:salesforce,項目名稱:grpc-java-contrib,代碼行數:32,代碼來源:CompletableFutureEndToEndTest.java

示例8: SeldonGrpcServer

import io.grpc.ServerBuilder; //導入依賴的package包/類
@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();
}
 
開發者ID:SeldonIO,項目名稱:seldon-core,代碼行數:20,代碼來源:SeldonGrpcServer.java

示例9: main

import io.grpc.ServerBuilder; //導入依賴的package包/類
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();
	}

}
 
開發者ID:laddcn,項目名稱:grpcx,代碼行數:18,代碼來源:Provider.java

示例10: start

import io.grpc.ServerBuilder; //導入依賴的package包/類
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");
    }
  });
}
 
開發者ID:lrtdc,項目名稱:book_ldrtc,代碼行數:17,代碼來源:HelloJsonServer.java

示例11: start

import io.grpc.ServerBuilder; //導入依賴的package包/類
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");
    }
  });
}
 
開發者ID:lrtdc,項目名稱:book_ldrtc,代碼行數:17,代碼來源:CustomHeaderServer.java

示例12: start

import io.grpc.ServerBuilder; //導入依賴的package包/類
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");
        }
    });
}
 
開發者ID:javahongxi,項目名稱:whatsmars,代碼行數:20,代碼來源:HelloWorldServer.java

示例13: main

import io.grpc.ServerBuilder; //導入依賴的package包/類
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();
}
 
開發者ID:saturnism,項目名稱:grpc-java-by-example,代碼行數:21,代碼來源:RxMetricsServer.java

示例14: start

import io.grpc.ServerBuilder; //導入依賴的package包/類
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 ***");
    }));
}
 
開發者ID:caio,項目名稱:grpc-java-gradle-hello-world,代碼行數:17,代碼來源:HelloWorldServer.java

示例15: start

import io.grpc.ServerBuilder; //導入依賴的package包/類
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");
        }
    });
}
 
開發者ID:mateuszdyminski,項目名稱:grpc,代碼行數:17,代碼來源:Backend.java


注:本文中的io.grpc.ServerBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。