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 RuntimeException
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 an unclassified failure. */
30 UNCLASSIFIED_FAILURE
31 }
32
33 private final Reason reason;
34
35 /**
36 * Creates an instance for the specified reason.
37 * @param reason the reason for the failure
38 */
39 public ExternalCacheException(Reason reason)
40 {
41 this.reason = requireNonNull(reason);
42 }
43
44 /**
45 * Creates an instance for the specified reason and cause.
46 * @param reason the reason for the failure
47 * @param cause the cause of the failure
48 */
49 public ExternalCacheException(Reason reason, Throwable cause)
50 {
51 super(cause);
52 this.reason = requireNonNull(reason);
53 }
54
55 /**
56 * Returns the reason for failure.
57 * @return the reason for failure.
58 */
59 @Nonnull
60 public Reason getReason()
61 {
62 return reason;
63 }
64 }