class BaragonRequestWorker implements Runnable {

  @VisibleForTesting
  static Comparator<QueuedRequestWithState> queuedRequestComparator() {
    return (requestA, requestB) -> {
      // noValidate & noReload comes first
      if ((requestA.getRequest().isNoValidate() && requestA.getRequest().isNoReload()) && (!requestB.getRequest().isNoReload() || !requestB.getRequest().isNoValidate())) {
        return -1;
      }

      if ((requestB.getRequest().isNoValidate() && requestB.getRequest().isNoReload()) && (!requestA.getRequest().isNoReload() || !requestA.getRequest().isNoValidate())) {
        return 1;
      }

      // Then noValidate *or* noReload
      if ((requestA.getRequest().isNoValidate() || requestA.getRequest().isNoReload()) && (!requestB.getRequest().isNoReload() && !requestB.getRequest().isNoValidate())) {
        return -1;
      }

      if ((requestB.getRequest().isNoValidate() || requestB.getRequest().isNoReload()) && (!requestA.getRequest().isNoReload() && !requestA.getRequest().isNoValidate())) {
        return 1;
      }

      // Then everything else, oldest first
      return Integer.compare(requestA.getQueuedRequestId().getIndex(), requestB.getQueuedRequestId().getIndex());
    };
  }

  @Inject public  BaragonRequestWorker(AgentManager agentManager,
                              RequestManager requestManager,
                              BaragonStateDatastore stateDatastore,
                              BaragonExceptionNotifier exceptionNotifier,
                              BaragonConfiguration configuration,
                              EdgeCache edgeCache,
                              UpstreamResolver resolver,
                              @Named(BaragonDataModule.BARAGON_SERVICE_WORKER_LAST_START) AtomicLong workerLastStartAt);

}