1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.fulcrum.yaafi.framework.locking;
21
22 /**
23 * Exception displaying a lock problem.
24 *
25 * @version $Revision: 1.1 $
26 * @since 1.1
27 */
28 public class LockException extends RuntimeException {
29
30 /**
31 * Thread has been interrupted while waiting for lock.
32 */
33 public static final int CODE_INTERRUPTED = 1;
34
35 /**
36 * Maximum wait time for a lock has been exceeded.
37 */
38 public static final int CODE_TIMED_OUT = 2;
39
40 /**
41 * Locking request canceled because of deadlock.
42 */
43 public static final int CODE_DEADLOCK_VICTIM = 3;
44
45 protected Object resourceId;
46
47 protected String reason;
48
49 protected int code;
50
51 public LockException(String reason, int code, Object resourceId) {
52 this.reason = reason;
53 this.code = code;
54 this.resourceId = resourceId;
55 }
56
57 /**
58 * Returns the formal reason for the exception.
59 *
60 * @return one of {@link #CODE_INTERRUPTED},{@link #CODE_TIMED_OUT}or
61 * {@link #CODE_DEADLOCK_VICTIM}.
62 */
63 public int getCode() {
64 return code;
65 }
66
67 /**
68 * Returns the resource the lock was tried on.
69 *
70 * @return the resource or <code>null</code> if not applicable
71 */
72 public Object getResourceId() {
73 return resourceId;
74 }
75
76 /**
77 * Returns the verbose for the exception.
78 *
79 * @return the reason message
80 */
81 public String getReason() {
82 return reason;
83 }
84 }