code: public boolean counterHasSpareCapacity(String resourceId) throws IOException {
      try {
        final CounterSnapshot counterSnapshot = getCounterSnapshot(resourceId);
        counterSnapshot.pickShardWithSpareCapacity(1);
        return true;
      } catch (CounterCapacityException e) {
        return false;
      }
    }
docs: Check if a resource counter has capacity to spare. Can be used as a cheaper check before starting an expensive
  operation, e.g. workflow instance dequeue. Note that even if this method returns true,
  {@link #updateCounter(StorageTransaction, String, long)} might throw {@link CounterCapacityException}.
  
  @throws RuntimeException if the resource does not exist or reading from storage fails.
  @todo Throw checked exceptions for expected failures like resource not existing.