void flush() {
   sendMessages();
   if (disconnect) {
     ClientSessionHandler handler = handlers.get(sessionRefId);
     /*
      * If session is local, disconnect session; otherwise, log
      * error message.
      */
     if (handler != null) {
       handler.handleDisconnect(false);
     } else {
       logger.log(
           Level.FINE, "discarding request to disconnect unknown session:{0}", sessionRefId);
     }
   }
 }
 /**
  * Validates the {@code identity} of the user logging in and returns {@code true} if the login is
  * allowed to proceed, and {@code false} if the login is denied.
  *
  * <p>A user with the specified {@code identity} is allowed to log in if one of the following
  * conditions holds:
  *
  * <ul>
  *   <li>the {@code identity} is not currently logged in, or
  *   <li>the {@code identity} is logged in, and the {@code
  *       com.sun.sgs.impl.service.session.allow.new.login} property is set to {@code true}.
  * </ul>
  *
  * In the latter case (new login allowed), the existing user session logged in with {@code
  * identity} is forcibly disconnected.
  *
  * <p>If this method returns {@code true}, the {@link #removeUserLogin} method must be invoked
  * when the user with the specified {@code identity} is disconnected.
  *
  * @param identity the user identity
  * @param handler the client session handler
  * @return {@code true} if the user is allowed to log in with the specified {@code identity},
  *     otherwise returns {@code false}
  */
 boolean validateUserLogin(Identity identity, ClientSessionHandler handler) {
   ClientSessionHandler previousHandler = loggedInIdentityMap.putIfAbsent(identity, handler);
   if (previousHandler == null) {
     // No user logged in with the same idenity; allow login.
     return true;
   } else if (!allowNewLogin) {
     // Same user logged in; new login not allowed, so deny login.
     return false;
   } else if (!previousHandler.loginHandled()) {
     // Same user logged in; can't preempt user in the
     // process of logging in; deny login.
     return false;
   } else {
     if (loggedInIdentityMap.replace(identity, previousHandler, handler)) {
       // Disconnect current user; allow new login.
       previousHandler.handleDisconnect(false, true);
       return true;
     } else {
       // Another same user login beat this one; deny login.
       return false;
     }
   }
 }