Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2014 Philip Helger (www.helger.com) philip[at]helger[dot]com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package com.helger.schedule.quartz;
 
 
Misc utility methods around Quartz schedulers

Author(s):
Philip Helger
 
 public final class QuartzSchedulerHelper
 {
   public static final boolean DEFAULT_START_AUTOMATICALLY = true;
   private static final SchedulerFactory s_aSchedulerFactory = new StdSchedulerFactory ();
 
   private QuartzSchedulerHelper ()
   {}

  

Returns:
The single org.quartz.Scheduler instance that is ensured to be started. Never null.
See also:
getScheduler(boolean)
 
   @Nonnull
   public static Scheduler getScheduler ()
   {
   }

  
Get the underlying Quartz scheduler

Parameters:
bStartAutomatically If true the returned scheduler is automatically started. If false the state is not changed.
Returns:
The underlying Quartz scheduler. Never null.
 
   @Nonnull
   public static Scheduler getScheduler (final boolean bStartAutomatically)
   {
     try
     {
       // Don't try to use a name - results in NPE
       final Scheduler aScheduler = .getScheduler ();
       if (bStartAutomatically && !aScheduler.isStarted ())
         aScheduler.start ();
       return aScheduler;
     }
     catch (final SchedulerException ex)
     {
       throw new IllegalStateException ("Failed to create and start scheduler!"ex);
     }
   }

  
Get the metadata of the scheduler. The state of the scheduler is not changed within this method.

Returns:
The metadata of the underlying scheduler.
 
   @Nonnull
   public static SchedulerMetaData getSchedulerMetaData ()
   {
     try
     {
       // Get the scheduler without starting it
       return .getScheduler ().getMetaData ();
     }
     catch (final SchedulerException ex)
     {
       throw new IllegalStateException ("Failed to get scheduler metadata"ex);
     }
   }

  

Returns:
The state of the scheduler. Never null.
  public static ESchedulerState getSchedulerState ()
  {
    try
    {
      // Get the scheduler without starting it
      final Scheduler aScheduler = .getScheduler ();
      if (aScheduler.isStarted ())
        return .;
      if (aScheduler.isInStandbyMode ())
        return .;
      if (aScheduler.isShutdown ())
        return .;
    }
    catch (final SchedulerException ex)
    {
      throw new IllegalStateException ("Error retrieving scheduler state!"ex);
    }
    throw new IllegalStateException ("Unknown scheduler state!");
  }
New to GrepCode? Check out our FAQ X