View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  }