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


Java ServerBuilder.forPort方法代码示例

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


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

示例1: onLocalNodeStarted

import io.grpc.ServerBuilder; //导入方法依赖的package包/类
@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");
        }
      }
    });
  }
}
 
开发者ID:h2oai,项目名称:h2o-3,代码行数:27,代码来源:GrpcExtension.java

示例2: startServerOnPort

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

示例3: testSyncFunctions

import io.grpc.ServerBuilder; //导入方法依赖的package包/类
@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();
        }
    }
}
 
开发者ID:altiplanogao,项目名称:rpc-comparison,代码行数:28,代码来源:FunctionTest.java

示例4: testAsyncFunctions

import io.grpc.ServerBuilder; //导入方法依赖的package包/类
@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();
        }
    }
}
 
开发者ID:altiplanogao,项目名称:rpc-comparison,代码行数:28,代码来源:FunctionTest.java

示例5: startInsecure

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

示例6: buildServerForServices

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

示例7: buildServer

import io.grpc.ServerBuilder; //导入方法依赖的package包/类
@Override
public Server buildServer() throws IOException {

  ServerBuilder serverBuilder = ServerBuilder.forPort(0);
  
  serverBuilder = bindService(serverBuilder);
  rpcServer = serverBuilder.build();
  return rpcServer;
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:10,代码来源:RpcTestServer.java

示例8: builder

import io.grpc.ServerBuilder; //导入方法依赖的package包/类
/**
 * @param environment to use
 * @return A {@link ServerBuilder}, with port and optional transport security set from the configuration. To use
 *         this, add gRPC services to the server, then call build(). The returned server is lifecycle-managed in the
 *         given {@link Environment}.
 */
public ServerBuilder<?> builder(final Environment environment) {
    final ServerBuilder<?> originBuilder;
    final ServerBuilder<?> dropwizardBuilder;
    originBuilder = ServerBuilder.forPort(port);
    dropwizardBuilder = new DropwizardServerBuilder(environment, originBuilder, shutdownPeriod);
    if (certChainFile != null && privateKeyFile != null) {
        dropwizardBuilder.useTransportSecurity(certChainFile.toFile(), privateKeyFile.toFile());
    }
    return dropwizardBuilder;
}
 
开发者ID:msteinhoff,项目名称:dropwizard-grpc,代码行数:17,代码来源:GrpcServerFactory.java

示例9: createGrpcServer

import io.grpc.ServerBuilder; //导入方法依赖的package包/类
@VisibleForTesting
Server createGrpcServer() {
    final ServerBuilder builder = ServerBuilder.forPort(port);
    for (ServerServiceDefinition service : services) {
        builder.addService(service);
    }

    return builder.build();
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:10,代码来源:GrpcContainer.java

示例10: ExternalRpcServer

import io.grpc.ServerBuilder; //导入方法依赖的package包/类
@Autowired
public ExternalRpcServer(PredictionService predictionService)
{
	logger.info("Initializing RPC server...");
	this.predictionService = predictionService;
	ServerBuilder<?> serverBuilder = ServerBuilder.forPort(port);
	server = serverBuilder.addService(ServerInterceptors.intercept(this, this)).build();
	
}
 
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:10,代码来源:ExternalRpcServer.java

示例11: LoadServer

import io.grpc.ServerBuilder; //导入方法依赖的package包/类
LoadServer(Control.ServerConfig config) throws Exception {
  log.log(Level.INFO, "Server Config \n" + config.toString());
  port = config.getPort() ==  0 ? Utils.pickUnusedPort() : config.getPort();
  ServerBuilder<?> serverBuilder = ServerBuilder.forPort(port);
  int asyncThreads = config.getAsyncServerThreads() == 0
      ? Runtime.getRuntime().availableProcessors()
      : config.getAsyncServerThreads();
  // The concepts of sync & async server are quite different in the C impl and the names
  // chosen for the enum are based on that implementation. We use 'sync' to mean
  // the direct executor case in Java even though the service implementations are always
  // fully async.
  switch (config.getServerType()) {
    case ASYNC_SERVER: {
      serverBuilder.executor(getExecutor(asyncThreads));
      break;
    }
    case SYNC_SERVER: {
      serverBuilder.directExecutor();
      break;
    }
    case ASYNC_GENERIC_SERVER: {
      serverBuilder.executor(getExecutor(asyncThreads));
      // Create buffers for the generic service
      PooledByteBufAllocator alloc = PooledByteBufAllocator.DEFAULT;
      genericResponse = alloc.buffer(config.getPayloadConfig().getBytebufParams().getRespSize());
      if (genericResponse.capacity() > 0) {
        genericResponse.writerIndex(genericResponse.capacity() - 1);
      }
      break;
    }
    default: {
      throw new IllegalArgumentException();
    }
  }
  if (config.hasSecurityParams()) {
    File cert = TestUtils.loadCert("server1.pem");
    File key = TestUtils.loadCert("server1.key");
    serverBuilder.useTransportSecurity(cert, key);
  }
  benchmarkService = new AsyncServer.BenchmarkServiceImpl();
  if (config.getServerType() == Control.ServerType.ASYNC_GENERIC_SERVER) {
    serverBuilder.addService(
        ServerServiceDefinition
            .builder(new ServiceDescriptor(BenchmarkServiceGrpc.SERVICE_NAME,
                GENERIC_STREAMING_PING_PONG_METHOD))
            .addMethod(GENERIC_STREAMING_PING_PONG_METHOD, new GenericServiceCallHandler())
            .build());
  } else {
    serverBuilder.addService(benchmarkService);
  }
  server = serverBuilder.build();

  List<OperatingSystemMXBean> beans =
      ManagementFactory.getPlatformMXBeans(OperatingSystemMXBean.class);
  if (!beans.isEmpty()) {
    osBean = beans.get(0);
  } else {
    osBean = null;
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:61,代码来源:LoadServer.java

示例12: GrpcStartable

import io.grpc.ServerBuilder; //导入方法依赖的package包/类
GrpcStartable(int port, BindableService... services) {
  ServerBuilder<?> serverBuilder = ServerBuilder.forPort(port);
  Arrays.stream(services).forEach(serverBuilder::addService);
  server = serverBuilder.build();
}
 
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:6,代码来源:GrpcStartable.java

示例13: start

import io.grpc.ServerBuilder; //导入方法依赖的package包/类
public void start() throws IOException {
    ServerBuilder serverBuilder = ServerBuilder.forPort(port);
    server = serverBuilder.addService(new AskerService()).build();
    server.start();
}
 
开发者ID:altiplanogao,项目名称:rpc-comparison,代码行数:6,代码来源:FunctionTest.java

示例14: SeldonGrpcServer

import io.grpc.ServerBuilder; //导入方法依赖的package包/类
public SeldonGrpcServer(AppProperties appProperties,DeploymentStore deploymentStore,TokenStore tokenStore,DeploymentsHandler deploymentsHandler,int port)
{
    this(appProperties,deploymentStore,tokenStore,ServerBuilder.forPort(port), deploymentsHandler, port);
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:5,代码来源:SeldonGrpcServer.java

示例15: BuildFarmServer

import io.grpc.ServerBuilder; //导入方法依赖的package包/类
public BuildFarmServer(BuildFarmServerConfig config) {
  this(ServerBuilder.forPort(config.getPort()), config);
}
 
开发者ID:bazelbuild,项目名称:bazel-buildfarm,代码行数:4,代码来源:BuildFarmServer.java


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