01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.org
04: * Distributable under GNU LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package org.huihoo.jfox.pool;
09:
10: import org.huihoo.jfox.service.ComponentSupport;
11:
12: /**
13: * the supper class of all object pool
14: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
15: */
16:
17: public abstract class AbstractObjectPool extends ComponentSupport
18: implements ObjectPool {
19:
20: protected ObjectFactory factory = null;
21:
22: public AbstractObjectPool(ObjectFactory factory) {
23: // super(factory.getClass().getName());
24: if (factory == null)
25: throw new NullPointerException("factory is null.");
26: this .factory = factory;
27: }
28:
29: public AbstractObjectPool(String objectFactoryClassName,
30: String poolableClassName) {
31: // super(objectFactoryClassName);
32: ClassLoader loader = Thread.currentThread()
33: .getContextClassLoader();
34: try {
35: Class factoryClass = loader
36: .loadClass(objectFactoryClassName);
37: factory = (ObjectFactory) factoryClass.getConstructor(
38: new Class[] { java.lang.String.class })
39: .newInstance(new String[] { poolableClassName });
40: } catch (ClassNotFoundException e) {
41: logger.fatal("Class " + objectFactoryClassName
42: + " not found!" + e);
43: } catch (NoSuchMethodException e) {
44: logger.fatal("No such constructor" + e);
45: } catch (Exception e) {
46: logger.fatal("ObjectFactory " + objectFactoryClassName
47: + " instantiator error" + e);
48: }
49: }
50:
51: public ObjectFactory getObjectFactory() {
52: return factory;
53: }
54:
55: /**
56: * get the pooled object's class type, it return by object pool's factory
57: * @return
58: */
59: public String getObjectClass() {
60: return factory.getObjectClass().getName();
61: }
62:
63: /**
64: * Clears any objects sitting idle in the pool, releasing any associated resources
65: */
66: public void clear() {
67: throw new UnsupportedOperationException("clear");
68: }
69:
70: protected void doInit() throws Exception {
71:
72: }
73:
74: protected void doDestroy() throws Exception {
75:
76: }
77:
78: /**
79: * get the count of working object
80: * @return
81: */
82: public int getWorking() {
83: throw new UnsupportedOperationException("getWorking");
84: }
85:
86: /**
87: * get the count of rest object
88: * @return
89: */
90: public int getRest() {
91: throw new UnsupportedOperationException("getRest");
92: }
93:
94: }
|