geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientHealthMonitor.java
@Override
    public void run() {
      if (logger.isDebugEnabled()) {
        logger.debug("{}: Beginning to monitor clients", ClientHealthMonitor.this);
      }

      while (!this._isStopped) {
        SystemFailure.checkFailure();
        try {
          Thread.sleep(monitorInterval);
          if (logger.isTraceEnabled()) {
            logger.trace("Monitoring {} client(s)", getClientHeartbeats().size());
          }
          // logger.warning("Monitoring " + getClientHeartbeats().size() +
          // " client(s).");

          // Get the current time
          long currentTime = System.currentTimeMillis();
          if (logger.isTraceEnabled()) {
            logger.trace("{} starting sweep at {}", ClientHealthMonitor.this, currentTime);
          }

          // Iterate through the clients and verify that they are all still
          // alive
          for (Iterator i = getClientHeartbeats().entrySet().iterator(); i.hasNext();) {
            Map.Entry entry = (Map.Entry) i.next();
            ClientProxyMembershipID proxyID = (ClientProxyMembershipID) entry.getKey();
            // Validate all ServerConnection threads. If a thread has been
            // processing a message for more than the socket timeout time,
            // close it it since the client will have timed out and resent.
            validateThreads(proxyID);

            Long latestHeartbeatValue = (Long) entry.getValue();
            // Compare the current value with the current time if it is not null
            // If it is null, that means that the client was just registered
            // and has not done a heartbeat yet.
            if (latestHeartbeatValue != null) {
              long latestHeartbeat = latestHeartbeatValue.longValue();
              if (logger.isTraceEnabled()) {
                logger.trace(
                    "{} ms have elapsed since the latest heartbeat for client with member id {}",
                    (currentTime - latestHeartbeat), proxyID);
              }

              if ((currentTime - latestHeartbeat) > this._maximumTimeBetweenPings) {
                // This client has been idle for too long. Determine whether
                // any of its ServerConnection threads are currently processing
                // a message. If so, let it go. If not, disconnect it.
                if (isAnyThreadProcessingMessage(proxyID)) {
                  if (logger.isDebugEnabled()) {
                    logger.debug(
                        "Monitoring client with member id {}. It has been {} ms since the latest heartbeat. This client would have been terminated but at least one of its threads is processing a message.",
                        entry.getKey(), (currentTime - latestHeartbeat));
                  }
                } else {
                  if (cleanupClientThreads(proxyID, true)) {
                    logger.warn(LocalizedMessage.create(
                        LocalizedStrings.ClientHealthMonitor_MONITORING_CLIENT_WITH_MEMBER_ID_0_IT_HAD_BEEN_1_MS_SINCE_THE_LATEST_HEARTBEAT_MAX_INTERVAL_IS_2_TERMINATED_CLIENT,
                        new Object[] {entry.getKey(), currentTime - latestHeartbeat,
                            this._maximumTimeBetweenPings}));
                  }
                }
              } else {
                if (logger.isTraceEnabled()) {
                  logger.trace(
                      "Monitoring client with member id {}. It has been {} ms since the latest heartbeat. This client is healthy.",
                      entry.getKey(), (currentTime - latestHeartbeat));
                }
                // logger.warning("Monitoring client with member id " +
                // entry.getKey() + ". It has been " + (currentTime -
                // latestHeartbeat) + " ms since the latest heartbeat. This
                // client is healthy.");
              }
            }
          }
        } catch (InterruptedException e) {
          // no need to reset the bit; we're exiting
          if (this._isStopped) {
            break;
          }
          logger.warn(LocalizedMessage
              .create(LocalizedStrings.ClientHealthMonitor_UNEXPECTED_INTERRUPT_EXITING), e);
          break;
        } catch (Exception e) {
          // An exception occurred while monitoring the clients. If the monitor
          // is not stopped, log it and continue processing.
          if (!this._isStopped) {
            logger.fatal(LocalizedMessage.create(
                LocalizedStrings.ClientHealthMonitor_0_AN_UNEXPECTED_EXCEPTION_OCCURRED,
                ClientHealthMonitor.this), e);
          }
        }
      } // while
    }
