Sign in to mpx, with a lock to prevent sign-in stampedes.

@param int $duration (optional) The number of seconds that the sign-in token should be valid for.

@return Token
169026
protected function signInWithLock(int $duration = null): Token
    {
        if ($this->store) {
            $factory = new Factory($this->store);
            $factory->setLogger($this->logger);
            $lock = $factory->createLock($this->user->getMpxUsername(), 10);

            // Blocking means this will throw an exception on failure.
            $lock->acquire(true);
        }

        try {
            // It's possible another thread has signed in for us, so check for a token first.
            $token = $this->tokenCachePool->getToken($this);
        } catch (TokenNotFoundException $e) {
            // We have the lock, and there's no token, so sign in.
            $token = $this->signIn($duration);
        }

        return $token;
    }
390465
public static function createFromDateString($duration): self
    {
        $duration = parent::createFromDateString($duration);
        if (false === $duration) {
            return $duration;
        }

        $new = new self('PT0S');
        foreach ($duration as $name => $value) {
            $new->$name = $value;
        }

        return $new;
    }
1132290
public function setToken($key, $value, $duration = 60)
    {
        $this->cache->put('reactor.tokens.' . $key, $value, $duration);
    }
731111
public function generateNoise($duration = 1.0, $percent = 100)
    {
        $numChannels = $this->getNumChannels();
        $numSamples  = $this->getSampleRate() * $duration;
        $minAmp      = $this->getMinAmplitude();
        $maxAmp      = $this->getMaxAmplitude();
        $bitDepth    = $this->getBitsPerSample();

        for ($s = 0; $s < $numSamples; ++$s) {
            if ($bitDepth == 32) {
                $val = rand(-$percent * 10000, $percent * 10000) / 1000000;
            } else {
                $val = rand($minAmp, $maxAmp);
                $val = (int)($val * $percent / 100);
            }

            $this->_samples .= str_repeat(self::packSample($val, $bitDepth), $numChannels);
        }

        $this->setDataSize();  // implicit setSize(), setActualSize(), setNumBlocks()

        return $this;
    }
1024205
public static function fromLengthAndDuration(Length $length, Duration $duration)
	{
		$meters = $length->convertTo(UnitLength::meters());
		$seconds = $duration->convertTo(UnitDuration::seconds());

		$speed = $meters->value() / $seconds->value();

		return new static($speed, UnitSpeed::metersPerSecond());
	}
911725
protected function validateMaxDuration($duration, Constraint $constraint)
    {
        if ($constraint->maxDuration) {
            if (!ctype_digit((string) $constraint->maxDuration)) {
                throw new ConstraintDefinitionException(
                    sprintf(
                        '"%s" is not a valid maximum duration',
                        $constraint->maxDuration
                    )
                );
            }

            if ($duration > $constraint->maxDuration) {
                $this->context->addViolation(
                    $constraint->maxDurationMessage,
                    array(
                        '{{ duration }}' => $duration,
                        '{{ max_duration }}' => $constraint->maxDuration
                    )
                );

                return true;
            }
        }
    }
1252484
public function addToken($token)
    {
        if (count($this->tokens) + 1 > self::MULTICAST_MAX_TOKENS) {
            throw new \RuntimeException(sprintf('Max token number reached. %s tokens max.', self::MULTICAST_MAX_TOKENS));
        }

        return parent::addToken($token);
    }
610887
public static function FromDuration( $duration )
	{
		if ( $duration instanceof DurationValue )
			$duration = $duration->getValue();

		$duration->y = 0;
		$duration->m = 0;
		$duration->days = 0;

		$dt = new \DateTimeImmutable();
		$diff = $dt->add( $duration )->diff( $dt );
		$diff->invert = $duration->invert;
		$diff->microseconds = $duration->microseconds;

		return new DayTimeDurationValue( $diff );
	}
1198950
public function createCustomToken($uid, array $claims = [], \DateTimeInterface $expiresAt = null): Token
    {
        if (count($claims)) {
            $this->builder->set('claims', $claims);
        }

        $this->builder->set('uid', (string) $uid);

        $now = time();
        $expiration = $expiresAt ? $expiresAt->getTimestamp() : $now + (60 * 60);

        $token = $this->builder
            ->setIssuedAt($now)
            ->setExpiration($expiration)
            ->sign($this->signer, $this->privateKey)
            ->getToken();

        $this->builder->unsign();

        return $token;
    }
33331
public function setTransmitTimeout($seconds = null)
    {
        if (is_integer($seconds)) {
            $this->_txtimeout = $seconds;
        } else {
            $this->_txtimeout = self::DEF_TX_RX_TIMEOUT;
        }
        return $this->_txtimeout;
    }
1176904
public function createNullSound($duration, $target)
    {
        if (empty($duration)) {
            $duration = 1;
        }

        $this->serviceLocator->setShared('playgroundcore_phpvideotoolkit', false);
       
        $this->serviceLocator->get('playgroundcore_phpvideotoolkit')
            ->addPreInputCommand('-y')
            ->addCommand('-filter_complex', 'aevalsrc=0:d='.$duration)
            ->setOutputPath($target)
            ->execute();

        return $target;
    }
288248
public function negated() : Duration
    {
        if ($this->isZero()) {
            return $this;
        }

        $seconds = -$this->seconds;
        $nanos = $this->nanos;

        if ($nanos !== 0) {
            $nanos = LocalTime::NANOS_PER_SECOND - $nanos;
            $seconds--;
        }

        return new Duration($seconds, $nanos);
    }
1051022
private static function keepSecondsWithinTimeout($seconds, $timedOut)
    {
        if (is_null($timedOut)) {
            return $seconds;
        }
        $remainingSeconds = max($timedOut - microtime(true), 0);
        return min($remainingSeconds, $seconds);
    }
567325
public static function durationToTime($duration)
    {
        $time = null;

        try {
            $interval = preg_match('/(\.[0-9]{1,6}S)$/', $duration)
                ? new DateIntervalMS($duration)
                : new DateInterval($duration);
            $time = self::intervalToTime($interval);
        } catch (Exception $e) {
            common_Logger::e($e->getMessage());
        }

        return $time;
    }
108073
public function dequeue($duration = 5)
    {
        $this->errorIfClosed();

        list($serialized, $receipt) = $this->driver->popMessage($this->name, $duration);

        if ($serialized) {
            $envelope = $this->serializer->unserialize($serialized);

            $this->receipts->attach($envelope, $receipt);

            return $envelope;
        }
    }
36040
public Duration add( Duration duration ) {
        return new Duration(this.durationInNanos + (duration == null ? 0l : duration.longValue()));
    }
914995
public function set($key, $value, $duration = null)
    {
        // TODO: Implement set() method.
        if ($this->connected) {
            return $this->conn->set($key, $value, null, $duration);
        }
    }