Fixes #4904 - WebsocketClient creates more connections than needed.
After merge fixes. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
parent
44d601aa60
commit
4277759a85
|
@ -47,13 +47,30 @@ public abstract class AbstractConnectionPool implements ConnectionPool, Dumpable
|
|||
private final int maxConnections;
|
||||
private final Callback requester;
|
||||
|
||||
/**
|
||||
* @param destination the correspondent destination
|
||||
* @param maxConnections the max number of connections
|
||||
* @param requester the callback to notify about new connection creation/failure
|
||||
* @deprecated use {@link #AbstractConnectionPool(HttpDestination, int, Callback)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
protected AbstractConnectionPool(Destination destination, int maxConnections, Callback requester)
|
||||
{
|
||||
this.destination = (HttpDestination)destination;
|
||||
this((HttpDestination)destination, maxConnections, requester);
|
||||
}
|
||||
|
||||
protected AbstractConnectionPool(HttpDestination destination, int maxConnections, Callback requester)
|
||||
{
|
||||
this.destination = destination;
|
||||
this.maxConnections = maxConnections;
|
||||
this.requester = requester;
|
||||
}
|
||||
|
||||
protected HttpDestination getHttpDestination()
|
||||
{
|
||||
return destination;
|
||||
}
|
||||
|
||||
@ManagedAttribute(value = "The max number of connections", readonly = true)
|
||||
public int getMaxConnectionCount()
|
||||
{
|
||||
|
|
|
@ -52,7 +52,7 @@ public class DuplexConnectionPool extends AbstractConnectionPool implements Swee
|
|||
|
||||
public DuplexConnectionPool(Destination destination, int maxConnections, Callback requester)
|
||||
{
|
||||
super(destination, maxConnections, requester);
|
||||
super((HttpDestination)destination, maxConnections, requester);
|
||||
this.idleConnections = new ArrayDeque<>(maxConnections);
|
||||
this.activeConnections = new HashSet<>(maxConnections);
|
||||
}
|
||||
|
|
|
@ -340,7 +340,7 @@ public abstract class HttpDestination extends ContainerLifeCycle implements Dest
|
|||
}
|
||||
}
|
||||
|
||||
public ProcessResult process(Connection connection)
|
||||
private ProcessResult process(Connection connection)
|
||||
{
|
||||
HttpClient client = getHttpClient();
|
||||
HttpExchange exchange = getHttpExchanges().poll();
|
||||
|
|
|
@ -42,7 +42,6 @@ public class MultiplexConnectionPool extends AbstractConnectionPool implements C
|
|||
private static final Logger LOG = Log.getLogger(MultiplexConnectionPool.class);
|
||||
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private final HttpDestination destination;
|
||||
private final Deque<Holder> idleConnections;
|
||||
private final Map<Connection, Holder> muxedConnections;
|
||||
private final Map<Connection, Holder> busyConnections;
|
||||
|
@ -51,7 +50,6 @@ public class MultiplexConnectionPool extends AbstractConnectionPool implements C
|
|||
public MultiplexConnectionPool(HttpDestination destination, int maxConnections, Callback requester, int maxMultiplex)
|
||||
{
|
||||
super(destination, maxConnections, requester);
|
||||
this.destination = destination;
|
||||
this.idleConnections = new ArrayDeque<>(maxConnections);
|
||||
this.muxedConnections = new HashMap<>(maxConnections);
|
||||
this.busyConnections = new HashMap<>(maxConnections);
|
||||
|
@ -64,7 +62,7 @@ public class MultiplexConnectionPool extends AbstractConnectionPool implements C
|
|||
Connection connection = activate();
|
||||
if (connection == null)
|
||||
{
|
||||
int queuedRequests = destination.getQueuedRequestCount();
|
||||
int queuedRequests = getHttpDestination().getQueuedRequestCount();
|
||||
int maxMultiplex = getMaxMultiplex();
|
||||
int maxPending = ceilDiv(queuedRequests, maxMultiplex);
|
||||
tryCreate(maxPending);
|
||||
|
|
|
@ -42,7 +42,7 @@ public class RoundRobinConnectionPool extends AbstractConnectionPool implements
|
|||
|
||||
public RoundRobinConnectionPool(Destination destination, int maxConnections, Callback requester, int maxMultiplex)
|
||||
{
|
||||
super(destination, maxConnections, requester);
|
||||
super((HttpDestination)destination, maxConnections, requester);
|
||||
entries = new ArrayList<>(maxConnections);
|
||||
for (int i = 0; i < maxConnections; ++i)
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.eclipse.jetty.client.http;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -28,6 +29,7 @@ import org.eclipse.jetty.client.ConnectionPool;
|
|||
import org.eclipse.jetty.client.DuplexConnectionPool;
|
||||
import org.eclipse.jetty.client.EmptyServerHandler;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.HttpDestination;
|
||||
import org.eclipse.jetty.client.Origin;
|
||||
import org.eclipse.jetty.client.api.Connection;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
|
@ -205,7 +207,9 @@ public class HttpDestinationOverHTTPTest extends AbstractHttpClientServerTest
|
|||
}
|
||||
|
||||
// There are no exchanges so process() is a no-op.
|
||||
destination.process(connection1);
|
||||
Method process = HttpDestination.class.getDeclaredMethod("process", Connection.class);
|
||||
process.setAccessible(true);
|
||||
process.invoke(destination, connection1);
|
||||
destination.release(connection1);
|
||||
|
||||
Connection connection2 = connectionPool.acquire();
|
||||
|
|
Loading…
Reference in New Issue