class StreamConnectionManager {

  public Optional<StreamConnection> closeConnection(final StreamConnectionId streamConnectionId) {
    Objects.requireNonNull(streamConnectionId);

    // WARNING: Don't ever remove the connection once it's closed. Closed connections MUST never be re-used so that they
    // don't accidentally use a sequence number that exceeds the StreamConnection.MAX_FRAMES_PER_CONNECTION
    return Optional.ofNullable(connections.get(streamConnectionId))
        .map(connectionToClose -> {
          connectionToClose.closeConnection();
          return connectionToClose;
        });
  }

}