Access the scheduled executor service.

@return ScheduledEventService - null if not found
487101
public static ScheduledExecutorService getScheduledExecutorService() {
        CHFWBundle c = instance.get().get();
        if (null != c) {
            return c.scheduledExecutor;
        }
        return null;
    }
1041402
public static ScheduledExecutorService newScheduledExecutor(int corePoolSize) {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(corePoolSize);
        EXECUTORS.add(scheduledExecutorService);
        return scheduledExecutorService;
    }
5941
public function getSchedule() {
    // Use cached schedule if already processed.
    if ($this->schedule) {
      return $this->schedule;
    }

    $conf = $this->configFactory->get('openy_group_schedules.settings');
    $days_range = is_numeric($conf->get('days_range')) ? $conf->get('days_range') : 14;

    $filter_date = DrupalDateTime::createFromTimestamp($this->parameters['filter_timestamp'], $this->timezone);
    $current_date = DrupalDateTime::createFromTimestamp(REQUEST_TIME, $this->timezone)->format(GroupexRequestTrait::$dateFilterFormat);
    // Define end date of shown items as 2 weeks.
    $end_date = DrupalDateTime::createFromTimestamp(REQUEST_TIME + 86400 * $days_range, $this->timezone);

    // Prepare classes items.
    $items = [];

    foreach ($this->processedData as $item) {
      // If item date more than 1 week in future skip it.
      $item_date = DrupalDateTime::createFromTimestamp($item->timestamp, $this->timezone);
      if ($item_date > $end_date) {
        continue;
      }
      $class_url_options = $this->parameters;
      // $class_url_options['class'] = $item->class_id; //doesn't exist in API, needs to be added through processData().
      $class_url_options['filter_date'] = $current_date;
      $class_url_options['filter_length'] = 'week';
      $class_url_options['groupex_class'] = 'groupex_table_class_individual';
      $class_url_options['view_mode'] = 'class';
      unset($class_url_options['instructor']);

      $instructor_url_options = $this->parameters;
      $instructor_url_options['filter_date'] = $current_date;
      $instructor_url_options['filter_length'] = 'week';

      $instructor_url_options['instructor'] = $item->instructor;
      // Here we need to remove redundant HTML if exists.
      // Example: Melissa T.<br><span class="fa fa-refresh" aria-hidden="true"></span><span class="sub">Lucy T.</span>
      $pos = strpos($item->instructor, '<span class="sub">');
      if (FALSE !== $pos) {
        $original_instructor = substr_replace($item->instructor, '', 0, $pos);
        $original_instructor = str_replace('<span class="sub">', '', $original_instructor);
        $original_instructor = str_replace('</span>', '', $original_instructor);
        $instructor_url_options['instructor'] = $original_instructor;
      }

      $instructor_url_options['class'] = 'any';
      $instructor_url_options['groupex_class'] = 'groupex_table_instructor_individual';
      unset($instructor_url_options['view_mode']);

      $date_url_options = $this->parameters;
      $date_url_options['filter_date'] = date('m/d/y', strtotime($item->date));
      $date_url_options['filter_length'] = 'day';
      $date_url_options['class'] = 'any';
      $date_url_options['groupex_class'] = 'groupex_table_class';
      unset($date_url_options['instructor']);
      unset($date_url_options['view_mode']);

      $items[$item->id] = [
        '#theme' => isset($this->parameters['groupex_class']) ? $this->parameters['groupex_class'] : 'groupex_class',
        '#class' => [
          'id' => trim($item->id),
          'name' => trim($item->title),
          'group' => trim($item->category),
          'description' => $item->desc,
          'address_1' => $item->address_1,
          'address_2' => trim($item->location),
          'date' => $item->date,
          'studio' => $item->studio,
          'date_short' => date('F, d', strtotime($item->date)),
          'time' => $item->start,
          'duration' => sprintf('%d min', trim($item->length)),
          'instructor' => $item->instructor,
//          'class_id' => $item->class_id, //doesn't exist in API, needs to be added through processData().
          'class_link' => Url::fromRoute('openy_group_schedules.all_schedules_search_results', [], ['query' => $class_url_options]),
          'instructor_link' => Url::fromRoute('openy_group_schedules.all_schedules_search_results', [], ['query' => $instructor_url_options]),
          'date_link' => Url::fromRoute('openy_group_schedules.all_schedules_search_results', [], ['query' => $date_url_options]),
          'calendar' => $item->calendar,
        ],
      ];
    }

    // Pack classes into the schedule.
    $schedule = [];

    // There 3 types of schedules.
    // Day: show classes for single day.
    // Week: show classes for week grouped by day.
    // Location: show classes for 1 day grouped by location.
    $schedule['type'] = isset($this->parameters['filter_length']) ? $this->parameters['filter_length'] : 'day';
    if (!empty($this->parameters['location']) && count($this->parameters['location']) > 1) {
      $schedule['type'] = 'location';
    }
    if (!empty($this->parameters['class']) && is_numeric($this->parameters['class'])) {
      $schedule['type'] = 'week';
    }
    if (!empty($this->parameters['instructor'])) {
      $schedule['type'] = 'instructor';
    }
    switch ($schedule['type']) {
      case 'day':
        $schedule['classes'] = [];
        foreach ($items as $id => $class) {
          $schedule['classes'][] = $class;
          $schedule['title'] = trim($this->enrichedData[$id]->location);
        }
        // Pass 'View This Week’s PDF' href if some location selected.
        if (!empty($this->parameters['location'])) {
          $location_id = $this->parameters['location'];
          $category = $this->parameters['category'] == 'any' ? NULL : $this->parameters['category'];
          $schedule['pdf_href'] = $this->groupexHelper->getPdfLink($location_id, $this->parameters['filter_timestamp'], $category);
        }

        // If no location selected show date instead of title.
        if (empty($this->parameters['location'])) {
          $schedule['title'] = $filter_date->format(GroupexRequestTrait::$dateFullFormat);
        }
        break;

      case 'week':
        $schedule['days'] = [];
        foreach ($items as $id => $class) {
          $schedule['days'][$this->enrichedData[$id]->day]['classes'][] = $class;
          $schedule['days'][$this->enrichedData[$id]->day]['day_short'] = DrupalDateTime::createFromFormat(GroupexRequestTrait::$dateFullFormat, $this->enrichedData[$id]->day, $this->timezone)->format('l, F j');
          $schedule['days'][$this->enrichedData[$id]->day]['date_link'] = $class['#class']['date_link'];
        }
        // Pass 'View This Week’s PDF' href if some location selected.
        if (!empty($this->parameters['location'])) {
          $location = $this->parameters['location'];
          $category = $this->parameters['category'] == 'any' ? NULL : $this->parameters['category'];
          $schedule['pdf_href'] = $this->groupexHelper->getPdfLink($location, $this->parameters['filter_timestamp'], $category);
        }

        // If no location selected show date instead of title.
        if (empty($this->parameters['location'])) {
          $schedule['day'] = $filter_date->format(GroupexRequestTrait::$dateFullFormat);
        }
        break;

      case 'location':
        $schedule['locations'] = [];
        $location_id = NULL;
        $locations_ids = \Drupal::entityQuery('mapping')
          ->condition('type', 'location')
          ->execute();
        $locations = \Drupal::entityManager()->getStorage('mapping')->loadMultiple($locations_ids);
        foreach ($items as $id => $class) {
          $short_location_name = trim($this->enrichedData[$id]->location);
          foreach ($locations as $location) {
            if ($location->get('name')->value == $short_location_name) {
              $field_groupex_id = $location->field_groupex_id->getValue();
              $location_id = isset($field_groupex_id[0]['value']) ? $field_groupex_id[0]['value'] : FALSE;
            }
          }
          $category = $this->parameters['category'] == 'any' ? NULL : $this->parameters['category'];
          $pdf_href = $this->groupexHelper->getPdfLink($location_id, $this->parameters['filter_timestamp'], $category);
          $schedule['locations'][$short_location_name]['classes'][] = $class;
          $schedule['locations'][$short_location_name]['pdf_href'] = $pdf_href;
        }
        $schedule['filter_date'] = date(GroupexRequestTrait::$dateFullFormat, $this->parameters['filter_timestamp']);
        break;

      case 'instructor':
        // Filter classes by instructor.
        $schedule['days'] = [];

        foreach ($items as $id => $class) {
          if ($class['#class']['instructor'] == $this->parameters['instructor']) {
            $class_date = DrupalDateTime::createFromFormat(
              GroupexRequestTrait::$dateFullFormat,
              $this->enrichedData[$id]->day,
              $this->timezone
            );

            $schedule['days'][$this->enrichedData[$id]->day]['classes'][] = $class;
            $schedule['days'][$this->enrichedData[$id]->day]['day_short'] = $class_date->format('l, F j');

            // Adjust query options to fit class date.
            $date_url_options['filter_date'] = $class_date->format(GroupexRequestTrait::$dateFilterFormat);
            $date_url_options['filter_timestamp'] = $class_date->format('U');

            $url = Url::fromRoute('openy_group_schedules.all_schedules_search_results', [], ['query' => $date_url_options]);
            $schedule['days'][$this->enrichedData[$id]->day]['date_link'] = $url;
          }
        }

        $schedule['instructor_location'] = t('Schedule for <span class="name"><span class="icon icon-user"></span>@name</span>', [
          '@name' => reset($schedule['days'])['classes'][0]['#class']['instructor'],
        ]);

        // Pass 'View This Week’s PDF' href if some location selected.
        if (!empty($this->parameters['location'])) {
          $location = $this->parameters['location'];
          $category = $this->parameters['category'] == 'any' ? NULL : $this->parameters['category'];
          $schedule['pdf_href'] = $this->groupexHelper->getPdfLink($location, $this->parameters['filter_timestamp'], $category);
        }

        // If no location selected show date instead of title.
        if (empty($this->parameters['location'])) {
          $schedule['day'] = $filter_date->format(GroupexRequestTrait::$dateFullFormat);
        }
        break;
    }

    $this->schedule = $schedule;
    return $this->schedule;
  }
