code: void reconnect() throws InterruptedException {
          long maxTries = options.getMaxReconnect();
          long tries = 0;
          String lastServer = null;
  
          if (isClosed()) {
              return;
          }
  
          if (maxTries == 0) {
              this.close();
              return;
          }
  
          this.writer.setReconnectMode(true);
  
          while (!isConnected() && !isClosed() && !this.isClosing()) {
              Collection<String> serversToTry = buildReconnectList();
  
              for (String server : serversToTry) {
                  if (isClosed()) {
                      break;
                  }
  
                  if (server.equals(lastServer)) {
                      this.reconnectWaiter = new CompletableFuture<>();
                      waitForReconnectTimeout();
                  }
  
                  if (isDisconnectingOrClosed() || this.isClosing()) {
                      break;
                  }
  
                  updateStatus(Status.RECONNECTING);
  
                  tryToConnect(server);
                  lastServer = server;
                  tries++;
  
                  if (maxTries > 0 && tries >= maxTries) {
                      break;
                  } else if (isConnected()) {
                      this.statistics.incrementReconnects();
                      break;
                  }
              }
  
              if (maxTries > 0 && tries >= maxTries) {
                  break;
              }
          }
  
          if (!isConnected()) {
              this.close();
              return;
          }
  
          this.subscribers.forEach((sid, sub) -> {
              if (sub.getDispatcher() == null && !sub.isDraining()) {
                  sendSubscriptionMessage(sub.getSID(), sub.getSubject(), sub.getQueueName(), true);
              }
          });
  
          this.dispatchers.forEach((nuid, d) -> {
              if (!d.isDraining()) {
                  d.resendSubscriptions();
              }
          });
  
          try {
              this.flush(this.options.getConnectionTimeout());
          } catch (Exception exp) {
              this.processException(exp);
          }
          
          // When the flush returns we are done sending internal messages, so we can switch to the
          // non-reconnect queue
          this.writer.setReconnectMode(false);
  
          processConnectionEvent(Events.RESUBSCRIBED);
      }
docs: Reconnect can only be called when the connection is disconnected