1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.commons.transaction.locking; 18 19 /** 20 * Exception displaying a lock problem. 21 * 22 * @version $Id: LockException.java 493628 2007-01-07 01:42:48Z joerg $ 23 * @since 1.1 24 */ 25 public class LockException extends RuntimeException { 26 27 /** 28 * Thread has been interrupted while waiting for lock. 29 */ 30 public static final int CODE_INTERRUPTED = 1; 31 32 /** 33 * Maximum wait time for a lock has been exceeded. 34 */ 35 public static final int CODE_TIMED_OUT = 2; 36 37 /** 38 * Locking request canceled because of deadlock. 39 */ 40 public static final int CODE_DEADLOCK_VICTIM = 3; 41 42 protected Object resourceId; 43 44 protected String reason; 45 46 protected int code; 47 48 public LockException(String reason, int code, Object resourceId) { 49 this.reason = reason; 50 this.code = code; 51 this.resourceId = resourceId; 52 } 53 54 /** 55 * Returns the formal reason for the exception. 56 * 57 * @return one of {@link #CODE_INTERRUPTED},{@link #CODE_TIMED_OUT}or 58 * {@link #CODE_DEADLOCK_VICTIM}. 59 */ 60 public int getCode() { 61 return code; 62 } 63 64 /** 65 * Returns the resource the lock was tried on. 66 * 67 * @return the resource or <code>null</code> if not applicable 68 */ 69 public Object getResourceId() { 70 return resourceId; 71 } 72 73 /** 74 * Returns the verbose for the exception. 75 * 76 * @return the reason message 77 */ 78 public String getReason() { 79 return reason; 80 } 81 }