01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
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: package org.apache.openjpa.util;
20:
21: import java.io.IOException;
22: import java.io.ObjectInputStream;
23: import java.io.ObjectOutputStream;
24:
25: import org.apache.openjpa.lib.util.Localizer;
26:
27: /**
28: * Exception indicating that locks on one or more objects could not be acquired.
29: *
30: * @author Marc Prud'hommeaux
31: * @since 0.3.1
32: */
33: public class LockException extends StoreException {
34:
35: private static final transient Localizer _loc = Localizer
36: .forPackage(LockException.class);
37:
38: private int timeout = -1;
39:
40: public LockException(Object failed) {
41: super (_loc.get("lock-failed", Exceptions.toString(failed)));
42: setFailedObject(failed);
43: }
44:
45: public LockException(Object failed, int timeout) {
46: super (_loc.get("lock-timeout", Exceptions.toString(failed),
47: String.valueOf(timeout)));
48: setFailedObject(failed);
49: setTimeout(timeout);
50: }
51:
52: public int getSubtype() {
53: return LOCK;
54: }
55:
56: /**
57: * The number of milliseconds to wait for a lock.
58: */
59: public int getTimeout() {
60: return timeout;
61: }
62:
63: /**
64: * The number of milliseconds to wait for a lock.
65: */
66: public LockException setTimeout(int timeout) {
67: this .timeout = timeout;
68: return this ;
69: }
70:
71: public String toString() {
72: String str = super .toString();
73: if (timeout < 0)
74: return str;
75: return str + Exceptions.SEP + "Timeout: " + timeout;
76: }
77:
78: private void writeObject(ObjectOutputStream out) throws IOException {
79: out.writeInt(timeout);
80: }
81:
82: private void readObject(ObjectInputStream in) throws IOException,
83: ClassNotFoundException {
84: timeout = in.readInt();
85: }
86: }
|