com.atlassian.scheduler.config
Class Schedule

java.lang.Object
  extended by com.atlassian.scheduler.config.Schedule

@Immutable
@PublicApi
public final class Schedule
extends Object

Represents a schedule used to run a job at particular times. Instances of this class are not created directly. Use one of the factory methods — such as forInterval(long, Date) or forCronExpression(String,TimeZone) — to construct them. To recover the information, use getType() to identify the type of schedule information and call the appropriate getter (getIntervalScheduleInfo() for Schedule.Type.INTERVAL; getCronScheduleInfo() for Schedule.Type.CRON_EXPRESSION).


Nested Class Summary
static class Schedule.Type
           
 
Method Summary
 boolean equals(Object o)
           
static Schedule forCronExpression(String cronExpression)
          Creates a new schedule for the given cron expression.
static Schedule forCronExpression(String cronExpression, TimeZone timeZone)
          Creates a new schedule for the given cron expression.
static Schedule forInterval(long intervalInMillis, Date firstRunTime)
          Creates a new schedule that will run periodically with the given interval.
 CronScheduleInfo getCronScheduleInfo()
          Returns a representation of the cron settings that were used to create this schedule.
 IntervalScheduleInfo getIntervalScheduleInfo()
          Returns a representation of the simple settings that were used to create this schedule.
 Schedule.Type getType()
          Returns the Schedule.Type of this schedule.
 int hashCode()
           
static Schedule runOnce(Date runTime)
          Creates a new schedule that will run once at the specified time.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

forCronExpression

public static Schedule forCronExpression(@Nonnull
                                         String cronExpression)
Creates a new schedule for the given cron expression. The cron expression is not verified immediately, but invalid expressions will cause SchedulerService.scheduleJobWithGeneratedId(JobConfig) to fail. The system's default time zone is assumed.

Parameters:
cronExpression - the cron expression to use for the schedule
Returns:
a schedule for running jobs when the given cron expression is satisfied

forCronExpression

public static Schedule forCronExpression(@Nonnull
                                         String cronExpression,
                                         @Nullable
                                         TimeZone timeZone)
Creates a new schedule for the given cron expression. The cron expression is not verified immediately, but invalid expressions will cause SchedulerService.scheduleJobWithGeneratedId(JobConfig) to fail.

Parameters:
cronExpression - the cron expression to use for the schedule
timeZone - the time zone within which to apply the rules of the cron expression; may be null to use a default time zone that is appropriate for the application
Returns:
a schedule for running jobs when the given cron expression is satisfied

runOnce

public static Schedule runOnce(@Nullable
                               Date runTime)
Creates a new schedule that will run once at the specified time. Jobs that are scheduled to run once are not guaranteed to remain in the system after they are attempted, regardless of the RunOutcome. Jobs scheduled as runOnce will be purged automatically after they have run; that is, at some point after they have run (possibly immediately), SchedulerService.getJobDetails(JobId) will no longer return the job's information.

Parameters:
runTime - when the job should run; may be null to indicate that the job should run as soon as possible
Returns:
a schedule for running once at the given time

forInterval

public static Schedule forInterval(long intervalInMillis,
                                   @Nullable
                                   Date firstRunTime)
Creates a new schedule that will run periodically with the given interval.

WARNING: Implementations are not required to honour the time interval at millisecond precision. The actual resolution that is permitted is implementation-defined. Implementations should round the requested interval up and persist the rounded value so that the interval reported by later calls to getIntervalScheduleInfo() will be consistent with the behaviour that the scheduler actually provides.

Parameters:
intervalInMillis - the minimum time interval (in milliseconds) between runs. If the value 0L is specified, then the job will not repeat (this is equivalent to using runOnce(firstRunTime)). Negative values are not permitted.
firstRunTime - when the job should run for the first time; may be null to indicate that the job should run as soon as possible
Returns:
a schedule for running once at the given time

getIntervalScheduleInfo

public IntervalScheduleInfo getIntervalScheduleInfo()
Returns a representation of the simple settings that were used to create this schedule.

Returns:
the interval schedule, or null if that is not this schedule's type.

getCronScheduleInfo

public CronScheduleInfo getCronScheduleInfo()
Returns a representation of the cron settings that were used to create this schedule.

Returns:
the cron schedule, or null if that is not this schedule's type.

getType

public Schedule.Type getType()
Returns the Schedule.Type of this schedule.

Returns:
the Schedule.Type of this schedule.

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2014 Atlassian. All Rights Reserved.