Example #1
0
  public synchronized String getNextName() {

    while (next >= maxAllocated) {
      final int allocate = 100 + rand.nextInt(100);

      try {
        byte[] max =
            ZooReaderWriter.getRetryingInstance()
                .mutate(
                    nextNamePath,
                    null,
                    ZooUtil.PRIVATE,
                    new ZooReaderWriter.Mutator() {
                      public byte[] mutate(byte[] currentValue) throws Exception {
                        long l = Long.parseLong(new String(currentValue), Character.MAX_RADIX);
                        l += allocate;
                        return Long.toString(l, Character.MAX_RADIX).getBytes();
                      }
                    });

        maxAllocated = Long.parseLong(new String(max), Character.MAX_RADIX);
        next = maxAllocated - allocate;

      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }

    return new String(FastFormat.toZeroPaddedString(next++, 7, Character.MAX_RADIX, new byte[0]));
  }