View Javadoc

1   package com.atlassian.scheduler.core.status;
2   
3   import com.atlassian.scheduler.config.JobId;
4   import com.atlassian.scheduler.config.JobRunnerKey;
5   import com.atlassian.scheduler.config.RunMode;
6   import com.atlassian.scheduler.config.Schedule;
7   import com.atlassian.scheduler.status.JobDetails;
8   
9   import javax.annotation.Nonnull;
10  import javax.annotation.Nullable;
11  import java.util.Date;
12  
13  import static com.atlassian.scheduler.util.Safe.copy;
14  import static com.atlassian.util.concurrent.Assertions.notNull;
15  
16  /**
17   * Base implementation for {@link JobDetails}.
18   *
19   * @since v1.0
20   */
21  public abstract class AbstractJobDetails implements JobDetails {
22      protected final JobId jobId;
23      protected final JobRunnerKey jobRunnerKey;
24      protected final RunMode runMode;
25      protected final Schedule schedule;
26  
27      private final Date nextRunTime;
28      private final byte[] rawParameters;
29  
30      protected AbstractJobDetails(JobId jobId, JobRunnerKey jobRunnerKey, RunMode runMode,
31                                   Schedule schedule, @Nullable Date nextRunTime, @Nullable byte[] rawParameters) {
32          this.jobId = notNull("jobId", jobId);
33          this.jobRunnerKey = notNull("jobRunnerKey", jobRunnerKey);
34          this.runMode = notNull("runMode", runMode);
35          this.schedule = notNull("schedule", schedule);
36          this.nextRunTime = copy(nextRunTime);
37          this.rawParameters = copy(rawParameters);
38      }
39  
40      @Nonnull
41      public final JobId getJobId() {
42          return jobId;
43      }
44  
45      @Nonnull
46      public final JobRunnerKey getJobRunnerKey() {
47          return jobRunnerKey;
48      }
49  
50      @Nonnull
51      public final RunMode getRunMode() {
52          return runMode;
53      }
54  
55      @Nonnull
56      public Schedule getSchedule() {
57          return schedule;
58      }
59  
60      @Nullable
61      public Date getNextRunTime() {
62          return copy(nextRunTime);
63      }
64  
65      /**
66       * Returns the raw bytes from the job's parameters.
67       * <p>
68       * This is not part of the public API.  It is intended for the persistence layer to use for accessing the raw
69       * parameters and/or a troubleshooting tool for a management interface to use.  For example, it might try to
70       * deserialize the map with the application's class loader or read the raw serialization data to show the
71       * administrator whatever information can be pulled out of it.
72       * </p>
73       *
74       * @return a copy of the raw bytes that encode the job's parameters, or {@code null} if the parameter map
75       * was empty.
76       */
77      @Nullable
78      public final byte[] getRawParameters() {
79          return copy(rawParameters);
80      }
81  
82      @Override
83      public final String toString() {
84          final StringBuilder sb = new StringBuilder(128).append(getClass().getSimpleName())
85                  .append("[jobId=").append(jobId)
86                  .append(",jobRunnerKey=").append(jobRunnerKey)
87                  .append(",runMode=").append(runMode)
88                  .append(",schedule=").append(schedule)
89                  .append(",nextRunTime=").append(nextRunTime)
90                  .append(",rawParameters=(");
91          if (rawParameters == null) {
92              sb.append("null)");
93          } else {
94              sb.append(rawParameters.length).append(" bytes)");
95          }
96          appendToStringDetails(sb);
97          return sb.append(']').toString();
98      }
99  
100     protected abstract void appendToStringDetails(final StringBuilder sb);
101 }