@Override
  public int calcNextMainId(final File dir, final boolean toCreateNew) {
    int result = 0;
    File[] children = findChildren(dir, MAIN_ID_PATTERN);

    /* Search child logs */
    for (File child : children) {
      String name = child.getName();
      int endIdIdx = name.lastIndexOf('-');
      int startIdIdx = name.lastIndexOf('-', endIdIdx - 1);
      String id = name.substring(startIdIdx + 1, endIdIdx);
      try {
        int mid = Integer.parseInt(id);
        if (mid > result) {
          result = mid;
        }
      } catch (NumberFormatException ignore) {
      }
    }

    /* And search meta logs */
    if (toCreateNew) {
      File[] metaFiles = findChildren(dir, META_ID_PATTERN);
      for (File metaFile : metaFiles) {
        String name = metaFile.getName();
        int endIdIdx = name.lastIndexOf('.');
        int startIdIdx = name.lastIndexOf('-', endIdIdx - 1);
        String id = name.substring(startIdIdx + 1, endIdIdx);
        try {
          int mid = Integer.parseInt(id);
          if (mid > result) {
            result = mid;
          }
        } catch (NumberFormatException ignore) {
        }
      }
      result++;
    }

    return result;
  }
Extracted from ManagerLogWriter. MainWithChildrenRollingFileHandler is used for both rolling of
log files and stat archive files.
geode-core/src/main/java/org/apache/geode/internal/io/MainWithChildrenRollingFileHandler.java