public Iterator getHistory()

in src/main/java/com/uber/cadence/internal/replay/ReplayDecider.java [668:732]


    public Iterator<HistoryEvent> getHistory() {
      return new Iterator<HistoryEvent>() {
        @Override
        public boolean hasNext() {
          return current.hasNext() || nextPageToken != null;
        }

        @Override
        public HistoryEvent next() {
          if (current.hasNext()) {
            return current.next();
          }

          Duration decisionTaskRemainingTime = decisionTaskRemainingTime();
          if (decisionTaskRemainingTime.isNegative() || decisionTaskRemainingTime.isZero()) {
            throw new Error(
                "Decision task timed out while querying history. If this happens consistently please consider "
                    + "increase decision task timeout or reduce history size.");
          }

          metricsScope.counter(MetricsType.WORKFLOW_GET_HISTORY_COUNTER).inc(1);
          Stopwatch sw = metricsScope.timer(MetricsType.WORKFLOW_GET_HISTORY_LATENCY).start();
          RetryOptions retryOptions =
              new RetryOptions.Builder()
                  .setExpiration(decisionTaskRemainingTime)
                  .setInitialInterval(retryServiceOperationInitialInterval)
                  .setMaximumInterval(retryServiceOperationMaxInterval)
                  .build();

          GetWorkflowExecutionHistoryRequest request = new GetWorkflowExecutionHistoryRequest();
          request
              .setDomain(context.getDomain())
              .setExecution(task.getWorkflowExecution())
              .setMaximumPageSize(MAXIMUM_PAGE_SIZE)
              .setNextPageToken(nextPageToken);

          try {
            GetWorkflowExecutionHistoryResponse r =
                RpcRetryer.retryWithResult(
                    retryOptions, () -> service.GetWorkflowExecutionHistory(request));
            current = r.getHistory().getEventsIterator();
            nextPageToken = r.getNextPageToken();
            metricsScope.counter(MetricsType.WORKFLOW_GET_HISTORY_SUCCEED_COUNTER).inc(1);
            sw.stop();
          } catch (TException e) {
            metricsScope.counter(MetricsType.WORKFLOW_GET_HISTORY_FAILED_COUNTER).inc(1);
            throw new Error(e);
          }
          if (!current.hasNext()) {
            log.error(
                "GetWorkflowExecutionHistory returns an empty history, maybe a bug in server, workflowID:"
                    + request.execution.workflowId
                    + ", runID:"
                    + request.execution.runId
                    + ", domain:"
                    + request.domain
                    + " token:"
                    + Arrays.toString(request.getNextPageToken()));
            throw new Error(
                "GetWorkflowExecutionHistory return empty history, maybe a bug in server");
          }
          return current.next();
        }
      };
    }