legacy/src/main/java/thredds/catalog/crawl/CatalogCrawler.java
public int crawl(InvCatalogImpl cat, CancelTask task, PrintWriter out, Object context) {

    if (out != null)
      out.println("***CATALOG " + cat.getCreateFrom());
    countCatrefs = 0;

    for (InvDataset ds : cat.getDatasets()) {
      if (type == Type.all)
        crawlDataset(ds, task, out, context, true);
      else
        crawlDirectDatasets(ds, task, out, context, true);
      if ((task != null) && task.isCancel()) break;
    }

    return 1 + countCatrefs;
  }
public int crawl(InvCatalogImpl cat, CancelTask task, PrintWriter out, Object context) {

    if (out != null)
      out.println("***CATALOG " + cat.getCreateFrom());
    countCatrefs = 0;

    for (InvDataset ds : cat.getDatasets()) {
      if (type == Type.all)
        crawlDataset(ds, task, out, context, true);
      else
        crawlDirectDatasets(ds, task, out, context, true);
      if ((task != null) && task.isCancel()) break;
    }

    return 1 + countCatrefs;
  }
Crawl a catalog thats already been opened.
When you get to a dataset containing leaf datasets, do all, only the first, or a randomly chosen one.

@param cat  the catalog
@param task user can cancel the task (may be null)
@param out  send status messages to here (may be null)
@param context caller can pass this object in (used for thread safety)
@return number of catalog references opened and crawled