263669
public function runSchedule()
    {
        if ($this->getScheduler()->isEmpty()) {
            return;
        }

        if (!$this->getScheduler()->top()->isDue()) {
            // Nothing to do.
            return;
        }

        $schedule = $this->getScheduler()->extract();

        $this->getLogger()->debug('Running schedule '.$schedule->getName().' with expression: '.$schedule->getExpression().'.');
        $schedule->run();

        $this->getScheduler()->insert($schedule);
    }
125627
private ExecutorService getExecutorService(){
        if (executors == null) {
            try {
                executors = Executors.newCachedThreadPool();
            } catch (Exception e) {
                HMSAgentLog.e("create thread service error:" + e.getMessage());
            }
        }

        return executors;
    }
497672
public function getEventManager()
    {
        if (!$this->eventManager instanceof EventManagerInterface) {
            $this->setEventManager(new EventManager(array(__CLASS__, get_called_class())));
        }
        return $this->eventManager;
    }
671032
public ScheduledExecutorService getScheduledExecutorService() {
        ScheduledExecutorService sRef = scheduledExecutorService.get();
        if (sRef == null) {
            throw new IllegalStateException("ScheduledExecutorService service is unavailable");
        }
        return sRef;
    }
914437
public ScheduledFuture<?> schedule() {
        synchronized (this.triggerContextMonitor) {
            this.scheduledExecutionTime = this.trigger.nextExecutionTime(this.triggerContext);
            if (this.scheduledExecutionTime == null) {
                return null;
            }
            long initialDelay = this.scheduledExecutionTime.getTime() - System.currentTimeMillis();
            this.currentFuture = this.executor.schedule(this, initialDelay, TimeUnit.MILLISECONDS);
            return this;
        }
    }
