Beispiel #1
0
 public function add(TimerInterface $timer)
 {
     $interval = $timer->getInterval();
     $scheduledAt = $interval + $this->getTime();
     $this->timers->attach($timer, $scheduledAt);
     $this->scheduler->insert($timer, -$scheduledAt);
 }
Beispiel #2
0
 /**
  * Generate ID
  *
  * @return string A 64 bit integer as a string of numbers (so we can deal
  *      with this on 32 bit platforms) 
  */
 public function generate()
 {
     $t = floor($this->timer->getUnixTimestamp() - $this->epoch);
     if ($t !== $this->lastTime) {
         if ($t < $this->lastTime) {
             throw new \UnexpectedValueException('Time moved backwards. We cannot generate IDs for ' . ($this->lastTime - $t) . ' milliseconds');
         } elseif ($t < 0) {
             throw new \UnexpectedValueException('Time is currently set before our epoch - unable ' . 'to generate IDs for ' . -$t . ' milliseconds');
         } elseif ($t > self::MAX_ADJUSTED_TIMESTAMP) {
             throw new \OverflowException('Timestamp overflow (past end of lifespan) - unable to generate any more IDs');
         }
         $this->sequence = 0;
         $this->lastTime = $t;
     } else {
         $this->sequence++;
         if ($this->sequence > 4095) {
             throw new \OverflowException('Sequence overflow (too many IDs generated) - unable to generate IDs for 1 milliseconds');
         }
     }
     if (PHP_INT_SIZE === 4) {
         return $this->mintId32($t, $this->machine, $this->sequence);
     } else {
         return $this->mintId64($t, $this->machine, $this->sequence);
     }
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function start(TimerInterface $timer)
 {
     if (!isset($this->timers[$timer])) {
         $interval = $timer->getInterval();
         $event = $this->loop->timer($interval, $timer->isPeriodic() ? $interval : 0, $this->callback, $timer);
         $this->timers[$timer] = $event;
     }
 }
 /**
  * @param TimerInterface $timer
  * @return $this
  * @throws \InvalidArgumentException
  */
 public function add(TimerInterface $timer)
 {
     $interval = $timer->getInterval();
     if ($interval < $this->getPrecision()) {
         throw new InvalidArgumentException('Timer events do not support sub-millisecond timeouts.');
     }
     $scheduledAt = $interval + $this->getTime();
     $this->timers->attach($timer, $scheduledAt);
     $this->scheduler->insert($timer, -$scheduledAt);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function start(TimerInterface $timer)
 {
     $flags = Event::TIMEOUT;
     if ($timer->isPeriodic()) {
         $flags |= Event::PERSIST;
     }
     $event = new Event($this->base, -1, $flags, $this->callback, $timer);
     $this->timers[$timer] = $event;
     $event->add($timer->getInterval());
 }
 /**
  * {@inheritdoc}
  */
 public function start(TimerInterface $timer)
 {
     if (!isset($this->timers[$timer])) {
         $handle = \uv_timer_init($this->loopHandle);
         $interval = $timer->getInterval() * self::MILLISEC_PER_SEC;
         \uv_timer_start($handle, $interval, $timer->isPeriodic() ? $interval : 0, $this->callback);
         $this->timers[$timer] = $handle;
         $this->handles[(int) $handle] = $timer;
     }
 }
Beispiel #7
0
 public function generate()
 {
     $milliseconds = (int) floor($this->timer->getMilliseconds() - $this->epochStart);
     $value = $milliseconds << 22 | $this->nodeIdentifier << 12 | $this->sequencer->getNext($milliseconds);
     return (string) $value;
 }