/** * Creates and schedules a timer task for the next timeout of the passed timer. * * @param \AppserverIo\Psr\EnterpriseBeans\TimerInterface $timer The timer we want to schedule a task for * @param boolean $newTimer TRUE if this is a new timer being scheduled, and not a re-schedule due to a timeout * * @return void */ public function scheduleTimeout(TimerInterface $timer, $newTimer) { // check if this timer has been cancelled by another thread if ($newTimer === false && $this->getTimers()->has($timer->getId()) === false) { return; // if yes, we just return } // if next expiration is NULL, no more tasks will be scheduled for this timer if ($timer->getNextExpiration() == null) { return; // we just return } // create the timer task and schedule it $this->getTimerServiceExecutor()->schedule($timer); }
/** * Calculates and returns the next timeout for the passed timer. * * @param \AppserverIo\Psr\EnterpriseBeans\TimerInterface $timer The timer we want to calculate the next timeout for * * @return \DateTime|null The next expiration timeout */ protected function calculateNextTimeout(TimerInterface $timer) { // try to load the interval $intervalDuration = $timer->getIntervalDuration(); // check if we've a interval if ($intervalDuration > 0) { // load the next expiration date $nextExpiration = $timer->getNextExpiration(); // compute and return the next expiration date return $nextExpiration->add(new \DateInterval(sprintf('PT%sS', $intervalDuration / 1000000))); } // return nothing return null; }
/** * Calculates and returns the next timeout for the passed timer. * * @param \AppserverIo\Psr\EnterpriseBeans\TimerInterface $timer The timer we want to calculate the next timeout for * * @return \DateTime|null The next expiration timeout */ protected function calculateNextTimeout(TimerInterface $timer) { return $timer->getCalendarTimeout()->getNextRunDate(); }