本文整理汇总了Java中io.grpc.ServerBuilder.addService方法的典型用法代码示例。如果您正苦于以下问题:Java ServerBuilder.addService方法的具体用法?Java ServerBuilder.addService怎么用?Java ServerBuilder.addService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.grpc.ServerBuilder
的用法示例。
在下文中一共展示了ServerBuilder.addService方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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());
}
}
示例3: 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();
}
示例4: 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());
}
示例5: 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();
}
示例6: startServer
import io.grpc.ServerBuilder; //导入方法依赖的package包/类
private void startServer(int serverFlowControlWindow) {
ServerBuilder<?> builder =
NettyServerBuilder.forAddress(new InetSocketAddress("localhost", 0))
.flowControlWindow(serverFlowControlWindow);
builder.addService(ServerInterceptors.intercept(
new TestServiceImpl(Executors.newScheduledThreadPool(2)),
ImmutableList.<ServerInterceptor>of()));
try {
server = builder.build().start();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例7: 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;
}
}
示例8: registerService
import io.grpc.ServerBuilder; //导入方法依赖的package包/类
/**
* Override this method to override how a {@link BindableService} is added to the {@link ServerBuilder}.
*/
protected void registerService(ServerBuilder builder, BindableService service) {
builder.addService(service);
}
示例9: registerWithServer
import io.grpc.ServerBuilder; //导入方法依赖的package包/类
static void registerWithServer(ServerBuilder sb) {
sb.addService(new ClusterService());
sb.addService(new JobService());
sb.addService(new CreateFrameService());
}