View Javadoc

1   package com.atlassian.scheduler.core.status;
2   
3   import com.atlassian.scheduler.SchedulerRuntimeException;
4   import com.atlassian.scheduler.config.JobId;
5   import com.atlassian.scheduler.config.JobRunnerKey;
6   import com.atlassian.scheduler.config.RunMode;
7   import com.atlassian.scheduler.config.Schedule;
8   import com.atlassian.scheduler.core.JobRunnerNotRegisteredException;
9   
10  import javax.annotation.Nonnull;
11  import javax.annotation.Nullable;
12  import java.io.Serializable;
13  import java.util.Date;
14  import java.util.Map;
15  
16  /**
17   * Concrete implementation of {@code JobDetails} that always throws an exception when the
18   * parameters are accessed.  This can be used when the {@code JobRunner} is unavailable or
19   * an exception occurs while trying to deserialize the parameters.
20   *
21   * @since v1.0
22   */
23  public class UnusableJobDetails extends AbstractJobDetails {
24      private final Throwable cause;
25  
26      /**
27       * @param cause the reason the parameters are unavailable.  If left {@code null}, then
28       *              it is assumed that the {@code JobRunner} is not available.
29       */
30      public UnusableJobDetails(final JobId jobId, final JobRunnerKey jobRunnerKey, final RunMode runMode,
31                                final Schedule schedule, @Nullable final Date nextRunTime, final byte[] parameters,
32                                @Nullable final Throwable cause) {
33          super(jobId, jobRunnerKey, runMode, schedule, nextRunTime, parameters);
34          this.cause = (cause != null) ? cause : new JobRunnerNotRegisteredException(jobRunnerKey);
35      }
36  
37      /**
38       * The parameters are not available because the map could not be reconstructed.
39       *
40       * @return never returns normally
41       * @throws SchedulerRuntimeException Unconditionally.  The exception's {@code cause} will be
42       *                                   either a {@link JobRunnerNotRegisteredException} or the error that occurred during
43       *                                   deserialization.
44       */
45      @Override
46      @Nonnull
47      public Map<String, Serializable> getParameters() {
48          throw new SchedulerRuntimeException("The parameters cannot be accessed: " + cause, cause);
49      }
50  
51      @Override
52      public boolean isRunnable() {
53          return false;
54      }
55  
56      @Override
57      protected void appendToStringDetails(final StringBuilder sb) {
58          sb.append(",cause=").append(cause);
59      }
60  }