Search in sources :

Example 1 with UtilGrpcExecutionContext

use of io.servicetalk.grpc.customtransport.Utils.UtilGrpcExecutionContext in project servicetalk by apple.

the class InMemoryServerTransport method getServiceContext.

private static GrpcServiceContext getServiceContext(Channel channel, BufferAllocator allocator) {
    // GrpcServiceContext is 1:1 with the Channel for the request. Closing it also closes the connection.
    Attribute<GrpcServiceContext> attr = channel.attr(GRPC_SERVICE_CONTEXT_KEY);
    GrpcServiceContext serviceContext = attr.get();
    if (serviceContext != null) {
        return serviceContext;
    }
    // GrpcExecutionContext exposes IoExecutor which is 1:1 with EventLoop. You could also use a
    // FastThreadLocal to store this info as well.
    GrpcExecutionContext executionContext = EVENT_LOOP_GRPC_EXECUTION_CONTEXT_MAP.computeIfAbsent(channel.eventLoop(), el -> new UtilGrpcExecutionContext(allocator, NettyIoExecutors.fromNettyEventLoop(el), GlobalExecutionContext.globalExecutionContext().executor()));
    serviceContext = new ChannelGrpcServiceContext(channel, executionContext);
    attr.set(serviceContext);
    return serviceContext;
}
Also used : ChannelGrpcServiceContext(io.servicetalk.grpc.customtransport.Utils.ChannelGrpcServiceContext) ChannelGrpcServiceContext(io.servicetalk.grpc.customtransport.Utils.ChannelGrpcServiceContext) GrpcServiceContext(io.servicetalk.grpc.api.GrpcServiceContext) UtilGrpcExecutionContext(io.servicetalk.grpc.customtransport.Utils.UtilGrpcExecutionContext) UtilGrpcExecutionContext(io.servicetalk.grpc.customtransport.Utils.UtilGrpcExecutionContext) GrpcExecutionContext(io.servicetalk.grpc.api.GrpcExecutionContext)

Aggregations

GrpcExecutionContext (io.servicetalk.grpc.api.GrpcExecutionContext)1 GrpcServiceContext (io.servicetalk.grpc.api.GrpcServiceContext)1 ChannelGrpcServiceContext (io.servicetalk.grpc.customtransport.Utils.ChannelGrpcServiceContext)1 UtilGrpcExecutionContext (io.servicetalk.grpc.customtransport.Utils.UtilGrpcExecutionContext)1