01: /*
02: * Copyright 1999-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.commons.pool;
18:
19: /**
20: * A simple base impementation of {@link ObjectPool}.
21: * All optional operations are implemented as throwing
22: * {@link UnsupportedOperationException}.
23: *
24: * @author Rodney Waldhoff
25: * @version $Revision: 383290 $ $Date: 2006-03-05 02:00:15 -0500 (Sun, 05 Mar 2006) $
26: */
27: public abstract class BaseObjectPool implements ObjectPool {
28: public abstract Object borrowObject() throws Exception;
29:
30: public abstract void returnObject(Object obj) throws Exception;
31:
32: public abstract void invalidateObject(Object obj) throws Exception;
33:
34: /**
35: * Not supported in this base implementation.
36: */
37: public int getNumIdle() throws UnsupportedOperationException {
38: throw new UnsupportedOperationException();
39: }
40:
41: /**
42: * Not supported in this base implementation.
43: */
44: public int getNumActive() throws UnsupportedOperationException {
45: throw new UnsupportedOperationException();
46: }
47:
48: /**
49: * Not supported in this base implementation.
50: */
51: public void clear() throws Exception, UnsupportedOperationException {
52: throw new UnsupportedOperationException();
53: }
54:
55: /**
56: * Not supported in this base implementation.
57: */
58: public void addObject() throws Exception,
59: UnsupportedOperationException {
60: throw new UnsupportedOperationException();
61: }
62:
63: public void close() throws Exception {
64: assertOpen();
65: closed = true;
66: }
67:
68: /**
69: * Not supported in this base implementation.
70: */
71: public void setFactory(PoolableObjectFactory factory)
72: throws IllegalStateException, UnsupportedOperationException {
73: throw new UnsupportedOperationException();
74: }
75:
76: protected final boolean isClosed() {
77: return closed;
78: }
79:
80: protected final void assertOpen() throws IllegalStateException {
81: if (isClosed()) {
82: throw new IllegalStateException("Pool not open");
83: }
84: }
85:
86: private volatile boolean closed = false;
87: }
|