当前位置: 首页>>代码示例>>Java>>正文


Java Server.start方法代码示例

本文整理汇总了Java中io.grpc.Server.start方法的典型用法代码示例。如果您正苦于以下问题:Java Server.start方法的具体用法?Java Server.start怎么用?Java Server.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.grpc.Server的用法示例。


在下文中一共展示了Server.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import io.grpc.Server; //导入方法依赖的package包/类
/**
 * Start Netty Grpc Server.
 *
 * @return Server gRPC Server
 * @throws IOException - when something went wrong starting the grpc server
 */
final Server start() throws IOException {
  final int port = 8080;

  log.info("Starting grpc server on port '{}'...", port);
  final Server server =
      NettyServerBuilder
          .forPort(port)
          .addService(productReadService)
          .addService(productUpdateService)
          .addService(ServerInterceptors.intercept(echoService, serviceInterceptor))
          .build();

  server.start();
  log.info("grpc (port={}) server started successfully.", port);

  return server;
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:24,代码来源:GrpcServer.java

示例2: serverRunsAndRespondsCorrectly

import io.grpc.Server; //导入方法依赖的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

示例3: main

import io.grpc.Server; //导入方法依赖的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

示例4: main

import io.grpc.Server; //导入方法依赖的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

示例5: run

import io.grpc.Server; //导入方法依赖的package包/类
/** Equivalent of "main", but non-static. */
public void run(String[] args) throws Exception {

	final Server server = newServer();

	server.start();

	Runtime.getRuntime().addShutdownHook(new Thread() {
		@Override
		public void run() {
			try {
				System.out.println("Server shutting down");
				server.shutdown();
				server.awaitTermination(5, TimeUnit.SECONDS);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	});
}
 
开发者ID:zourzouvillys,项目名称:graphql,代码行数:21,代码来源:AsyncServer.java

示例6: startServer

import io.grpc.Server; //导入方法依赖的package包/类
public Server startServer() throws IOException {
  ServerInterceptor headersInterceptor = new TracingMetadataUtils.ServerHeadersInterceptor();
  NettyServerBuilder b =
      NettyServerBuilder.forPort(workerOptions.listenPort)
          .addService(ServerInterceptors.intercept(actionCacheServer, headersInterceptor))
          .addService(ServerInterceptors.intercept(bsServer, headersInterceptor))
          .addService(ServerInterceptors.intercept(casServer, headersInterceptor));

  if (execServer != null) {
    b.addService(ServerInterceptors.intercept(execServer, headersInterceptor));
    b.addService(ServerInterceptors.intercept(watchServer, headersInterceptor));
  } else {
    logger.info("Execution disabled, only serving cache requests.");
  }

  Server server = b.build();
  logger.log(INFO, "Starting gRPC server on port {0,number,#}.", workerOptions.listenPort);
  server.start();

  return server;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:22,代码来源:RemoteWorker.java

示例7: main

import io.grpc.Server; //导入方法依赖的package包/类
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();
    }
 
开发者ID:meteatamel,项目名称:grpc-samples-java,代码行数:16,代码来源:ChatServer.java

示例8: main

import io.grpc.Server; //导入方法依赖的package包/类
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();
    }
 
开发者ID:meteatamel,项目名称:grpc-samples-java,代码行数:16,代码来源:GreeterServer.java

示例9: startServerOnPort

import io.grpc.Server; //导入方法依赖的package包/类
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());
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:13,代码来源:LoadBalancedClusterMessageSenderTest.java

示例10: main

import io.grpc.Server; //导入方法依赖的package包/类
static public void main(String [] args) throws IOException, InterruptedException {
  Server server = ServerBuilder.forPort(8080)
      .addService(new GreetingServiceImpl()).build();

  System.out.println("Starting server...");
  server.start();
  System.out.println("Server started!");
  server.awaitTermination();
}
 
开发者ID:saturnism,项目名称:grpc-java-by-example,代码行数:10,代码来源:MyGrpcServer.java

示例11: main

import io.grpc.Server; //导入方法依赖的package包/类
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();
  }
 
开发者ID:saturnism,项目名称:grpc-java-by-example,代码行数:11,代码来源:EchoServer.java

示例12: main

import io.grpc.Server; //导入方法依赖的package包/类
static public void main(String [] args) throws IOException, InterruptedException {
  Brave brave = Constant.brave("greeting-service");
  Server greetingServer = ServerBuilder.forPort(8080)
      .addService(ServerInterceptors.intercept(new GreetingServiceImpl(),
          new BraveGrpcServerInterceptor(brave),
          MonitoringServerInterceptor.create(Configuration.allMetrics())))
      .build();
  greetingServer.start();

  System.out.println("Server started!");
  greetingServer.awaitTermination();
}
 
开发者ID:saturnism,项目名称:grpc-java-by-example,代码行数:13,代码来源:GreetingServer.java

示例13: main

import io.grpc.Server; //导入方法依赖的package包/类
static public void main(String[] args) throws IOException, InterruptedException {
  UnknownStatusDescriptionInterceptor unknownStatusDescriptionInterceptor = new UnknownStatusDescriptionInterceptor(Arrays.asList(
      IllegalArgumentException.class
  ));
  Server server = ServerBuilder.forPort(8080)
      .addService(ServerInterceptors.intercept(new ErrorServiceImpl(), unknownStatusDescriptionInterceptor))
      .build();

  System.out.println("Starting server...");
  server.start();
  System.out.println("Server started!");
  server.awaitTermination();
}
 
开发者ID:saturnism,项目名称:grpc-java-by-example,代码行数:14,代码来源:ErrorGrpcServer.java

示例14: main

import io.grpc.Server; //导入方法依赖的package包/类
static public void main(String [] args) throws IOException, InterruptedException {
  JwtServerInterceptor jwtInterceptor = new JwtServerInterceptor(Constant.JWT_SECRET);

  Server greetingServer = ServerBuilder.forPort(8080)
      .addService(ServerInterceptors.intercept(new GreetingServiceImpl(), jwtInterceptor, new TraceIdServerInterceptor()))
      .build();
  greetingServer.start();

  System.out.println("Server started!");
  greetingServer.awaitTermination();
}
 
开发者ID:saturnism,项目名称:grpc-java-by-example,代码行数:12,代码来源:GreetingServer.java

示例15: createServer

import io.grpc.Server; //导入方法依赖的package包/类
private static Server createServer(BindableService service, InetSocketAddress socket)
    throws IOException {
  Server server =
      NettyServerBuilder.forPort(socket.getPort())
          .addService(service)
          // Set the message size to max value here. The actual size is governed by the
          // buffer size in the layers above.
          .maxMessageSize(Integer.MAX_VALUE)
          .build();
  server.start();
  return server;
}
 
开发者ID:apache,项目名称:beam,代码行数:13,代码来源:ServerFactory.java


注:本文中的io.grpc.Server.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。