Java Code Examples for com.google.common.util.concurrent.MoreExecutors#newSequentialExecutor()

The following examples show how to use com.google.common.util.concurrent.MoreExecutors#newSequentialExecutor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrderedExecutorImpl.java    From java-trader with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() {
    executors = new Executor[THREAD_COUNT];
    for(int i=0;i<this.executors.length;i++) {
        executors[i] = MoreExecutors.newSequentialExecutor(executorService);
    }
}
 
Example 2
Source File: ArmeriaServerCall.java    From armeria with Apache License 2.0 4 votes vote down vote up
ArmeriaServerCall(HttpHeaders clientHeaders,
                  MethodDescriptor<I, O> method,
                  CompressorRegistry compressorRegistry,
                  DecompressorRegistry decompressorRegistry,
                  HttpResponseWriter res,
                  int maxInboundMessageSizeBytes,
                  int maxOutboundMessageSizeBytes,
                  ServiceRequestContext ctx,
                  SerializationFormat serializationFormat,
                  @Nullable GrpcJsonMarshaller jsonMarshaller,
                  boolean unsafeWrapRequestBuffers,
                  boolean useBlockingTaskExecutor,
                  ResponseHeaders defaultHeaders) {
    requireNonNull(clientHeaders, "clientHeaders");
    this.method = requireNonNull(method, "method");
    this.ctx = requireNonNull(ctx, "ctx");
    this.serializationFormat = requireNonNull(serializationFormat, "serializationFormat");
    this.defaultHeaders = requireNonNull(defaultHeaders, "defaultHeaders");
    messageReader = new HttpStreamReader(
            requireNonNull(decompressorRegistry, "decompressorRegistry"),
            new ArmeriaMessageDeframer(
                    this,
                    maxInboundMessageSizeBytes,
                    ctx.alloc())
                    .decompressor(clientDecompressor(clientHeaders, decompressorRegistry)),
            this);
    messageFramer = new ArmeriaMessageFramer(ctx.alloc(), maxOutboundMessageSizeBytes);
    this.res = requireNonNull(res, "res");
    this.compressorRegistry = requireNonNull(compressorRegistry, "compressorRegistry");
    clientAcceptEncoding =
            Strings.emptyToNull(clientHeaders.get(GrpcHeaderNames.GRPC_ACCEPT_ENCODING));
    marshaller = new GrpcMessageMarshaller<>(ctx.alloc(), serializationFormat, method, jsonMarshaller,
                                             unsafeWrapRequestBuffers);
    this.unsafeWrapRequestBuffers = unsafeWrapRequestBuffers;
    blockingExecutor = useBlockingTaskExecutor ?
                       MoreExecutors.newSequentialExecutor(ctx.blockingTaskExecutor()) : null;

    res.whenComplete().handleAsync((unused, t) -> {
        if (!closeCalled) {
            // Closed by client, not by server.
            cancelled = true;
            try (SafeCloseable ignore = ctx.push()) {
                close(Status.CANCELLED, new Metadata());
            }
        }
        return null;
    }, ctx.eventLoop());
}