@Override
    public void execute(FunctionContext context) {
      RegionFunctionContext ctx = (RegionFunctionContext) context;

      final WindowedArgs<K, V> args = (WindowedArgs<K, V>) ctx.getArguments();
      ResultSender<SnapshotPacket> rs = ctx.getResultSender();

      Region<K, V> region = ctx.getDataSet();
      if (PartitionRegionHelper.isPartitionedRegion(region)) {
        region = PartitionRegionHelper.getLocalDataForContext(ctx);
      }

      LocalRegion local = RegionSnapshotServiceImpl.getLocalRegion(region);
      window = FlowController.getInstance().create(region, args.getExporter(), WINDOW_SIZE);

      try {
        int bufferSize = 0;
        List<SnapshotRecord> buffer = new ArrayList<>();
        DistributedMember me = region.getCache().getDistributedSystem().getDistributedMember();
        for (Iterator<Entry<K, V>> iter = region.entrySet().iterator(); iter.hasNext()
            && !window.isAborted();) {
          Entry<K, V> entry = iter.next();
          try {
            SnapshotOptions<K, V> options = args.getOptions();
            if (options.getFilter() == null || options.getFilter().accept(entry)) {
              SnapshotRecord rec = new SnapshotRecord(local, entry);
              buffer.add(rec);
              bufferSize += rec.getSize();
            }
          } catch (EntryDestroyedException e) {
            // continue to next entry

          } catch (IOException e) {
            throw new FunctionException(e);
          }

          if (bufferSize > RegionSnapshotServiceImpl.BUFFER_SIZE) {
            window.waitForOpening();
            rs.sendResult(new SnapshotPacket(window.getWindowId(), me, buffer));
            buffer.clear();
            bufferSize = 0;
          }
        }

        window.waitForOpening();
        rs.lastResult(new SnapshotPacket(window.getWindowId(), me, buffer));
        if (getLogger().fineEnabled()) {
          getLogger().fine("SNP: Sent all entries in region " + region.getName());
        }

      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new FunctionException(e);

      } finally {
        window.close();
      }
    }
Gathers the local data on the region and sends it back to the {@link ResultCollector} in
serialized form as {@link SnapshotPacket}s. Uses a sliding window provided by the
{@link FlowController} to avoid over-running the exporting member.

@param <K> the key type
@param <V> the value type

@see FlowController
geode-core/src/main/java/org/apache/geode/internal/cache/snapshot/WindowedExporter.java