code: public synchronized Runnable addAllocationThreshold(ThresholdDirection direction, long threshold, Runnable action) {
        switch (direction) {
          case RISING:
            return risingThresholds.put(threshold, action);
          case FALLING:
            return fallingThresholds.put(threshold, action);
        }
        throw new AssertionError();
      }
docs: Adds an allocation threshold action.
  <p>
  There can be only a single action associated with each unique direction
  and threshold combination.  If an action is already associated with the
  supplied combination then the action is replaced by the new action and the
  old action is returned.
  <p>
  Actions are fired on passing through the supplied threshold and are called
  synchronously with the triggering allocation.  This means care must be taken
  to avoid mutating any map that uses this page source from within the action
  otherwise deadlocks may result.  Exceptions thrown by the action will be
  caught and logged by the page source and will not be propagated on the
  allocating thread.
  
  @param direction new actions direction
  @param threshold new actions threshold level
  @param action fired on breaching the threshold
  @return the replaced action or {@code null} if no action was present.