public int obtain() {
    synchronized (this) {
      int candidate = ctr;
      int result = nextClearBit(candidate);
      if (result == -1 && candidate != 0) {
        // The following check will do some additional work by scanning
        // the range [candidate..MAX_ID] again if it does not find a clear bit
        // in the range [0..candidate-1] but it will only do this when
        // we are going to throw an exception.
        result = nextClearBit(0);
      }
      if (result == -1) {
        throw new IllegalStateException(
            "Ran out of message ids");
      } else {
        setBit(result);
        if (result == MAX_ID) {
          ctr = 0;
        } else {
          ctr = result + 1;
        }
        return result;
      }
    }
  }
Obtain an id form the pool of available ids and return it.

@throws IllegalStateException if all ids have been obtained
geode-core/src/main/java/org/apache/geode/internal/UniqueIdGenerator.java