View Javadoc

1   package com.atlassian.vcache;
2   
3   import javax.annotation.Nonnull;
4   
5   import com.atlassian.annotations.PublicApi;
6   
7   import static java.util.Objects.requireNonNull;
8   
9   /**
10   * Represents a failure occurred with an {@link ExternalCache}.
11   *
12   * @since 1.0
13   */
14  @PublicApi
15  public class ExternalCacheException extends VCacheException
16  {
17      /**
18       * The reasons for failure. Note that even though a failure may be reported, the operation may have still been
19       * performed on the external cache.
20       */
21      public enum Reason
22      {
23          /** Operation timed out. */
24          TIMEOUT,
25          /** Operation failed due to a network error. */
26          NETWORK_FAILURE,
27          /** Operation failed due a {@link Marshaller} failure. */
28          MARSHALLER_FAILURE,
29          /** Operation failed due to the supplied Function not returning the expected number of values. */
30          FUNCTION_INCORRECT_RESULT,
31          /** Creation of cache failed. */
32          CREATION_FAILURE,
33          /** Operation failed due to an unclassified failure. */
34          UNCLASSIFIED_FAILURE
35      }
36  
37      private final Reason reason;
38  
39      /**
40       * Creates an instance for the specified reason.
41       * @param reason the reason for the failure
42       */
43      public ExternalCacheException(Reason reason)
44      {
45          super("Failed due to " + reason.name());
46          this.reason = requireNonNull(reason);
47      }
48  
49      /**
50       * Creates an instance for the specified reason and cause.
51       * @param reason the reason for the failure
52       * @param cause the cause of the failure
53       */
54      public ExternalCacheException(Reason reason, Throwable cause)
55      {
56          super("Failed due to " + reason.name(), cause);
57          this.reason = requireNonNull(reason);
58      }
59  
60      /**
61       * Returns the reason for failure.
62       * @return the reason for failure.
63       */
64      @Nonnull
65      public Reason getReason()
66      {
67          return reason;
68      }
69  }