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 a transaction sync failure. */
34          TRANSACTION_FAILURE,
35          /** Operation failed due to an unclassified failure. */
36          UNCLASSIFIED_FAILURE
37      }
38  
39      private final Reason reason;
40  
41      /**
42       * Creates an instance for the specified reason.
43       * @param reason the reason for the failure
44       */
45      public ExternalCacheException(Reason reason)
46      {
47          super("Failed due to " + reason.name());
48          this.reason = requireNonNull(reason);
49      }
50  
51      /**
52       * Creates an instance for the specified reason and cause.
53       * @param reason the reason for the failure
54       * @param cause the cause of the failure
55       */
56      public ExternalCacheException(Reason reason, Throwable cause)
57      {
58          super("Failed due to " + reason.name(), cause);
59          this.reason = requireNonNull(reason);
60      }
61  
62      /**
63       * Returns the reason for failure.
64       * @return the reason for failure.
65       */
66      @Nonnull
67      public Reason getReason()
68      {
69          return reason;
70      }
71  }