KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > pool > AbstractObjectPool


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.pool;
8
9 import org.jfox.ioc.common.AbstractComponent;
10
11 /**
12  * the supper class of all object pool
13  *
14  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
15  */

16
17 public abstract class AbstractObjectPool extends AbstractComponent implements ObjectPool {
18
19     protected ObjectFactory factory = null;
20
21     public AbstractObjectPool(ObjectFactory factory) {
22 // super(factory.getClass().getName());
23
if(factory == null) throw new NullPointerException JavaDoc("factory is null.");
24         this.factory = factory;
25     }
26
27     public AbstractObjectPool(Class JavaDoc factoryClass, Class JavaDoc poolableClass) {
28 // super(objectFactoryClassName);
29
try {
30             factory = (ObjectFactory) factoryClass.getConstructor(new Class JavaDoc[]{java.lang.Class JavaDoc.class}).newInstance(new Object JavaDoc[]{poolableClass});
31         }
32         catch(NoSuchMethodException JavaDoc e) {
33             logger.fatal("No such constructor" + e);
34         }
35         catch(Exception JavaDoc e) {
36             logger.fatal("ObjectFactory " + factoryClass.getName() + " instantiator error" + e);
37         }
38     }
39
40     public ObjectFactory getObjectFactory() {
41         return factory;
42     }
43
44     /**
45      * get the pooled object's class type, it return by object pool's factory
46      *
47      * @return
48      */

49     public String JavaDoc getObjectClass() {
50         return factory.getObjectClass().getName();
51     }
52
53     /**
54      * Clears any objects sitting idle in the pool, releasing any associated resources
55      */

56     public void clear() {
57         throw new UnsupportedOperationException JavaDoc("clear");
58     }
59
60     protected void doInit() throws Exception JavaDoc {
61
62     }
63
64     protected void doDestroy() throws Exception JavaDoc {
65
66     }
67
68     /**
69      * get the count of working object
70      *
71      * @return
72      */

73     public int getWorking() {
74         throw new UnsupportedOperationException JavaDoc("getWorking");
75     }
76
77     /**
78      * get the count of rest object
79      *
80      * @return
81      */

82     public int getRest() {
83         throw new UnsupportedOperationException JavaDoc("getRest");
84     }
85
86     public int getInitNum() {
87         throw new UnsupportedOperationException JavaDoc("getInitNum");
88     }
89
90     public int getMaxRest() {
91         throw new UnsupportedOperationException JavaDoc("getMaxRest");
92     }
93 }
94
Popular Tags