src/main/java/io/vertx/core/http/impl/ConnectionManager.java
pool.closeAllConnections();
void closeAllConnections()
Waiter waiter
src/main/java/io/vertx/core/http/impl/ConnectionManager.java
// Enqueue
      if (maxWaitQueueSize < 0 || waiters.size() < maxWaitQueueSize || pool.canCreateStream(connCount)) {
        if (metrics != null) {
          waiter.metric = metrics.enqueueRequest(metric);
void getConnection(Waiter waiter)
src/main/java/io/vertx/core/http/impl/ConnectionManager.java
while (true) {
        Waiter waiter = waiters.peek();
        if (waiter == null) {
          break;
void checkPending()
Waiter waiter
src/main/java/io/vertx/core/http/impl/ConnectionManager.java
connCount++;
      sslHelper.validate(vertx);
      Bootstrap bootstrap = new Bootstrap();
      bootstrap.group(waiter.context.nettyEventLoop());
      bootstrap.channel(vertx.transport().channelType(false));
      connector.connect(this, bootstrap, waiter.context, peerHost, ssl, pool.version(), host, port, ar -> {
          initConnection(waiter, ar.result());
          waiter.context.executeFromIO(() -> {
            closeConnection();
    private synchronized void initConnection(Waiter waiter, HttpClientConnection conn) {
      conn.lifecycleHandler(reuse -> {
        if (reuse) {
          recycleConnection(conn);
          evictConnection(conn);
void createConnection(Waiter waiter)
HttpClientConnection conn
src/main/java/io/vertx/core/http/impl/ConnectionManager.java
pool.evictConnection(conn);
    private synchronized void recycleConnection(HttpClientConnection conn) {
      pool.recycleConnection(conn);
    private void deliverInternal(HttpClientConnection conn, Waiter waiter) {
      if (conn.getContext().nettyEventLoop().inEventLoop()) {
        conn.getContext().executeFromIO(() -> {
          HttpClientStream stream;
          try {
            stream = pool.createStream(conn);
void evictConnection(HttpClientConnection conn)
int connCount
src/main/java/io/vertx/core/http/impl/Http1xPool.java
return connCount < maxSockets;
boolean canCreateStream(int connCount)
int connCount
src/main/java/io/vertx/core/http/impl/Http2Pool.java
for (Http2ClientConnection conn : allConnections) {
      if (canReserveStream(conn)) {
        return true;
boolean canCreateStream(int connCount)
src/main/java/io/vertx/core/http/impl/ClientConnection.java
return count++;
int use()
Waiter waiter
src/main/java/io/vertx/core/http/impl/ConnectionManager.java
HttpClientConnection conn = pool.pollConnection();
      if (conn != null) {
        conn.getContext().runOnContext(v -> deliver(conn, waiter));
        if (pool.canCreateConnection(connCount)) {
          // Create a new connection
          createNewConnection(waiter);
          // Wait in queue
          if (maxWaitQueueSize < 0 || waiters.size() < maxWaitQueueSize) {
            if (metrics != null) {
              waiter.metric = metrics.enqueueRequest(metric);
void getConnection(Waiter waiter)
src/main/java/io/vertx/core/http/impl/ConnectionManager.java
pool.closeAllConnections();
void closeAllConnections()
Waiter waiter
src/main/java/io/vertx/core/http/impl/ConnectionManager.java
ContextImpl context;
      if (waiter.context == null) {
        // Embedded
        context = vertx.getOrCreateContext();
void createNewConnection(Waiter waiter)
Waiter waiter  HttpClientConnection conn
src/main/java/io/vertx/core/http/impl/ConnectionManager.java
conn.lifecycleHandler(reuse -> recycleConnection(conn, reuse));
      deliver(conn, waiter);
void newConnection(Waiter waiter, HttpClientConnection conn)
HttpClientConnection conn  boolean reuse
src/main/java/io/vertx/core/http/impl/ConnectionManager.java
if (reuse) {
        recycle(conn);
void recycleConnection(HttpClientConnection conn, boolean reuse)
ContextImpl context  Handler<AsyncResult<HttpClientConnection>> handler
src/main/java/io/vertx/core/http/impl/ConnectionManager.java
connCount++;
      sslHelper.validate(vertx);
      Bootstrap bootstrap = new Bootstrap();
      bootstrap.group(context.nettyEventLoop());
      bootstrap.channel(vertx.transport().channelType(false));
      connector.connect(this, bootstrap, context, peerHost, ssl, pool.version(), host, port, handler);
void createNewConnection(ContextImpl context, Handler<AsyncResult<HttpClientConnection>> handler)
HttpClientConnection conn
src/main/java/io/vertx/core/http/impl/ConnectionManager.java
pool.recycleConnection(conn);
      checkPending();
void recycle(HttpClientConnection conn)
HttpClientConnection conn  Waiter waiter
src/main/java/io/vertx/core/http/impl/ConnectionManager.java
if (conn.isValid()) {
        if (!waiter.isCancelled()) {
          deliverInternal(conn, waiter);
          // Should check connection is still VALID
          recycle(conn);
        getConnection(waiter);
    private void deliverInternal(HttpClientConnection conn, Waiter waiter) {
      conn.getContext().executeFromIO(() -> {
        HttpClientStream stream;
        try {
          stream = pool.createStream(conn);
void deliver(HttpClientConnection conn, Waiter waiter)
src/main/java/io/vertx/core/http/impl/ConnectionManager.java
while (true) {
        Waiter waiter = waiters.peek();
        if (waiter == null) {
          break;
void checkPending()
src/main/java/io/vertx/core/http/impl/ConnectionManager.java
Waiter waiter = waiters.poll();
      if (metrics != null && waiter != null) {
        metrics.dequeueRequest(metric, waiter.metric);
Waiter getNextWaiter()
src/main/java/io/vertx/core/http/impl/ConnectionManager.java
Waiter waiter = getNextWaiter();
      if (waiter != null) {
        // There's a waiter - so it can have a new connection
        createNewConnection(waiter);
void connectionClosed()
src/main/java/io/vertx/core/http/impl/Http2ClientConnection.java
return count++;
int use()