View Javadoc

1   package com.atlassian.scheduler.core;
2   
3   import com.atlassian.scheduler.JobRunner;
4   import com.atlassian.scheduler.SchedulerService;
5   import com.atlassian.scheduler.SchedulerServiceException;
6   import com.atlassian.scheduler.config.JobConfig;
7   import com.atlassian.scheduler.config.JobId;
8   import com.atlassian.scheduler.config.JobRunnerKey;
9   import com.atlassian.scheduler.config.Schedule;
10  import com.atlassian.scheduler.status.JobDetails;
11  
12  import javax.annotation.CheckForNull;
13  import javax.annotation.Nonnull;
14  import javax.annotation.Nullable;
15  import java.util.Date;
16  import java.util.List;
17  import java.util.Set;
18  
19  import static com.atlassian.util.concurrent.Assertions.notNull;
20  
21  /**
22   * A scheduler service that delegates all requests to another scheduler service.
23   * The intended purpose is to allow applications to instantiate one of the
24   * {@link AbstractSchedulerService} implementations as a {@link LifecycleAwareSchedulerService}
25   * visible only to the application and register this restricted implementation as
26   * the {@link SchedulerService} that is available to add-ons.
27   *
28   * @since v1.0
29   */
30  @SuppressWarnings("unused")
31  public class DelegatingSchedulerService implements SchedulerService {
32      private final SchedulerService delegate;
33  
34      public DelegatingSchedulerService(SchedulerService delegate) {
35          this.delegate = notNull("delegate", delegate);
36      }
37  
38      @Override
39      public void registerJobRunner(JobRunnerKey jobRunnerKey, JobRunner jobRunner) {
40          delegate.registerJobRunner(jobRunnerKey, jobRunner);
41      }
42  
43      @Override
44      public void unregisterJobRunner(JobRunnerKey jobRunnerKey) {
45          delegate.unregisterJobRunner(jobRunnerKey);
46      }
47  
48      @Override
49      @Nonnull
50      public Set<JobRunnerKey> getRegisteredJobRunnerKeys() {
51          return delegate.getRegisteredJobRunnerKeys();
52      }
53  
54      @Override
55      @Nonnull
56      public Set<JobRunnerKey> getJobRunnerKeysForAllScheduledJobs() {
57          return delegate.getJobRunnerKeysForAllScheduledJobs();
58      }
59  
60      @Override
61      public void scheduleJob(JobId jobId, JobConfig jobConfig) throws SchedulerServiceException {
62          delegate.scheduleJob(jobId, jobConfig);
63      }
64  
65      @Override
66      @Nonnull
67      public JobId scheduleJobWithGeneratedId(JobConfig jobConfig) throws SchedulerServiceException {
68          return delegate.scheduleJobWithGeneratedId(jobConfig);
69      }
70  
71      @Override
72      public void unscheduleJob(JobId jobId) {
73          delegate.unscheduleJob(jobId);
74      }
75  
76      @Override
77      @Nullable
78      public Date calculateNextRunTime(Schedule schedule) throws SchedulerServiceException {
79          return delegate.calculateNextRunTime(schedule);
80      }
81  
82      @Override
83      @CheckForNull
84      public JobDetails getJobDetails(JobId jobId) {
85          return delegate.getJobDetails(jobId);
86      }
87  
88      @Override
89      @Nonnull
90      public List<JobDetails> getJobsByJobRunnerKey(JobRunnerKey jobRunnerKey) {
91          return delegate.getJobsByJobRunnerKey(jobRunnerKey);
92      }
93  }