/*
@param int $requestNumber maximum number of allowed requests
@param int $timeInterval time interval in seconds
422556
public function createCollector(
        $type,
        $namespace,
        $requestNumber,
        $timeInterval,
        $configuratorCallable = null
    ) {
        $className = $this->getCollectorClassName($type);

        $collector = new $className(
            $this->getKey() . ':' . $namespace,
            $requestNumber,
            $timeInterval
        );

        if (!($collector instanceof CollectorInterface)) {
            throw new \Exception('Collector must inherit CollectorInterface');
        }

        // configure
        if(is_callable($configuratorCallable)) {
            call_user_func($configuratorCallable, $collector, $this);
        }

        return $collector;

    }
134229
protected function emitUrlEvents($requestId, $url, UserEvent $event, EventQueue $queue)
    {
        $host = Url::extractHost($url);

        $eventName = 'url.host.' . $host;
        if (count($this->emitter->listeners($eventName)) > 0) {
            $this->logDebug('[' . $requestId . ']Emitting: ' . $eventName);
            $this->emitter->emit($eventName, [$url, $event, $queue]);
            return false;
        } else {
            return true;
        }
    }
502754
public function fromWidgetHtml($name, $defaultTimeWindow = 3600)
    {
        $post = $this->request->request;

        $s = $post->get($name . '_maxRequests');
        $maxRequests = (is_scalar($s) && is_numeric($s)) ? (int) $s : null;
        if ($maxRequests !== null && $maxRequests <= 0) {
            throw new UserMessageException(t('Please specify a positive integer for the maximum number of requests (or leave it empty)'));
        }
        try {
            $timeWindow = $this->joinTimeWindow($post->get($name . '_timeWindow_value'), $post->get($name . '_timeWindow_unit'), true);
        } catch (UserMessageException $x) {
            if ($maxRequests === null) {
                $timeWindow = $defaultTimeWindow;
            } else {
                throw $x;
            }
        }

        return [$maxRequests, $timeWindow];
    }
724817
private function dispatchRequest(int $requestId): int
    {
        $request = new Request(
            $this->requests[$requestId]['params'],
            $this->requests[$requestId]['stdin']
        );

        try {
            $response = $this->kernel->handleRequest($request);
        } finally {
            $request->cleanUploadedFiles();
        }

        if ($response instanceof ResponseInterface) {
            $this->sendResponse($requestId, $response);
        } elseif ($response instanceof HttpFoundationResponse) {
            $this->sendHttpFoundationResponse($requestId, $response);
        } else {
            throw new \LogicException('Kernel must return a PSR-7 or HttpFoundation response message');
        }

        $this->endRequest($requestId);

        // This method exists on PSR-7 and Symfony responses
        return $response->getStatusCode();
    }
1128626
public void buildForMissingInterval(@Nullable final LocalDate startDate, @Nullable final LocalDate endDate, @Nullable final UUID targetInvoiceId, final Collection<Item> output, final boolean addRepair) {
        final Item item = createNewItem(startDate, endDate, targetInvoiceId, addRepair);
        if (item != null) {
            output.add(item);
        }
    }
1228901
public void close(int requestNumber)
   {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "close", requestNumber);

      if (subConsumer != null)
      {
         subConsumer.close(requestNumber);
      }
      else
      {
         super.close(requestNumber);
      }

      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "close");
   }
134822
public function canRequest(RequestInterface $request, array $options = []) : bool
    {
        $groupCanRequest = true;
        $this->_requestLimiters->rewind();
        while ($this->_requestLimiters->valid())
        {
            /** @var RequestLimiter $requestLimiter */
            $requestLimiter = $this->_requestLimiters->current();

            $canRequest = $requestLimiter->canRequest($request, $options);
            if ($groupCanRequest && !$canRequest)
            {
                $groupCanRequest = false;
                $this->_retryAfter = $requestLimiter->getRemainingSeconds();
            }

            $this->_requestLimiters->next();
        }

        return $groupCanRequest;
    }
486189
private function renderRequirement(
        $intervalVariable,
        $callbackVariable,
        $requirementVariable,
        $nextStatement = null
    ) {
        $formatter = $this->getFormatter();
        $codes = [$formatter->renderCall($callbackVariable, [], true)];

        if (empty($nextStatement)) {
            array_unshift($codes, $formatter->renderCall('clearInterval', [$intervalVariable], true));
        }

        return $formatter->renderStatement(
            'if',
            $formatter->renderLines($codes, true, false),
            $formatter->renderCall($requirementVariable),
            $nextStatement,
            false
        );
    }
414061
public function addIterationsIntervalCallback($iterationsInterval, callable $onIterationsInterval)
    {
        if (!is_int($iterationsInterval) || ($iterationsInterval <= 0)) {
            throw new \InvalidArgumentException('Iteration interval must be a positive integer');
        }

        $this->iterationsIntervalCallbacks[] = ['interval' => $iterationsInterval, 'callable' => $onIterationsInterval,];
    }
