当前位置: 首页>>代码示例>>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;未经允许,请勿转载。