function $AdfXhrPoolManager$$($requestQueueManager$$) {
  this.Init($requestQueueManager$$);
}
$goog$exportSymbol$$("AdfXhrPoolManager", $AdfXhrPoolManager$$);
$AdfObject$$.$createSubclass$($AdfXhrPoolManager$$);
$AdfXhrPoolManager$$.$InitClass$ = function $$AdfXhrPoolManager$$$$InitClass$$() {
};
$goog$exportSymbol$$("AdfXhrPoolManager.InitClass", $AdfXhrPoolManager$$.$InitClass$);
$AdfXhrPoolManager$$.prototype.Init = function $$AdfXhrPoolManager$$$$Init$($requestQueueManager$$1$$) {
  $AdfXhrPoolManager$$.$superclass$.Init.call(this);
  for (var $maxAvailableConns$$inline_618$$ = $AdfAgent$$.$AGENT$.$getMaxConnectionsPerDomain$() - 2, $maxAvailableConns$$inline_618$$ = 0 >= $maxAvailableConns$$inline_618$$ ? 1 : $maxAvailableConns$$inline_618$$, $connectionTokens$$inline_619$$ = [], $i$$inline_620$$ = 1;$i$$inline_620$$ <= $maxAvailableConns$$inline_618$$;$i$$inline_620$$++) {
    $connectionTokens$$inline_619$$[$i$$inline_620$$] = $i$$inline_620$$;
  }
  this.$_connectionTokens$ = $connectionTokens$$inline_619$$;
  window.Map && (this.$_progressRequests$ = new Map, this.$_progressRequests$.forEach || (this.$_progressRequests$ = null));
  this.$_requestQueueManager$ = $requestQueueManager$$1$$;
  this.$_requestQueueManager$.$registerRequestQueuedListener$(this.$createCallback$(this.$_drainRequests$));
};
$AdfObject$$.$exportPrototypeSymbol$("AdfXhrPoolManager.prototype.Init", {Init:$AdfXhrPoolManager$$.prototype.Init});
$AdfXhrPoolManager$$.prototype.$hasDispatchedPriorityRequests$ = function $$AdfXhrPoolManager$$$$$hasDispatchedPriorityRequests$$() {
  if (!this.$_progressRequests$) {
    return !1;
  }
  var $hasDispatchedPriorityRequests$$ = !1;
  this.$_progressRequests$.forEach(function($requestItem$$) {
    $requestItem$$[$AdfRestDataService$$.$PRIORITIZE$] && ($hasDispatchedPriorityRequests$$ = !0);
  });
  return $hasDispatchedPriorityRequests$$;
};
$AdfObject$$.$exportPrototypeSymbol$("AdfXhrPoolManager.prototype.hasDispatchedPriorityRequests", {$hasDispatchedPriorityRequests$:$AdfXhrPoolManager$$.prototype.$hasDispatchedPriorityRequests$});
$AdfXhrPoolManager$$.$_createConfiguredXhr$ = function $$AdfXhrPoolManager$$$$_createConfiguredXhr$$($dispatchRequest$$1$$, $httpMethod$$) {
  var $decoratedXhrObject_xhrObject$$ = new XMLHttpRequest;
  $decoratedXhrObject_xhrObject$$.open($httpMethod$$, $dispatchRequest$$1$$.$actionURL$, !0);
  $decoratedXhrObject_xhrObject$$ = $AdfRestXhrFactory$$.$__getXhr$($decoratedXhrObject_xhrObject$$, $AdfXhrPoolManager$$.$_getXhrProps$($dispatchRequest$$1$$));
  $AdfAssert$$.assert($decoratedXhrObject_xhrObject$$.readyState != XMLHttpRequest.$HEADERS_RECEIVED$ && $decoratedXhrObject_xhrObject$$.readyState != XMLHttpRequest.LOADING);
  $decoratedXhrObject_xhrObject$$.setRequestHeader("Accept", "application/json");
  $decoratedXhrObject_xhrObject$$.responseType = "json";
  return $decoratedXhrObject_xhrObject$$;
};
$AdfXhrPoolManager$$.$_getXhrProps$ = function $$AdfXhrPoolManager$$$$_getXhrProps$$($dispatchRequest$$2$$) {
  var $decoratedXhrProps$$ = {};
  $decoratedXhrProps$$[$AdfRestXhrFactory$$.$URL_KEY$] = $dispatchRequest$$2$$.$actionURL$;
  $decoratedXhrProps$$[$AdfRestXhrFactory$$.$CLIENT_ID_LIST_KEY$] = $AdfRestRequestQueueManager$$.$getClientIdList$($dispatchRequest$$2$$);
  return $decoratedXhrProps$$;
};
function $JSCompiler_StaticMethods__dispatch$$($JSCompiler_StaticMethods__dispatch$self$$, $dispatchRequest$$3$$, $token$$12$$) {
  var $requestData$$3$$ = $dispatchRequest$$3$$.options[0][$AdfRestDataService$$.$REQUEST_DATA$], $xhrObject$$1$$ = $AdfXhrPoolManager$$.$_createConfiguredXhr$($dispatchRequest$$3$$, $requestData$$3$$.method);
  $xhrObject$$1$$.onreadystatechange = function $$xhrObject$$1$$$onreadystatechange$() {
    if ($xhrObject$$1$$.readyState === XMLHttpRequest.DONE) {
      $AdfPage$$.$PAGE$.$__perfTimings$(!1, !1, !0, "REST response received: status\x3d ", $xhrObject$$1$$.status, ", url\x3d", $dispatchRequest$$3$$.$actionURL$);
      $JSCompiler_StaticMethods__dispatch$self$$.$_progressRequests$["delete"]($dispatchRequest$$3$$.$actionURL$);
      $JSCompiler_StaticMethods__dispatch$self$$.$_connectionTokens$.push($token$$12$$);
      $JSCompiler_StaticMethods__dispatch$self$$.$_drainRequests$();
      var $requestData$$3$$ = $AdfPage$$.$PAGE$.$getRestDataService$();
      200 == $xhrObject$$1$$.status ? $requestData$$3$$.$__xhrCallback$($dispatchRequest$$3$$, $AdfRestDataService$$.$SUCCESS_CALLBACK_KEY$, [$xhrObject$$1$$.response]) : $requestData$$3$$.$__xhrCallback$($dispatchRequest$$3$$, $AdfRestDataService$$.$ERROR_CALLBACK_KEY$, [$xhrObject$$1$$.status, $xhrObject$$1$$.response]);
    }
  };
  $xhrObject$$1$$.readyState <= XMLHttpRequest.$OPENED$ ? ($AdfPage$$.$PAGE$.$__perfTimings$(!1, !1, !0, "REST request sent: url\x3d", $dispatchRequest$$3$$.$actionURL$), $xhrObject$$1$$.send($requestData$$3$$.body)) : $AdfLogger$$.$LOGGER$.warning("XHR request to '" + $dispatchRequest$$3$$.$actionURL$ + "' already issued by the request callback. The connection token usedfor this request was " + $token$$12$$);
}
$AdfXhrPoolManager$$.prototype.$_drainRequests$ = function $$AdfXhrPoolManager$$$$$_drainRequests$$() {
  if (this.$_progressRequests$) {
    do {
      for (var $peekedRequest$$inline_629_token$$13$$ = this.$_requestQueueManager$.first();$peekedRequest$$inline_629_token$$13$$;) {
        var $dispatchedRequest$$inline_630_nextReqToProcess$$1$$ = this.$_progressRequests$.get($peekedRequest$$inline_629_token$$13$$.$actionURL$);
        if (!$dispatchedRequest$$inline_630_nextReqToProcess$$1$$) {
          break;
        }
        $AdfRestRequestQueueManager$$.$markDead$($peekedRequest$$inline_629_token$$13$$);
        $dispatchedRequest$$inline_630_nextReqToProcess$$1$$.options = $dispatchedRequest$$inline_630_nextReqToProcess$$1$$.options.concat($peekedRequest$$inline_629_token$$13$$.options);
        $dispatchedRequest$$inline_630_nextReqToProcess$$1$$[$AdfRestDataService$$.$PRIORITIZE$] = $dispatchedRequest$$inline_630_nextReqToProcess$$1$$[$AdfRestDataService$$.$PRIORITIZE$] || $peekedRequest$$inline_629_token$$13$$[$AdfRestDataService$$.$PRIORITIZE$];
        $peekedRequest$$inline_629_token$$13$$ = this.$_requestQueueManager$.first();
      }
      $peekedRequest$$inline_629_token$$13$$ = this.$_connectionTokens$.pop();
      if (void 0 === $peekedRequest$$inline_629_token$$13$$) {
        break;
      }
      $dispatchedRequest$$inline_630_nextReqToProcess$$1$$ = this.$_requestQueueManager$.shift();
      if (!$dispatchedRequest$$inline_630_nextReqToProcess$$1$$) {
        this.$_connectionTokens$.push($peekedRequest$$inline_629_token$$13$$);
        break;
      }
      this.$_progressRequests$.set($dispatchedRequest$$inline_630_nextReqToProcess$$1$$.$actionURL$, $dispatchedRequest$$inline_630_nextReqToProcess$$1$$);
      $JSCompiler_StaticMethods__dispatch$$(this, $dispatchedRequest$$inline_630_nextReqToProcess$$1$$, $peekedRequest$$inline_629_token$$13$$);
    } while (1);
  }
};
