class GetRegionsFunction implements InternalFunction<Void> {

  @Override
  public void execute(FunctionContext<Void> functionContext) {
    try {
      Cache cache = functionContext.getCache();
      Set<Region<?, ?>> regions = cache.rootRegions(); // should never return a null

      if (regions == null || regions.isEmpty()) {
        functionContext.getResultSender().lastResult(null);
      } else {
        Set<RegionInformation> regionInformationSet = new HashSet<>();

        for (Region<?, ?> region : regions) {
          RegionInformation regInfo = new RegionInformation(region, true);
          regionInformationSet.add(regInfo);
        }
        functionContext.getResultSender()
            .lastResult(regionInformationSet.toArray(new RegionInformation[0]));
      }
    } catch (Exception e) {
      functionContext.getResultSender().sendException(e);
    }
  }

}