@Override
  public int calcNextChildId(final File file, final int mainId) {
    int result = 0;
    File dir = getParentFile(file.getAbsoluteFile());
    int endIdx1 = file.getName().indexOf('-');
    int endIdx2 = file.getName().lastIndexOf('.');
    String baseName;
    if (endIdx1 != -1) {
      baseName = file.getName().substring(0, endIdx1);
    } else if (endIdx2 != -1) {
      baseName = file.getName().substring(0, endIdx2);
    } else {
      baseName = file.getName();
    }

    File[] children = findChildren(dir, CHILD_ID_PATTERN);

    /* Search child logs */

    for (File child : children) {
      String name = child.getName();
      // only compare the child id among the same set of files.
      if (!name.startsWith(baseName)) {
        continue;
      }
      int endIdIdx = name.lastIndexOf('-');
      int startIdIdx = name.lastIndexOf('-', endIdIdx - 1);
      String id = name.substring(startIdIdx + 1, endIdIdx);

      int startChild = name.lastIndexOf("-");
      int endChild = name.lastIndexOf(".");
      if (startChild > 0 && endChild > 0) {
        String childId = name.substring(startChild + 1, endChild);

        try {
          int mainLogId = Integer.parseInt(id);
          int childLogId = Integer.parseInt(childId);
          if (mainLogId == mainId && childLogId > result) {
            result = childLogId;
          }
        } 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