public function getActiveEndpoint()
    {
        // try to get endpoint with status active
        $active = $this->getEndpoints()->filter(function (Endpoint $endpoint) {
            return $endpoint->isActive();
        });

        // when empty, try other endpoints
        if ($active->isEmpty() === true) {
            $active = $this->getEndpoints()->filter(function (Endpoint $endpoint) {
                return $this->canBeActivated($endpoint);
            });
        }

        if ($active->isEmpty() === true) {
            throw new NoServerAvailableException('No active server available');
        }

        /** @var Endpoint $endpoint */
        $endpoint = $active->first();
        $endpoint->setStatus(Endpoint::STATUS_ACTIVE);

        return $endpoint;
    }