/** Handles closing the session. */
 private void onClose() {
   if (isOpen()) {
     LOGGER.debug("Closed session: {}", id);
     this.id = 0;
     this.state = State.CLOSED;
     if (connection != null) connection.close();
     client.close();
     context.close();
     closeListeners.forEach(l -> l.accept(this));
   }
 }
Beispiel #2
0
  @Override
  public CompletableFuture<Void> close() {
    int i = 0;
    CompletableFuture<?>[] futures = new CompletableFuture[connections.size()];
    for (Connection connection : connections.values()) {
      futures[i++] = connection.close();
    }

    CompletableFuture<Void> future = new CompletableFuture<>();
    CompletableFuture.allOf(futures)
        .whenComplete(
            (result, error) -> {
              channelGroup
                  .close()
                  .addListener(
                      channelFuture -> {
                        future.complete(null);
                      });
            });
    return future;
  }