Search in sources :

Example 1 with ServerBuilder

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");
                }
            }
        });
    }
}
Also used : IOException(java.io.IOException) ServerBuilder(io.grpc.ServerBuilder)

Example 2 with ServerBuilder

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();
}
Also used : InProcessServerBuilder(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.inprocess.InProcessServerBuilder)

Example 3 with ServerBuilder

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);
}
Also used : LoggerFactory(org.apache.dubbo.common.logger.LoggerFactory) CallOptions(io.grpc.CallOptions) ExtensionLoader(org.apache.dubbo.common.extension.ExtensionLoader) ServerInterceptor(org.apache.dubbo.rpc.protocol.grpc.interceptors.ServerInterceptor) ManagedChannel(io.grpc.ManagedChannel) SslConfig(org.apache.dubbo.config.SslConfig) NettyServerBuilder(io.grpc.netty.NettyServerBuilder) CLIENT_INTERCEPTORS(org.apache.dubbo.rpc.protocol.grpc.GrpcConstants.CLIENT_INTERCEPTORS) MAX_INBOUND_MESSAGE_SIZE(org.apache.dubbo.rpc.protocol.grpc.GrpcConstants.MAX_INBOUND_MESSAGE_SIZE) ConfigManager(org.apache.dubbo.config.context.ConfigManager) ArrayList(java.util.ArrayList) ClientAuth(io.netty.handler.ssl.ClientAuth) SERVER_INTERCEPTORS(org.apache.dubbo.rpc.protocol.grpc.GrpcConstants.SERVER_INTERCEPTORS) URL(org.apache.dubbo.common.URL) SSL_ENABLED_KEY(org.apache.dubbo.common.constants.CommonConstants.SSL_ENABLED_KEY) PROVIDER_SIDE(org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE) ServerBuilder(io.grpc.ServerBuilder) CONSUMER_SIDE(org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE) MAX_CONCURRENT_CALLS_PER_CONNECTION(org.apache.dubbo.rpc.protocol.grpc.GrpcConstants.MAX_CONCURRENT_CALLS_PER_CONNECTION) MAX_INBOUND_METADATA_SIZE(org.apache.dubbo.rpc.protocol.grpc.GrpcConstants.MAX_INBOUND_METADATA_SIZE) EXECUTOR(org.apache.dubbo.rpc.protocol.grpc.GrpcConstants.EXECUTOR) ApplicationModel(org.apache.dubbo.rpc.model.ApplicationModel) GrpcConfigurator(org.apache.dubbo.rpc.protocol.grpc.interceptors.GrpcConfigurator) SslContext(io.netty.handler.ssl.SslContext) Logger(org.apache.dubbo.common.logger.Logger) CollectionUtils(org.apache.dubbo.common.utils.CollectionUtils) ThreadPool(org.apache.dubbo.common.threadpool.ThreadPool) Set(java.util.Set) IOException(java.io.IOException) DISPATCHER_KEY(org.apache.dubbo.remoting.Constants.DISPATCHER_KEY) TRANSPORT_FILTERS(org.apache.dubbo.rpc.protocol.grpc.GrpcConstants.TRANSPORT_FILTERS) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) SSLException(javax.net.ssl.SSLException) List(java.util.List) EXECUTES_KEY(org.apache.dubbo.rpc.Constants.EXECUTES_KEY) ServerTransportFilter(org.apache.dubbo.rpc.protocol.grpc.interceptors.ServerTransportFilter) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) Optional(java.util.Optional) ClientInterceptor(org.apache.dubbo.rpc.protocol.grpc.interceptors.ClientInterceptor) GrpcSslContexts(io.grpc.netty.GrpcSslContexts) InputStream(java.io.InputStream) ServerInterceptor(org.apache.dubbo.rpc.protocol.grpc.interceptors.ServerInterceptor) ThreadPool(org.apache.dubbo.common.threadpool.ThreadPool) ServerTransportFilter(org.apache.dubbo.rpc.protocol.grpc.interceptors.ServerTransportFilter)

Aggregations

ServerBuilder (io.grpc.ServerBuilder)2 IOException (java.io.IOException)2 CallOptions (io.grpc.CallOptions)1 ManagedChannel (io.grpc.ManagedChannel)1 GrpcSslContexts (io.grpc.netty.GrpcSslContexts)1 NettyChannelBuilder (io.grpc.netty.NettyChannelBuilder)1 NettyServerBuilder (io.grpc.netty.NettyServerBuilder)1 ClientAuth (io.netty.handler.ssl.ClientAuth)1 SslContext (io.netty.handler.ssl.SslContext)1 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 SSLException (javax.net.ssl.SSLException)1 InProcessServerBuilder (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.inprocess.InProcessServerBuilder)1 URL (org.apache.dubbo.common.URL)1 CONSUMER_SIDE (org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE)1 PROVIDER_SIDE (org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE)1