/**
     * Runs the monitor by iterating the map of clients and testing the latest ping time received
     * against the current time.
     */
Runs the monitor by iterating the map of clients and testing the latest ping time received
against the current time.
Runs the monitor by iterating the map of clients and testing the latest ping time received against the current time .
@Override
    public void run() {
      if (logger.isDebugEnabled()) {
        logger.debug("{}: Beginning to monitor clients", ClientHealthMonitor.this);
      }
      while (!this._isStopped) {
        SystemFailure.checkFailure();
        try {
          Thread.sleep(monitorInterval);
          if (logger.isTraceEnabled()) {
            logger.trace("Monitoring {} client(s)", getClientHeartbeats().size());
          }
          long currentTime = System.currentTimeMillis();
          if (logger.isTraceEnabled()) {
            logger.trace("{} starting sweep at {}", ClientHealthMonitor.this, currentTime);
          }
          for (Iterator i = getClientHeartbeats().entrySet().iterator(); i.hasNext();) {
            Map.Entry entry = (Map.Entry) i.next();
            ClientProxyMembershipID proxyID = (ClientProxyMembershipID) entry.getKey();
            validateThreads(proxyID);
            Long latestHeartbeatValue = (Long) entry.getValue();
            if (latestHeartbeatValue != null) {
              long latestHeartbeat = latestHeartbeatValue.longValue();
              if (logger.isTraceEnabled()) {
                logger.trace(
                    "{} ms have elapsed since the latest heartbeat for client with member id {}",
                    (currentTime - latestHeartbeat), proxyID);
              }
              if ((currentTime - latestHeartbeat) > this._maximumTimeBetweenPings) {
                if (isAnyThreadProcessingMessage(proxyID)) {
                  if (logger.isDebugEnabled()) {
                    logger.debug(
                        "Monitoring client with member id {}. It has been {} ms since the latest heartbeat. This client would have been terminated but at least one of its threads is processing a message.",
                        entry.getKey(), (currentTime - latestHeartbeat));
                  }
                } else {
                  if (cleanupClientThreads(proxyID, true)) {
                    logger.warn(LocalizedMessage.create(
                        LocalizedStrings.ClientHealthMonitor_MONITORING_CLIENT_WITH_MEMBER_ID_0_IT_HAD_BEEN_1_MS_SINCE_THE_LATEST_HEARTBEAT_MAX_INTERVAL_IS_2_TERMINATED_CLIENT,
                        new Object[] {entry.getKey(), currentTime - latestHeartbeat,
                            this._maximumTimeBetweenPings}));
                  }
                }
              } else {
                if (logger.isTraceEnabled()) {
                  logger.trace(
                      "Monitoring client with member id {}. It has been {} ms since the latest heartbeat. This client is healthy.",
                      entry.getKey(), (currentTime - latestHeartbeat));
                }
              }
            }
          }
        } catch (InterruptedException e) {
          if (this._isStopped) {
            break;
          }
          logger.warn(LocalizedMessage
              .create(LocalizedStrings.ClientHealthMonitor_UNEXPECTED_INTERRUPT_EXITING), e);
          break;
        } catch (Exception e) {
          if (!this._isStopped) {
            logger.fatal(LocalizedMessage.create(
                LocalizedStrings.ClientHealthMonitor_0_AN_UNEXPECTED_EXCEPTION_OCCURRED,
                ClientHealthMonitor.this), e);
          }
        }
      } 
    }
