use of io.servicetalk.grpc.customtransport.Utils.ChannelGrpcServiceContext 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;
}
Aggregations