code: private void aggregateTasklets(final AggregateTriggerType type) {
      final List<WorkerToMasterReport> workerToMasterReports = new ArrayList<>();
      final List<Object> results = new ArrayList<>();
      final List<Integer> aggregatedTasklets = new ArrayList<>();
  
      // Synchronization to prevent duplication of work on the same aggregation function on the same worker.
      synchronized (stateLock) {
        switch(type) {
        case ALARM:
          aggregateTasklets(workerToMasterReports, results, aggregatedTasklets);
          break;
        case COUNT:
          if (!aggregateOnCount()) {
            return;
          }
  
          aggregateTasklets(workerToMasterReports, results, aggregatedTasklets);
          break;
        default:
          throw new RuntimeException("Unexpected aggregate type.");
        }
      }
  
      if (!results.isEmpty()) {
        // Run the aggregation function.
        try {
          final Object aggregationResult = taskletAggregationRequest.executeAggregation(results);
          workerToMasterReports.add(new TaskletAggregationResultReport(aggregatedTasklets, aggregationResult));
        } catch (final Exception e) {
          workerToMasterReports.add(new TaskletAggregationFailureReport(aggregatedTasklets, e));
        }
      }
  
      // Add to worker report only if there is something to report back.
      if (!workerToMasterReports.isEmpty()) {
        workerReportsQueue.addLast(kryoUtils.serialize(new WorkerToMasterReports(workerToMasterReports)));
        heartBeatTriggerManager.triggerHeartBeat();
      }
    }
docs: Performs the output aggregation and generates the {@link WorkerToMasterReports} to report back to the
  {@link org.apache.reef.vortex.driver.VortexDriver}.