/**
  * Additional factory method that creates a new instance from
  * the passed schedule expression.
  *
  * @param \AppserverIo\Psr\EnterpriseBeans\ScheduleExpression $scheduleExpression The schedule expression with the data to create the instance with
  *
  * @return \AppserverIo\Appserver\PersistenceContainer\CalendarBasedTimeout The instance
  */
 public static function factoryFromScheduleExpression(ScheduleExpression $scheduleExpression)
 {
     // prepare the CRON expression
     $cronExpression = sprintf('%s %s %s %s %s %s %s', $scheduleExpression->getSecond(), $scheduleExpression->getMinute(), $scheduleExpression->getHour(), $scheduleExpression->getDayOfMonth(), $scheduleExpression->getMonth(), $scheduleExpression->getDayOfWeek(), $scheduleExpression->getYear());
     // return the point in time at which the next timer expiration is scheduled to occur
     return new CalendarBasedTimeout($cronExpression, $scheduleExpression, new FieldFactory());
 }
 /**
  * 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);
         }
     }
 }
 /**
  * Test the getMonth() method.
  *
  * @return void
  */
 public function testGetMonth()
 {
     $this->scheduleExpression->month($month = 10);
     $this->assertEquals($month, $this->scheduleExpression->getMonth());
 }
Exemple #4
0
 /**
  * Creates a new schedule expression instance from this annotations data.
  *
  * @return \AppserverIo\Psr\EnterpriseBeans\ScheduleExpression The expression initialzed with the data from this annotation
  */
 public function toScheduleExpression()
 {
     // create a new expression instance
     $expression = new ScheduleExpression();
     // copy the data from the annotation
     $expression->hour($this->getHour());
     $expression->minute($this->getMinute());
     $expression->month($this->getMonth());
     $expression->second($this->getSecond());
     $expression->start($this->getStart());
     $expression->end($this->getEnd());
     $expression->timezone($this->getTimezone());
     $expression->year($this->getYear());
     $expression->dayOfMonth($this->getDayOfMonth());
     $expression->dayOfWeek($this->getDayOfWeek());
     // return the expression
     return $expression;
 }