ok2c commented on code in PR #726: URL: https://github.com/apache/httpcomponents-client/pull/726#discussion_r2356027961
########## httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/AsyncDisposalCallback.java: ########## @@ -0,0 +1,128 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ +package org.apache.hc.client5.http.impl.io; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.apache.hc.core5.annotation.Internal; +import org.apache.hc.core5.http.SocketModalCloseable; +import org.apache.hc.core5.io.CloseMode; +import org.apache.hc.core5.pool.DefaultDisposalCallback; +import org.apache.hc.core5.pool.DisposalCallback; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Asynchronously disposes {@code SocketModalCloseable} instances on a daemon thread, + * delegating the actual close to {@link DefaultDisposalCallback}. + */ +@Internal +final class AsyncDisposalCallback<C extends SocketModalCloseable> + implements DisposalCallback<C>, AutoCloseable { + + private static final Logger LOG = LoggerFactory.getLogger(AsyncDisposalCallback.class); + + private static final class Item<X extends SocketModalCloseable> { + final X closeable; + final CloseMode mode; + + Item(final X c, final CloseMode m) { + this.closeable = c; + this.mode = m; + } + } + + private final BlockingQueue<Item<C>> queue; + private final AtomicBoolean running = new AtomicBoolean(true); + private final Thread worker; Review Comment: @arturobernalg I think you are over-complicating it. Just drain the queue at the end of `#lease`, `#release` and other methods that can call `PoolEntry#discardConnection`. As long as it is done outside the pool lock it is good enough. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