@ Override public void run ( ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "{}: Beginning to monitor clients" , ClientHealthMonitor . this ) ; } while ( ! this . _isStopped ) { SystemFailure . checkFailure ( ) ; try { Thread . sleep ( monitorInterval ) ; if ( logger . isTraceEnabled ( ) ) { logger . trace ( "Monitoring {} client(s)" , getClientHeartbeats ( ) . size ( ) ) ; } long currentTime = System . currentTimeMillis ( ) ; if ( logger . isTraceEnabled ( ) ) { logger . trace ( "{} starting sweep at {}" , ClientHealthMonitor . this , currentTime ) ; } for ( Iterator i = getClientHeartbeats ( ) . entrySet ( ) . iterator ( ) ; i . hasNext ( ) ; ) { Map . Entry entry = ( Map . Entry ) i . next ( ) ; ClientProxyMembershipID proxyID = ( ClientProxyMembershipID ) entry . getKey ( ) ; validateThreads ( proxyID ) ; Long latestHeartbeatValue = ( Long ) entry . getValue ( ) ; if ( latestHeartbeatValue != null ) { long latestHeartbeat = latestHeartbeatValue . longValue ( ) ; if ( logger . isTraceEnabled ( ) ) { logger . trace ( "{} ms have elapsed since the latest heartbeat for client with member id {}" , ( currentTime - latestHeartbeat ) , proxyID ) ; } if ( ( currentTime - latestHeartbeat ) > this . _maximumTimeBetweenPings ) { if ( isAnyThreadProcessingMessage ( proxyID ) ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Monitoring client with member id {}. It has been {} ms since the latest heartbeat. This client would have been terminated but at least one of its threads is processing a message." , entry . getKey ( ) , ( currentTime - latestHeartbeat ) ) ; } } else { if ( cleanupClientThreads ( proxyID , true ) ) { logger . warn ( LocalizedMessage . create ( LocalizedStrings . ClientHealthMonitor_MONITORING_CLIENT_WITH_MEMBER_ID_0_IT_HAD_BEEN_1_MS_SINCE_THE_LATEST_HEARTBEAT_MAX_INTERVAL_IS_2_TERMINATED_CLIENT , new Object [ ] { entry . getKey ( ) , currentTime - latestHeartbeat , this . _maximumTimeBetweenPings } ) ) ; } } } else { if ( logger . isTraceEnabled ( ) ) { logger . trace ( "Monitoring client with member id {}. It has been {} ms since the latest heartbeat. This client is healthy." , entry . getKey ( ) , ( currentTime - latestHeartbeat ) ) ; } } } } } catch ( InterruptedException e ) { if ( this . _isStopped ) { break ; } logger . warn ( LocalizedMessage . create ( LocalizedStrings . ClientHealthMonitor_UNEXPECTED_INTERRUPT_EXITING ) , e ) ; break ; } catch ( Exception e ) { if ( ! this . _isStopped ) { logger . fatal ( LocalizedMessage . create ( LocalizedStrings . ClientHealthMonitor_0_AN_UNEXPECTED_EXCEPTION_OCCURRED , ClientHealthMonitor . this ) , e ) ; } } } }
Runs the monitor by iterating the map of clients and testing the latest ping time received
 against the current time.
Runs the monitor by iterating the map of clients and testing the latest ping time received against the current time .
// logger.warning("Monitoring " + getClientHeartbeats().size() + // " client(s)."); // Get the current time // Iterate through the clients and verify that they are all still // alive // Validate all ServerConnection threads. If a thread has been // processing a message for more than the socket timeout time, // close it it since the client will have timed out and resent. // Compare the current value with the current time if it is not null // If it is null, that means that the client was just registered // and has not done a heartbeat yet. // This client has been idle for too long. Determine whether // any of its ServerConnection threads are currently processing // a message. If so, let it go. If not, disconnect it. // logger.warning("Monitoring client with member id " + // entry.getKey() + ". It has been " + (currentTime - // latestHeartbeat) + " ms since the latest heartbeat. This // client is healthy."); // no need to reset the bit; we're exiting // An exception occurred while monitoring the clients. If the monitor // is not stopped, log it and continue processing. // while