public void updateStateAndSendEvent(long bytesUsed, String eventOrigin) {
    stats.changeTenuredHeapUsed(bytesUsed);
    synchronized (this) {
      MemoryState oldState = mostRecentEvent.getState();
      MemoryState newState = thresholds.computeNextState(oldState, bytesUsed);
      if (oldState != newState) {
        setUsageThresholdOnMXBean(bytesUsed);

        currentState = newState;

        MemoryEvent event = new MemoryEvent(ResourceType.HEAP_MEMORY, oldState, newState,
            cache.getMyId(), bytesUsed, true, thresholds);

        upcomingEvent.set(event);
        processLocalEvent(event, eventOrigin);
        updateStatsFromEvent(event);

        // The state didn't change. However, if the state isn't normal and the
        // number of bytes used changed, then go ahead and send the event
        // again with an updated number of bytes used.
      } else if (!oldState.isNormal() && bytesUsed != mostRecentEvent.getBytesUsed()) {
        MemoryEvent event = new MemoryEvent(ResourceType.HEAP_MEMORY, oldState, newState,
            cache.getMyId(), bytesUsed, true, thresholds);
        upcomingEvent.set(event);
        processLocalEvent(event, eventOrigin);
      }
    }
  }
Compare the number of bytes used to the thresholds. If necessary, change the state and send an
event for the state change.

@param bytesUsed Number of bytes of heap memory currently used.
@param eventOrigin Indicates where the event originated e.g. notification vs polling
geode-core/src/main/java/org/apache/geode/internal/cache/control/HeapMemoryMonitor.java