/** * Initializes the timer with the necessary data. * * @param \AppserverIo\Appserver\PersistenceContainer\CalendarTimerBuilder $builder The builder with the data to create the timer from * @param \AppserverIo\Psr\EnterpriseBeans\TimerServiceInterface $timerService The timer service instance */ public function __construct(CalendarTimerBuilder $builder, TimerServiceInterface $timerService) { // call parent constructor parent::__construct($builder, $timerService); // load the auto timer flag $this->autoTimer = $builder->isAutoTimer(); // check if we've an auto timer if ($this->autoTimer) { // check if the timeout method is available if ($builder->getTimeoutMethod() == null) { // TODO: Throw an exception here, because we NEED a timeout method } // if yes, set it $this->timeoutMethod = $builder->getTimeoutMethod(); } else { // we don't expect an timeout method here if ($builder->getTimeoutMethod() != null) { // TODO: Throw an exception here, because we DON'T expect a timeout method } // reset the timeout method $this->timeoutMethod = null; } // create the schedule for this timer $scheduledExpression = new ScheduleExpression(); $scheduledExpression->second($builder->getScheduleExprSecond()); $scheduledExpression->minute($builder->getScheduleExprMinute()); $scheduledExpression->hour($builder->getScheduleExprHour()); $scheduledExpression->dayOfWeek($builder->getScheduleExprDayOfWeek()); $scheduledExpression->dayOfMonth($builder->getScheduleExprDayOfMonth()); $scheduledExpression->month($builder->getScheduleExprMonth()); $scheduledExpression->year($builder->getScheduleExprYear()); $scheduledExpression->start($builder->getScheduleExprStartDate()); $scheduledExpression->end($builder->getScheduleExprEndDate()); $scheduledExpression->timezone($builder->getScheduleExprTimezone()); // create the calender timeout from the schedule $this->calendarTimeout = CalendarBasedTimeout::factoryFromScheduleExpression($scheduledExpression); // if the timer has a next date and is new if ($builder->getNextDate() == null && $builder->isNewTimer()) { // compute the next timeout (from "now") $nextTimeout = $this->calendarTimeout->getNextRunDate(); if ($nextTimeout != null) { $this->nextExpiration = $nextTimeout->format($scheduledExpression::DATE_FORMAT); } } }
/** * This is invoked on every iteration of the daemons while() loop. * * @param integer $timeout The timeout before the daemon wakes up * * @return void */ public function iterate($timeout) { // call parent method and sleep for the default timeout parent::iterate($timeout); // create the requested timer instance $this->synchronized(function ($self) { // create the timer, only if we're NOT dispatched if ($self->dispatched === false) { $self->timer = Timer::builder()->setNewTimer(true)->setId(Uuid::uuid4()->__toString())->setInitialDate($self->initialExpiration)->setRepeatInterval($self->intervalDuration)->setInfo($self->info)->setPersistent($self->persistent)->setTimerState(TimerState::CREATED)->setTimedObjectId($self->timerService->getTimedObjectInvoker()->getTimedObjectId())->build($self->timerService); // we're dispatched now $self->dispatched = true; } }, $this); // profile the size of the sessions if ($this->profileLogger) { $this->profileLogger->debug(sprintf('Size of session pool is: %d', sizeof($this->sessionPool))); } }