use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ServerBuilder in project h2o-3 by h2oai.
the class GrpcExtension method onLocalNodeStarted.
@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");
}
}
});
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ServerBuilder in project beam by apache.
the class InProcessServerFactory method allocateAddressAndCreate.
@Override
public Server allocateAddressAndCreate(List<BindableService> services, ApiServiceDescriptor.Builder builder) throws IOException {
String name = String.format("InProcessServer_%s", serviceNameUniqifier.getAndIncrement());
builder.setUrl(name);
InProcessServerBuilder serverBuilder = InProcessServerBuilder.forName(name);
services.stream().forEach(service -> serverBuilder.addService(ServerInterceptors.intercept(service, GrpcContextHeaderAccessorProvider.interceptor())));
return serverBuilder.build().start();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ServerBuilder in project dubbo by alibaba.
the class GrpcOptionsUtils method buildServerBuilder.
static ServerBuilder buildServerBuilder(URL url, NettyServerBuilder builder) {
int maxInboundMessageSize = url.getParameter(MAX_INBOUND_MESSAGE_SIZE, 0);
if (maxInboundMessageSize > 0) {
builder.maxInboundMessageSize(maxInboundMessageSize);
}
int maxInboundMetadataSize = url.getParameter(MAX_INBOUND_METADATA_SIZE, 0);
if (maxInboundMetadataSize > 0) {
builder.maxInboundMetadataSize(maxInboundMetadataSize);
}
if (url.getParameter(SSL_ENABLED_KEY, false)) {
builder.sslContext(buildServerSslContext(url));
}
int flowControlWindow = url.getParameter(MAX_INBOUND_MESSAGE_SIZE, 0);
if (flowControlWindow > 0) {
builder.flowControlWindow(flowControlWindow);
}
int maxCalls = url.getParameter(MAX_CONCURRENT_CALLS_PER_CONNECTION, url.getParameter(EXECUTES_KEY, 0));
if (maxCalls > 0) {
builder.maxConcurrentCallsPerConnection(maxCalls);
}
// server interceptors
List<ServerInterceptor> serverInterceptors = ExtensionLoader.getExtensionLoader(ServerInterceptor.class).getActivateExtension(url, SERVER_INTERCEPTORS, PROVIDER_SIDE);
for (ServerInterceptor serverInterceptor : serverInterceptors) {
builder.intercept(serverInterceptor);
}
// server filters
List<ServerTransportFilter> transportFilters = ExtensionLoader.getExtensionLoader(ServerTransportFilter.class).getActivateExtension(url, TRANSPORT_FILTERS, PROVIDER_SIDE);
for (ServerTransportFilter transportFilter : transportFilters) {
builder.addTransportFilter(transportFilter.grpcTransportFilter());
}
String thread = url.getParameter(EXECUTOR, url.getParameter(DISPATCHER_KEY));
if ("direct".equals(thread)) {
builder.directExecutor();
} else {
builder.executor(ExtensionLoader.getExtensionLoader(ThreadPool.class).getAdaptiveExtension().getExecutor(url));
}
// Give users the chance to customize ServerBuilder
return getConfigurator().map(configurator -> configurator.configureServerBuilder(builder, url)).orElse(builder);
}
Aggregations