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


Java ServerBuilder.build方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: onStart

import io.grpc.ServerBuilder; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
protected void onStart() {
    super.onStart();

    ServerBuilder<?> serverBuilder = createServerBuilder(configContext().config().grpc().port());

    for (ServerServiceDefinition serverServiceDefinition : serverServiceDefinitionsWithInterceptors()) {
        serverBuilder.addService(serverServiceDefinition);
    }

    server = serverBuilder.build();

    wrapChecked(() -> server.start());
}
 
開發者ID:joeyb,項目名稱:undercarriage,代碼行數:18,代碼來源:GrpcApplicationBase.java

示例8: 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

示例9: 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

示例10: 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


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