69205
@Override
  public IScheduleBuilder <ICronTrigger> getScheduleBuilder ()
  {
    final CronScheduleBuilder cb = CronScheduleBuilder.cronSchedule (getCronExpression ()).inTimeZone (getTimeZone ());

    switch (getMisfireInstruction ())
    {
      case MISFIRE_INSTRUCTION_DO_NOTHING:
        cb.withMisfireHandlingInstructionDoNothing ();
        break;
      case MISFIRE_INSTRUCTION_FIRE_ONCE_NOW:
        cb.withMisfireHandlingInstructionFireAndProceed ();
        break;
    }

    return cb;
  }
335441
public function dequeuePlain()
    {
        $document = $this->collection
            ->find()
            ->sort(array(
                'priority' => -1,
                'datetime' => 1,
            ))
            ->findAndRemove();
        
        if (!$document) {
            return null;
        }
        
        return $document->get('payload');
    }
673031
public synchronized static ExecutorService getExecutorService() {
        if (executorService == null) {
            executorService = Executors.newCachedThreadPool();
            ((ThreadPoolExecutor) executorService).setMaximumPoolSize(executorPoolSize);
        }
        return executorService;
    }
1244258
public function index()
    {
        $schedule = Schedule::query();

        if ($sortBy = Binput::get('sort')) {
            $direction = Binput::has('order') && Binput::get('order') == 'desc';

            $schedule->sort($sortBy, $direction);
        }

        $schedule = $schedule->paginate(Binput::get('per_page', 20));

        return $this->paginator($schedule, Request::instance());
    }
542074
protected function runnableRetriever()
    {
        $runnable = $this->getRunnable();

        if ($runnable && is_callable($runnable)) {
            return $runnable;
        }

        return function ($server, $process) {
            $this->dispatchEvent('Run', $server, $process);
        };
    }
474935
public function getPersistenceEventQueue()
    {
        if (null === $this->persistenceEventQueue) {
            $this->persistenceEventQueue = new Persistence\PersistenceEventQueue(
                $this->getConfigurationRegistry(),
                $this->getEventDispatcher()
            );
        }

        return $this->persistenceEventQueue;
    }
534751
public function getEvents()
    {
        if (! $this->events) {
            $services = $this->getServices();
            $events   = $services->get('Events');
            $this->setEvents($events);
        }

        return $this->events;
    }
1324309
public function scheduler()
    {
        if (is_null($this->scheduler)) {
            $this->scheduler = app(Scheduler::class);
        }

        return $this->scheduler;
    }
721731
protected function getExecutionTime()
    {
        if ($this->executionTime === null) {
            $resource = $this->getActionExecution();

            if ($resource !== null) {
                /** @var \core_kernel_classes_Resource $resource */
                $time = (string) $resource->getOnePropertyValue(new \core_kernel_classes_Property(self::PROPERTY_EXECUTION_TIME));
                if (!empty($time)) {
                    $this->executionTime = new DateTime('@' . $time);
                }
            }
        }
        return $this->executionTime;
    }