01: /*
02: * This file is part of the QuickServer library
03: * Copyright (C) 2003-2005 QuickServer.org
04: *
05: * Use, modification, copying and distribution of this software is subject to
06: * the terms and conditions of the GNU Lesser General Public License.
07: * You should have received a copy of the GNU LGP License along with this
08: * library; if not, you can download a copy from <http://www.quickserver.org/>.
09: *
10: * For questions, suggestions, bug-reports, enhancement-requests etc.
11: * visit http://www.quickserver.org
12: *
13: */
14:
15: package org.quickserver.util.pool;
16:
17: import java.util.*;
18: import org.apache.commons.pool.*;
19:
20: /**
21: * This class that creates QSObjectPool from ObjectPool passed to it.
22: * @since 1.4.5
23: */
24: public class MakeQSObjectPool implements QSObjectPool,
25: QSObjectPoolMaker {
26: protected ObjectPool objectPool = null;
27: protected List list = null;
28:
29: public QSObjectPool getQSObjectPool(ObjectPool objectPool) {
30: return new MakeQSObjectPool(objectPool);
31: }
32:
33: public MakeQSObjectPool() {
34: }
35:
36: public MakeQSObjectPool(ObjectPool objectPool) {
37: setObjectPool(objectPool);
38: }
39:
40: protected void setObjectPool(ObjectPool objectPool) {
41: this .objectPool = objectPool;
42: list = Collections.synchronizedList(new LinkedList());
43: }
44:
45: public void returnObject(Object obj) throws Exception {
46: list.remove(obj);
47: objectPool.returnObject(obj);
48: }
49:
50: public Object borrowObject() throws Exception {
51: Object obj = objectPool.borrowObject();
52: list.add(obj);
53: return obj;
54: }
55:
56: public synchronized void close() throws Exception {
57: list.clear();
58: objectPool.close();
59: }
60:
61: /**
62: * Returns the iterator of all active objects
63: */
64: public Iterator getAllActiveObjects() {
65: return list.iterator();
66: }
67:
68: public Object getObjectToSynchronize() {
69: return list;
70: }
71:
72: public void addObject() throws Exception {
73: objectPool.addObject();
74: }
75:
76: public void clear() throws Exception {
77: objectPool.clear();
78: }
79:
80: public int getNumActive() {
81: return objectPool.getNumActive();
82: }
83:
84: public int getNumIdle() {
85: return objectPool.getNumIdle();
86: }
87:
88: public void invalidateObject(Object obj) throws Exception {
89: objectPool.invalidateObject(obj);
90: }
91:
92: public void setFactory(PoolableObjectFactory factory) {
93: objectPool.setFactory(factory);
94: }
95: }
|