746052
protected function cacheResponse(RequestInterface $request, Response $response, $ttl = null)
    {
        if (!$this->isSupportedMethod($request)) {
            return;
        }

        $cacheTtl = $ttl ?: $this->getCachettl($response);

        // do we have a valid ttl to set the cache ?
        if ($cacheTtl <= 0) {
            return;
        }

        if (($statusCode = $response->getStatusCode()) >= 500 && !$this->cacheServerErrors) {
            return;
        }

        if (($statusCode < 500 && $statusCode >= 400) && !$this->cacheClientErrors) {
            return;
        }

        // copy response in array to  store
        $cached = new \SplFixedArray(5);
        $cached[0] = $statusCode;
        $cached[1] = $response->getHeaders();
        $cached[2] = $response->getBody()->__toString();
        $cached[3] = $response->getProtocolVersion();
        $cached[4] = $response->getReasonPhrase();

        return $this->cache->set(
            self::getKey($request),
            serialize($cached),
            $cacheTtl
        );
    }
184337
public function createRequest($requestId, $url, UserEvent $event, EventQueue $queue)
    {
        $start = microtime(true);
        return new Request([
            'url' => $url,
            'responseCallback' => function ($headers, $code) use ($requestId, $start) {
                $end = microtime(true);
                $this->logDebug('[' . $requestId . ']Reponse (after ' . ($end - $start) . 's): ' . $code);
            },
            'resolveCallback' =>
                function (Response $response) use ($requestId, $url, $event, $queue, $start) {
                    $data = $response->getBody()->getContents();
                    $headers = $response->getHeaders();
                    array_walk($headers, function (&$value, $key) use ($response) {
                        $value = $response->getHeader($key);
                    });
                    $code = $response->getStatusCode();
                    $end = microtime(true);
                    $message = '[';
                    $message .= $requestId;
                    $message .= ']Download complete (after ';
                    $message .= ($end - $start);
                    $message .= 's): ';
                    $message .= strlen($data);
                    $message .= ' in length length';
                    $this->logDebug($message);
                    $this->emitShorteningEvents($requestId, $url)->then(
                        function ($shortUrl) use ($url, $data, $headers, $code, $end, $start, $event, $queue) {
                            $this->sendMessage(
                                new Url($url, $data, $headers, $code, $end - $start, $shortUrl),
                                $event,
                                $queue
                            );
                        },
                        function () use ($url, $data, $headers, $code, $end, $start, $event, $queue) {
                            $this->sendMessage(new Url($url, $data, $headers, $code, $end - $start), $event, $queue);
                        }
                    );
                },
        ]);
    }
54253
public function withInterval($timeInterval, $unit)
    {
        DateBuilder::validateIntervalUnit($unit);
        $this->validateInterval($timeInterval);

        $this->interval = $timeInterval;
        $this->intervalUnit = $unit;

        return $this;
    }
325643
public CircuitBreakerBuilder trialRequestInterval(Duration trialRequestInterval) {
        requireNonNull(trialRequestInterval, "trialRequestInterval");
        if (trialRequestInterval.isNegative() || trialRequestInterval.isZero()) {
            throw new IllegalArgumentException(
                    "trialRequestInterval: " + trialRequestInterval + " (expected: > 0)");
        }
        this.trialRequestInterval = trialRequestInterval;
        return this;
    }
483530
public static function setLogFlushTimeLimit($seconds) {
    if (!is_int($seconds)) {
      throw new \InvalidArgumentException(
          'Seconds must be an integer but was ' . self::typeOrClass($seconds));
    }
    self::$flush_time_limit = $seconds;
  }
1268814
public void addTimeInterval(T interval){
		timeIntervals.add(interval);
		minBorders.setStart(Math.max(minBorders.getStart(), interval.getStart()));
		minBorders.setEnd(Math.min(minBorders.getEnd(), interval.getEnd()));
		if(maxBorders == null){
			maxBorders = interval.clone();
		} else {
			maxBorders.setStart(Math.min(maxBorders.getStart(), interval.getStart()));
			maxBorders.setEnd(Math.max(maxBorders.getEnd(), interval.getEnd()));
		}
	}
1107912
public function onKernelRequest(RequestEvent $event): void
    {
        if (!$this->check($event)) {
            return;
        }

        $disabled = $event->getRequest()->headers->get(PhpsedCache::CACHE_HEADER);
        if (null !== $disabled) {
            $headers = array_map('trim', explode(',', $disabled));
            if (in_array(PhpsedCache::DISABLE_CACHE, $headers, true) && $annotation = $this->getAnnotation($event)) {
                $annotation->setData($this->getAttributes($event));
                $key = $annotation->getKey($event->getRequest()->get(self::ROUTE));
                $this->client->deleteItem($key);
            }
        }
    }
850370
public function onClientRequest(RequestEvent $event)
    {
        $errors = $this->validator->validate($event->getRequest());

        if (count($errors)) {
            throw new RequestException((string) $errors);
        }
    }