Get the underlying Quartz scheduler

@param bStartAutomatically
If <code>true</code> the returned scheduler is automatically
started. If <code>false</code> the state is not changed.
@return The underlying Quartz scheduler. Never <code>null</code>.
421754
@Nonnull
  public static IScheduler getScheduler (final boolean bStartAutomatically)
  {
    try
    {
      // Don't try to use a name - results in NPE
      final IScheduler aScheduler = s_aSchedulerFactory.getScheduler ();
      if (bStartAutomatically && !aScheduler.isStarted ())
        aScheduler.start ();
      return aScheduler;
    }
    catch (final SchedulerException ex)
    {
      throw new IllegalStateException ("Failed to create" +
                                       (bStartAutomatically ? " and start" : "") +
                                       " scheduler!",
                                       ex);
    }
  }
908426
@Nonnull
    private Timer getTimer() {
        return timerReference.updateAndGet(timer -> timer == null ? new Timer(LogConfigurationTask.class.getSimpleName(), true) : timer);
    }
577710
public long getStartTick()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "getStateTick");

    long startTick = getTickRange().startstamp;
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "getStartTick", new Long(startTick));
      
    return startTick;
  }
213108
public final String getStartFormattedShort() {
        Granularity startGran = this.interval.getStartGranularity();
        return formatStart(startGran != null ? startGran.getShortFormat()
                : null);
    }
276473
public boolean startInactivityTimer() {
        final boolean traceOn = TraceComponent.isAnyTracingEnabled();

        if (traceOn && tc.isEntryEnabled())
            Tr.entry(tc, "startInactivityTimer");

        if (_inactivityTimeout > 0
            && _status.getState() == TransactionState.STATE_ACTIVE
            && !_inactivityTimerActive) {
            EmbeddableTimeoutManager.setTimeout(this,
                                                EmbeddableTimeoutManager.INACTIVITY_TIMEOUT, _inactivityTimeout);
            _inactivityTimerActive = true;

            _mostRecentThread.pop();
        }

        if (traceOn && tc.isEntryEnabled())
            Tr.exit(tc, "startInactivityTimer", _inactivityTimerActive);
        return _inactivityTimerActive;
    }
892929
@Override
    public ScheduledExecutorService getScheduler() {
        ScheduledExecutorService sRef = executorService.get();
        if (sRef == null) {
            throw new IllegalStateException("ScheduledExecutorService service is unavailable");
        }
        return sRef;
    }
193877
public Boolean isSchedulerPaused() {
        try {
            return this.scheduler.isInStandbyMode();
        } catch (SchedulerException e) {
            logger.error("error retrieveing scheduler condition", e);
        }
        return null;
    }
555772
protected ScheduledFuture<?> startTimer() {
        return getExecutorService().scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                endOfPeriod();
            }
        }, getPeriod(), getPeriod(), getUnit());
    }
392041
public Date getStartDate()
   {
      Date startDate = null;

      for (Task task : m_tasks)
      {
         //
         // If a hidden "summary" task is present we ignore it
         //
         if (NumberHelper.getInt(task.getUniqueID()) == 0)
         {
            continue;
         }

         //
         // Select the actual or forecast start date. Note that the
         // behaviour is different for milestones. The milestone end date
         // is always correct, the milestone start date may be different
         // to reflect a missed deadline.
         //
         Date taskStartDate;
         if (task.getMilestone() == true)
         {
            taskStartDate = task.getActualFinish();
            if (taskStartDate == null)
            {
               taskStartDate = task.getFinish();
            }
         }
         else
         {
            taskStartDate = task.getActualStart();
            if (taskStartDate == null)
            {
               taskStartDate = task.getStart();
            }
         }

         if (taskStartDate != null)
         {
            if (startDate == null)
            {
               startDate = taskStartDate;
            }
            else
            {
               if (taskStartDate.getTime() < startDate.getTime())
               {
                  startDate = taskStartDate;
               }
            }
         }
      }

      return (startDate);
   }
1149491
public static ArchTaskExecutor getInstance() {
        if (sInstance != null) {
            return sInstance;
        }
        synchronized (ArchTaskExecutor.class) {
            if (sInstance == null) {
                sInstance = new ArchTaskExecutor();
            }
        }
        return sInstance;
    }
928738
public Calendar getStart() {
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(start);
		return cal;
	}
758998
boolean schedule(Runnable task,
                   ClassLoader loader,
                   long timeout)
  {
    return schedule(new RunnableItem(task, loader, timeout));
  }
994590
@Bean
    @ConditionalOnMissingBean(name = "quartzDataSource")
    @ConditionalOnProperty(name = {"jbpm.quartz.enabled", "jbpm.quartz.db"}, havingValue="true")
    public DataSource quartzDataSource(DataSource dataSource) {
        return dataSource;
    }
