code: public void removeSession(String key, Session doomedSession) {
          SessionEntry removedEntry = null;
  
          // If no session was passed in, remove any session associated with the given key.
          // If a session was passed in, only remove it if the key is associated with that session.
          // This is to support the need to close extra sessions a feed might have created.
  
          sessionsLockWrite.lock();
          try {
              if (doomedSession == null) {
                  removedEntry = this.sessions.remove(key);
              } else {
                  /* here between sessions.get() and sessions.remove() the write lock is especially important */
                  SessionEntry existingEntry = this.sessions.get(key);
                  if (existingEntry != null && existingEntry.getSession().getId().equals(doomedSession.getId())) {
                      removedEntry = this.sessions.remove(key);
                  }
              }
  
              if (removedEntry != null) {
                  /* we really removed a session, let's call its listeners */
                  removedEntry.removed();
                  log.debugf(
                          "WebSocket Session [%s] of [%s] with key [%s] has been removed."
                                  + " The endpoint has now [%d] sessions",
                          removedEntry.getSession().getId(), endpoint, key, this.sessions.size());
              }
          } finally {
              sessionsLockWrite.unlock();
          }
  
      }
docs: Removes the session associated with the given {@code key}. If {@code doomedSession} is not {@code null}, the
  session matching the given {@code key} in {@link #sessions} will only be removed if that session has the same ID
  as the given {@code doomedSession}.
  <p>
  When removing a known session, that doomed session's websocket session listeners will be told via
  {@link WsSessionListener#sessionRemoved()}.
  
  @param key identifies the session to be removed
  @param doomedSession if not null, ensures that only this session will be removed
  @return the removed session or null if nothing was removed