963510
public boolean runScheduler() {
    IScheduler scheduler = null;

    String statemgrClass = Context.stateManagerClass(config);
    IStateManager statemgr;

    try {
      // create an instance of state manager
      statemgr = ReflectionUtils.newInstance(statemgrClass);
    } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
      LOG.log(Level.SEVERE, "Failed to instantiate instances using config: " + config, e);
      return false;
    }

    SchedulerServer server = null;
    boolean isSuccessful = false;

    // Put it in a try block so that we can always clean resources
    try {
      // initialize the state manager
      statemgr.initialize(config);

      // TODO(mfu): timeout should read from config
      SchedulerStateManagerAdaptor adaptor = new SchedulerStateManagerAdaptor(statemgr, 5000);

      // get a packed plan and schedule it
      PackingPlans.PackingPlan serializedPackingPlan = adaptor.getPackingPlan(topology.getName());
      if (serializedPackingPlan == null) {
        LOG.log(Level.SEVERE, "Failed to fetch PackingPlan for topology:{0} from the state manager",
            topology.getName());
        return false;
      }
      LOG.log(Level.INFO, "Packing plan fetched from state: {0}", serializedPackingPlan);
      PackingPlan packedPlan = new PackingPlanProtoDeserializer().fromProto(serializedPackingPlan);

      // build the runtime config
      LauncherUtils launcherUtils = LauncherUtils.getInstance();
      Config runtime = Config.newBuilder()
          .putAll(launcherUtils.createPrimaryRuntime(topology))
          .putAll(launcherUtils.createAdaptorRuntime(adaptor))
          .put(Key.SCHEDULER_SHUTDOWN, getShutdown())
          .put(Key.SCHEDULER_PROPERTIES, properties)
          .build();

      Config ytruntime = launcherUtils.createConfigWithPackingDetails(runtime, packedPlan);

      // invoke scheduler
      scheduler = launcherUtils.getSchedulerInstance(config, ytruntime);
      if (scheduler == null) {
        return false;
      }

      isSuccessful = scheduler.onSchedule(packedPlan);
      if (!isSuccessful) {
        LOG.severe("Failed to schedule topology");
        return false;
      }

      // Failures in server initialization throw exceptions
      // get the scheduler server endpoint for receiving requests
      server = getServer(ytruntime, scheduler, schedulerServerPort);
      // start the server to manage runtime requests
      server.start();

      // write the scheduler location to state manager
      // Make sure it happens after IScheduler.onScheduler
      isSuccessful = SchedulerUtils.setSchedulerLocation(
          runtime, String.format("%s:%d", server.getHost(), server.getPort()), scheduler);

      if (isSuccessful) {
        // wait until kill request or some interrupt occurs if the scheduler starts successfully
        LOG.info("Waiting for termination... ");
        Runtime.schedulerShutdown(ytruntime).await();
      }
    } catch (IOException e) {
      LOG.log(Level.SEVERE, "Failed to start server", e);
      return false;
    } finally {
      // Clean the resources
      if (server != null) {
        server.stop();
      }

      // 4. Close the resources
      SysUtils.closeIgnoringExceptions(scheduler);
      SysUtils.closeIgnoringExceptions(statemgr);
    }

    return isSuccessful;
  }
996384
public boolean pauseQuartzScheduler() {
        try {
            this.scheduler.standby();
            return true;
        } catch (SchedulerException e) {
            logger.error("error pausing quartz scheduler", e);
        }
        return false;
    }
806962
@Override
  public IScheduleBuilder <ISimpleTrigger> getScheduleBuilder ()
  {
    final SimpleScheduleBuilder sb = SimpleScheduleBuilder.simpleSchedule ()
                                                          .withIntervalInMilliseconds (getRepeatInterval ())
                                                          .withRepeatCount (getRepeatCount ());

    switch (getMisfireInstruction ())
    {
      case MISFIRE_INSTRUCTION_FIRE_NOW:
        sb.withMisfireHandlingInstructionFireNow ();
        break;
      case MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT:
        sb.withMisfireHandlingInstructionNextWithExistingCount ();
        break;
      case MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT:
        sb.withMisfireHandlingInstructionNextWithRemainingCount ();
        break;
      case MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT:
        sb.withMisfireHandlingInstructionNowWithExistingCount ();
        break;
      case MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT:
        sb.withMisfireHandlingInstructionNowWithRemainingCount ();
        break;
    }

    return sb;
  }
654027
public Action0 getStartAction() {
    return new Action0() {
      @Override
      public void call() {
        if (startTime == null) {
          startTime = new Date().getTime();
        }
      }
    };
  }