Added:
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/Pool.java
Deleted:
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/PoolType.java
Modified:
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/AbstractBaseController.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/AbstractBaseFactory.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/AbstractBasePooling.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/BasePooling.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/CommonPool.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/PoolStaticUtils.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/StackPool.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/WeakPool.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/annotation/Pooling.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/annotation/SystemPooling.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/context/PoolScope.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/support/PoolInvocationMethodInterceptor.java
=======================================
--- /dev/null
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/Pool.java
Sun Aug 2 17:54:16 2009
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2007-2009 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project: JGentleFramework
+ */
+package org.jgentleframework.services.objectpooling;
+
+import java.util.NoSuchElementException;
+
+import org.jgentleframework.context.beans.Disposable;
+
+/**
+ * A pooling interface.
+ * <p>
+ * {@link Pool} defines a trivially simple pooling interface.
+ *
+ * @author Quoc Chung - mailto: <a
+ * href="mailto:skydu...@yahoo.com">skydu...@yahoo.com</a>
+ * @date Apr 7, 2009
+ */
+public interface Pool {
+ /**
+ * Creates an object using the implementation dependent mechanism,
passivate
+ * it, and then place it in the idle object pool. <code>addObject</code>
is
+ * useful for "pre-loading" a pool with idle objects. (Optional
operation).
+ *
+ * @throws Throwable
+ * when creation fails.
+ * @throws UnsupportedOperationException
+ * when this pool cannot add new idle objects.
+ */
+ void addObject() throws UnsupportedOperationException, Throwable;
+
+ /**
+ * Clears any objects sitting idle in the pool, releasing any associated
+ * resources (optional operation). Idle objects cleared must be
+ * {@link Disposable#destroy() destroyed}.
+ *
+ * @throws UnsupportedOperationException
+ * if this implementation does not support the operation
+ */
+ void clear() throws UnsupportedOperationException, Throwable;
+
+ /**
+ * Close this pool, and free any resources associated with it.
+ *
+ * @throws Throwable
+ * implementations should silently fail if not all resources
can
+ * be freed.
+ */
+ void close() throws Throwable;
+
+ /**
+ * Returns the number of instances currently borrowed from this pool
+ * (optional operation). Returns a negative value if this information is
not
+ * available.
+ *
+ * @return the number of instances currently borrowed from this pool or a
+ * negative value if unsupported
+ * @throws UnsupportedOperationException
+ * if this implementation does not support the operation
+ */
+ int getNumActive() throws UnsupportedOperationException;
+
+ /**
+ * Returns the number of instances currently idle in this pool (optional
+ * operation). This may be considered an approximation of the number of
+ * objects that can be {@link #obtainObject() borrowed} without creating
any
+ * new instances. Returns a negative value if this information is not
+ * available.
+ *
+ * @return the number of instances currently idle in this pool or a
negative
+ * value if unsupported
+ * @throws UnsupportedOperationException
+ * if this implementation does not support the operation
+ */
+ int getNumIdle() throws UnsupportedOperationException;
+
+ /**
+ * Invalidates an object from the pool.
+ * <p>
+ * This method should be used when an object that has been borrowed is
+ * determined (due to an exception or other problem) to be invalid.
+ *
+ * @param obj
+ * a {@link #obtainObject() borrowed} instance to be disposed.
+ * @throws Throwable
+ * the throwable
+ */
+ void invalidateObject(Object obj) throws Throwable;
+
+ /**
+ * Checks if this pool is empty.
+ *
+ * @return true, if is empty
+ */
+ boolean isEmpty();
+
+ /**
+ * Obtains an instance from this pool.
+ * <p>
+ * The behaviour of this method when the pool has been exhausted is not
+ * strictly specified (although it may be specified by implementations).
+ * This method will return <code>null</code> to indicate exhaustion or
throw
+ * a {@link NoSuchElementException}.
+ *
+ * @return an instance from this pool.
+ * @throws NoSuchElementException
+ * when the pool is exhausted and cannot or will not return
+ * another instance.
+ */
+ Object obtainObject() throws NoSuchElementException, Throwable;
+
+ /**
+ * Return an instance to the pool.
+ *
+ * @param obj
+ * a {@link #obtainObject() borrowed} instance to be returned.
+ */
+ void returnObject(Object obj) throws Throwable;
+}
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/PoolType.java
Wed Jun 24 01:53:41 2009
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright 2007-2009 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Project: JGentleFramework
- */
-package org.jgentleframework.services.objectpooling;
-
-import java.util.NoSuchElementException;
-
-import org.jgentleframework.context.beans.Disposable;
-
-/**
- * A pooling interface.
- * <p>
- * {@link PoolType} defines a trivially simple pooling interface.
- *
- * @author Quoc Chung - mailto: <a
- * href="mailto:skydu...@yahoo.com">skydu...@yahoo.com</a>
- * @date Apr 7, 2009
- */
-public interface PoolType {
- /**
- * Creates an object using the implementation dependent mechanism,
passivate
- * it, and then place it in the idle object pool. <code>addObject</code>
is
- * useful for "pre-loading" a pool with idle objects. (Optional
operation).
- *
- * @throws Throwable
- * when creation fails.
- * @throws UnsupportedOperationException
- * when this pool cannot add new idle objects.
- */
- void addObject() throws UnsupportedOperationException, Throwable;
-
- /**
- * Clears any objects sitting idle in the pool, releasing any associated
- * resources (optional operation). Idle objects cleared must be
- * {@link Disposable#destroy() destroyed}.
- *
- * @throws UnsupportedOperationException
- * if this implementation does not support the operation
- */
- void clear() throws UnsupportedOperationException, Throwable;
-
- /**
- * Close this pool, and free any resources associated with it.
- *
- * @throws Throwable
- * implementations should silently fail if not all resources
can
- * be freed.
- */
- void close() throws Throwable;
-
- /**
- * Returns the number of instances currently borrowed from this pool
- * (optional operation). Returns a negative value if this information is
not
- * available.
- *
- * @return the number of instances currently borrowed from this pool or a
- * negative value if unsupported
- * @throws UnsupportedOperationException
- * if this implementation does not support the operation
- */
- int getNumActive() throws UnsupportedOperationException;
-
- /**
- * Returns the number of instances currently idle in this pool (optional
- * operation). This may be considered an approximation of the number of
- * objects that can be {@link #obtainObject() borrowed} without creating
any
- * new instances. Returns a negative value if this information is not
- * available.
- *
- * @return the number of instances currently idle in this pool or a
negative
- * value if unsupported
- * @throws UnsupportedOperationException
- * if this implementation does not support the operation
- */
- int getNumIdle() throws UnsupportedOperationException;
-
- /**
- * Invalidates an object from the pool.
- * <p>
- * This method should be used when an object that has been borrowed is
- * determined (due to an exception or other problem) to be invalid.
- *
- * @param obj
- * a {@link #obtainObject() borrowed} instance to be disposed.
- * @throws Throwable
- * the throwable
- */
- void invalidateObject(Object obj) throws Throwable;
-
- /**
- * Checks if this pool is empty.
- *
- * @return true, if is empty
- */
- boolean isEmpty();
-
- /**
- * Obtains an instance from this pool.
- * <p>
- * The behaviour of this method when the pool has been exhausted is not
- * strictly specified (although it may be specified by implementations).
- * This method will return <code>null</code> to indicate exhaustion or
throw
- * a {@link NoSuchElementException}.
- *
- * @return an instance from this pool.
- * @throws NoSuchElementException
- * when the pool is exhausted and cannot or will not return
- * another instance.
- */
- Object obtainObject() throws NoSuchElementException, Throwable;
-
- /**
- * Return an instance to the pool.
- *
- * @param obj
- * a {@link #obtainObject() borrowed} instance to be returned.
- */
- void returnObject(Object obj) throws Throwable;
-}
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/AbstractBaseController.java
Wed Jul 29 17:21:08 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/AbstractBaseController.java
Sun Aug 2 17:54:16 2009
@@ -48,14 +48,92 @@
* @author Quoc Chung - mailto: <a
* href="mailto:skydu...@yahoo.com">skydu...@yahoo.com</a>
* @date Jun 22, 2009
+ * @see AbstractBasePooling
*/
public abstract class AbstractBaseController extends AbstractBasePooling
implements ProviderAware {
/** The num active. */
- protected int numActive = 0;
+ protected int numActive = 0;
/** The current {@link Provider}. */
- protected Provider provider = null;
+ protected Provider provider = null;
+
+ /** The init method lst. */
+ protected List<Method> initMethodLst = null;
+
+ /** The can be pooled method lst. */
+ protected List<Method> canBePooledMethodLst = null;
+
+ /** The deactivate method lst. */
+ protected List<Method> deactivateMethodLst = null;
+
+ /** The disposable method lst. */
+ protected List<Method> disposableMethodLst = null;
+
+ /** The validate method lst. */
+ protected List<Method> validateMethodLst = null;
+
+ /*
+ * (non-Javadoc)
+ * @see
+ *
org.jgentleframework.services.objectpooling.AbstractBasePooling#activate
+ * ()
+ */
+ @Override
+ public synchronized void activate() {
+
+ super.activate();
+ // Find activate methods
+ if (this.definition
+ .isAnnotationPresentAtAnyMethods(InitializingMethod.class)) {
+ this.initMethodLst = this.definition
+ .getMethodsAnnotatedWith(InitializingMethod.class);
+ }
+ // Find canBePooled methods
+ if (this.definition
+ .isAnnotationPresentAtAnyMethods(CanBePooledMethod.class)) {
+ this.canBePooledMethodLst = this.definition
+ .getMethodsAnnotatedWith(CanBePooledMethod.class);
+ for (Method method : canBePooledMethodLst) {
+ if (method.getReturnType() != Boolean.class
+ && method.getReturnType() != boolean.class) {
+ if (log.isErrorEnabled()) {
+ log.error("The 'return type' of canBePooled method ["
+ + method + "] must be boolean !!",
+ new UnsupportedOperationException());
+ }
+ }
+ }
+ }
+ // Find deactivate methods
+ if (this.definition
+ .isAnnotationPresentAtAnyMethods(DeactivateMethod.class)) {
+ this.deactivateMethodLst = this.definition
+ .getMethodsAnnotatedWith(DeactivateMethod.class);
+ }
+ // Find disposable methods
+ if (this.definition
+ .isAnnotationPresentAtAnyMethods(DisposableMethod.class)) {
+ this.disposableMethodLst = this.definition
+ .getMethodsAnnotatedWith(DisposableMethod.class);
+ }
+ // Find validate methods
+ if (this.definition
+ .isAnnotationPresentAtAnyMethods(ValidateMethod.class)) {
+ this.validateMethodLst = this.definition
+ .getMethodsAnnotatedWith(ValidateMethod.class);
+ for (Method method : validateMethodLst) {
+ if (method.getReturnType() != Boolean.class
+ && method.getReturnType() != boolean.class) {
+ if (log.isErrorEnabled()) {
+ log.error("The 'return type' of validate method ["
+ + method + "] must be boolean !!",
+ new UnsupportedOperationException());
+ }
+ }
+ }
+ }
+ }
/**
* Activates object.
@@ -70,11 +148,8 @@
if (obj != null) {
if (ReflectUtils.isCast(Initializing.class, obj))
((Initializing) obj).activate();
- else if (this.definition
- .isAnnotationPresentAtAnyMethods(InitializingMethod.class)) {
- List<Method> methods = this.definition
- .getMethodsAnnotatedWith(InitializingMethod.class);
- for (Method method : methods) {
+ else if (this.initMethodLst != null) {
+ for (Method method : initMethodLst) {
method.setAccessible(true);
method.invoke(obj);
}
@@ -88,6 +163,8 @@
* @param obj
* the obj
* @return true, if can be pooled
+ * @throws Throwable
+ * the throwable
*/
protected boolean canBePooled(Object obj) throws Throwable {
@@ -97,25 +174,10 @@
&& ReflectUtils.isCast(CanBePooled.class, obj)) {
return ((CanBePooled) obj).canBePooled();
}
- else if (this.definition
- .isAnnotationPresentAtAnyMethods(CanBePooledMethod.class)) {
- List<Method> methods = this.definition
- .getMethodsAnnotatedWith(CanBePooledMethod.class);
- for (Method method : methods) {
- if (method.getReturnType() == Boolean.class
- || method.getReturnType() == boolean.class) {
- method.setAccessible(true);
- return (Boolean) method.invoke(obj);
- }
- else {
- if (log.isErrorEnabled()) {
- log.error(
- "The 'return type' of canBePooled method ["
- + method
- + "] must be boolean !!",
- new UnsupportedOperationException());
- }
- }
+ else if (this.canBePooledMethodLst != null) {
+ for (Method method : canBePooledMethodLst) {
+ method.setAccessible(true);
+ return (Boolean) method.invoke(obj);
}
}
}
@@ -138,6 +200,8 @@
* @return the object
* @throws Exception
* the exception
+ * @throws Throwable
+ * the throwable
*/
protected Object createsBean() throws Throwable {
@@ -199,6 +263,8 @@
*
* @param obj
* the obj
+ * @throws Throwable
+ * the throwable
*/
protected void deactivateObject(Object obj) throws Throwable {
@@ -207,11 +273,8 @@
if (ReflectUtils.isCast(Deactivate.class, obj)) {
((Deactivate) obj).deactivate();
}
- else if (this.definition
- .isAnnotationPresentAtAnyMethods(DeactivateMethod.class)) {
- List<Method> methods = this.definition
- .getMethodsAnnotatedWith(DeactivateMethod.class);
- for (Method method : methods) {
+ else if (this.deactivateMethodLst != null) {
+ for (Method method : deactivateMethodLst) {
method.setAccessible(true);
method.invoke(obj);
}
@@ -231,7 +294,7 @@
/*
* (non-Javadoc)
* @see
- * org.jgentleframework.services.objectpooling.PoolType#invalidateObject
+ * org.jgentleframework.services.objectpooling.Pool#invalidateObject
* (java.lang.Object)
*/
@Override
@@ -253,6 +316,8 @@
*
* @param obj
* the given object need to be destroyed.
+ * @throws Throwable
+ * the throwable
*/
protected void destroyObject(Object obj) throws Throwable {
@@ -260,11 +325,8 @@
if (obj != null) {
if (ReflectUtils.isCast(Disposable.class, obj))
((Disposable) obj).destroy();
- else if (this.definition
- .isAnnotationPresentAtAnyMethods(DisposableMethod.class)) {
- List<Method> methods = this.definition
- .getMethodsAnnotatedWith(DisposableMethod.class);
- for (Method method : methods) {
+ else if (this.disposableMethodLst != null) {
+ for (Method method : disposableMethodLst) {
method.setAccessible(true);
method.invoke(obj);
}
@@ -284,6 +346,8 @@
* the given object need to be validated.
* @throws Exception
* the exception
+ * @throws Throwable
+ * the throwable
*/
protected void validatesObject(Object obj) throws Throwable {
@@ -294,26 +358,11 @@
if (!((Validate) obj).validate())
throw new Exception("Validate failed !!");
}
- else if (this.definition
- .isAnnotationPresentAtAnyMethods(ValidateMethod.class)) {
- List<Method> methods = this.definition
- .getMethodsAnnotatedWith(ValidateMethod.class);
- for (Method method : methods) {
- if (method.getReturnType() == Boolean.class
- || method.getReturnType() == boolean.class) {
- method.setAccessible(true);
- if (!(Boolean) method.invoke(obj))
- throw new Exception("Validate failed !!");
- }
- else {
- if (log.isErrorEnabled()) {
- log.error(
- "The 'return type' of validate method ["
- + method
- + "] must be boolean !!",
- new UnsupportedOperationException());
- }
- }
+ else if (this.validateMethodLst != null) {
+ for (Method method : validateMethodLst) {
+ method.setAccessible(true);
+ if (!(Boolean) method.invoke(obj))
+ throw new Exception("Validate failed !!");
}
}
}
@@ -340,7 +389,7 @@
/*
* (non-Javadoc)
- * @see
org.jgentleframework.services.objectpooling.PoolType#getNumActive()
+ * @see org.jgentleframework.services.objectpooling.Pool#getNumActive()
*/
@Override
public synchronized int getNumActive() {
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/AbstractBaseFactory.java
Thu Jul 30 17:59:31 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/AbstractBaseFactory.java
Sun Aug 2 17:54:16 2009
@@ -34,6 +34,18 @@
public abstract class AbstractBaseFactory extends AbstractBaseController {
/** pool. */
protected Collection<TimestampObjectBean<Object>> pool = null;
+
+ /*
+ * (non-Javadoc)
+ * @see
+ *
org.jgentleframework.services.objectpooling.AbstractBasePooling#activate
+ * ()
+ */
+ @Override
+ public synchronized void activate() {
+
+ super.activate();
+ }
/**
* Adds the object to pool.
@@ -63,11 +75,11 @@
}
synchronized (this) {
if (isEnable() && success) {
-// if (ReflectUtils.isCast(Stack.class, pool))
-// ((Stack<TimestampObjectBean<Object>>) pool)
-// .push(new TimestampObjectBean<Object>(obj));
-// else
- pool.add(new TimestampObjectBean<Object>(obj));
+ // if (ReflectUtils.isCast(Stack.class, pool))
+ // ((Stack<TimestampObjectBean<Object>>) pool)
+ // .push(new TimestampObjectBean<Object>(obj));
+ // else
+ pool.add(new TimestampObjectBean<Object>(obj));
}
}
if (decrementNumActive) {
@@ -80,7 +92,7 @@
/*
* (non-Javadoc)
- * @see org.jgentleframework.services.objectpooling.PoolType#clear()
+ * @see org.jgentleframework.services.objectpooling.Pool#clear()
*/
@Override
public void clear() throws UnsupportedOperationException, Throwable {
@@ -99,7 +111,7 @@
/*
* (non-Javadoc)
* @see
- * org.jgentleframework.services.objectpooling.PoolType#returnObject(java
+ * org.jgentleframework.services.objectpooling.Pool#returnObject(java
* .lang.Object)
*/
@Override
@@ -110,7 +122,7 @@
/*
* (non-Javadoc)
- * @see org.jgentleframework.services.objectpooling.PoolType#getNumIdle()
+ * @see org.jgentleframework.services.objectpooling.Pool#getNumIdle()
*/
@Override
public int getNumIdle() throws UnsupportedOperationException {
@@ -120,7 +132,7 @@
/*
* (non-Javadoc)
- * @see org.jgentleframework.services.objectpooling.PoolType#isEmpty()
+ * @see org.jgentleframework.services.objectpooling.Pool#isEmpty()
*/
@Override
public boolean isEmpty() {
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/AbstractBasePooling.java
Wed Jul 29 17:21:08 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/AbstractBasePooling.java
Sun Aug 2 17:54:16 2009
@@ -35,7 +35,7 @@
* href="mailto:skydu...@yahoo.com">skydu...@yahoo.com</a>
* @date Apr 1, 2009
*/
-public abstract class AbstractBasePooling implements PoolType,
Initializing,
+public abstract class AbstractBasePooling implements Pool, Initializing,
BasePooling {
/** The can be pooled. */
protected boolean canBePooled = SystemPooling.DEFAULT_CAN_BE_POOLED;
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/BasePooling.java
Wed Jun 24 01:53:41 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/BasePooling.java
Sun Aug 2 17:54:16 2009
@@ -26,9 +26,9 @@
* @author Quoc Chung - mailto: <a
* href="mailto:skydu...@yahoo.com">skydu...@yahoo.com</a>
* @date Apr 13, 2009
- * @see PoolType
+ * @see Pool
*/
-public interface BasePooling extends PoolType {
+public interface BasePooling extends Pool {
/**
* Throws an <code>IllegalStateException</code> when this pool has been
* disabled.
@@ -41,9 +41,9 @@
/**
* Returns the maximum amount of time (in millis) the
- * {@link PoolType#obtainObject()} method should block before throwing an
+ * {@link Pool#obtainObject()} method should block before throwing an
* exception when the pool is exhausted. When less than or equal to 0, the
- * {@link PoolType#obtainObject()} method may block indefinitely.
+ * {@link Pool#obtainObject()} method may block indefinitely.
*
* @return the creation time out
*/
@@ -57,7 +57,7 @@
public Evictor getEvictor();
/**
- * Returns the action to take when the {@link PoolType#obtainObject()}
+ * Returns the action to take when the {@link Pool#obtainObject()}
* method is invoked when the pool is exhausted (the maximum number of
* "active" objects has been reached).
*
@@ -130,10 +130,10 @@
/**
* When <b>true</b>, objects will be validated by
* {@link CanBePooled#canBePooled()} before being returned to the pool
- * within the {@link PoolType#returnObject}.
+ * within the {@link Pool#returnObject}.
*
* @return <code>true</code> when objects will be validated before
returned
- * to {@link PoolType#returnObject}.
+ * to {@link Pool#returnObject}.
*/
public boolean isCanBePooled();
@@ -151,7 +151,7 @@
/**
* Whether or not the idle object pool acts as a LIFO queue. True means
that
- * {@link PoolType#obtainObject()} returns the most recently used
+ * {@link Pool#obtainObject()} returns the most recently used
* ("last in") idle object in the pool (if there are idle instances
* available). False means that the pool behaves as a FIFO queue - objects
* are taken from the idle object pool in the order that they are returned
@@ -161,7 +161,7 @@
/**
* When <b>true</b>, objects will be {@link Validate#validate() validated}
- * before being returned by the {@link PoolType#obtainObject()} method. If
+ * before being returned by the {@link Pool#obtainObject()} method. If
* the object fails to validate, it will be dropped from the pool, and we
* will attempt to borrow another.
*/
@@ -177,20 +177,20 @@
/**
* When <b>true</b>, objects will be validated by
* {@link CanBePooled#canBePooled()} before being returned to the pool
- * within the {@link PoolType#returnObject}.
+ * within the {@link Pool#returnObject}.
*
* @param canBePooled
* <code>true</code> so objects will be
* {@link CanBePooled#canBePooled() validated} after returned
to
- * {@link PoolType#returnObject}.
+ * {@link Pool#returnObject}.
*/
public void setCanBePooled(boolean canBePooled);
/**
* Sets the maximum amount of time (in millis) the
- * {@link PoolType#obtainObject()} method should block before throwing an
+ * {@link Pool#obtainObject()} method should block before throwing an
* exception when the pool is exhausted. When less than or equal to 0, the
- * {@link PoolType#obtainObject()} method may block indefinitely.
+ * {@link Pool#obtainObject()} method may block indefinitely.
*
* @param creationTimeOut
* the creation TimeOut to set
@@ -314,7 +314,7 @@
/**
* When <b>true</b>, objects will be {@link Validate#validate() validated}
- * before being returned by the {@link PoolType#obtainObject()} method. If
+ * before being returned by the {@link Pool#obtainObject()} method. If
* the object fails to validate, it will be dropped from the pool, and we
* will attempt to borrow another.
*
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/CommonPool.java
Wed Jul 29 17:21:08 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/CommonPool.java
Sun Aug 2 17:54:16 2009
@@ -32,7 +32,7 @@
* @author Quoc Chung - mailto: <a
* href="mailto:skydu...@yahoo.com">skydu...@yahoo.com</a>
* @date Apr 8, 2008
- * @see PoolType
+ * @see Pool
* @see BasePooling
* @see ProviderAware
* @see Initializing
@@ -58,7 +58,7 @@
/*
* (non-Javadoc)
- * @see org.jgentleframework.services.objectpooling.PoolType#addObject()
+ * @see org.jgentleframework.services.objectpooling.Pool#addObject()
*/
@Override
public void addObject() throws UnsupportedOperationException, Throwable {
@@ -70,7 +70,7 @@
/*
* (non-Javadoc)
- * @see org.jgentleframework.services.objectpooling.PoolType#close()
+ * @see org.jgentleframework.services.objectpooling.Pool#close()
*/
@Override
public void close() throws Throwable {
@@ -84,7 +84,7 @@
/*
* (non-Javadoc)
- * @see
org.jgentleframework.services.objectpooling.PoolType#obtainObject()
+ * @see org.jgentleframework.services.objectpooling.Pool#obtainObject()
*/
@Override
public Object obtainObject() throws NoSuchElementException, Throwable {
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/PoolStaticUtils.java
Wed Jul 15 04:51:31 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/PoolStaticUtils.java
Sun Aug 2 17:54:16 2009
@@ -126,7 +126,7 @@
* @param basePool
* the base pool
* @throws Exception
- * when {@link PoolType#addObject()} fails.
+ * when {@link Pool#addObject()} fails.
*/
public static void ensureMinIdle(BasePooling basePool) throws Throwable {
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/StackPool.java
Thu Jul 30 17:59:31 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/StackPool.java
Sun Aug 2 17:54:16 2009
@@ -52,7 +52,7 @@
/*
* (non-Javadoc)
- * @see org.jgentleframework.services.objectpooling.PoolType#addObject()
+ * @see org.jgentleframework.services.objectpooling.Pool#addObject()
*/
@Override
public void addObject() throws UnsupportedOperationException, Throwable {
@@ -72,7 +72,7 @@
/*
* (non-Javadoc)
- * @see org.jgentleframework.services.objectpooling.PoolType#close()
+ * @see org.jgentleframework.services.objectpooling.Pool#close()
*/
@Override
public void close() throws Throwable {
@@ -86,7 +86,7 @@
/*
* (non-Javadoc)
- * @see
org.jgentleframework.services.objectpooling.PoolType#obtainObject()
+ * @see org.jgentleframework.services.objectpooling.Pool#obtainObject()
*/
@Override
public Object obtainObject() throws NoSuchElementException, Throwable {
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/WeakPool.java
Thu Jun 25 00:40:10 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/WeakPool.java
Sun Aug 2 17:54:16 2009
@@ -61,7 +61,7 @@
/*
* (non-Javadoc)
- * @see org.jgentleframework.services.objectpooling.PoolType#addObject()
+ * @see org.jgentleframework.services.objectpooling.Pool#addObject()
*/
@Override
public synchronized void addObject() throws Throwable {
@@ -85,7 +85,7 @@
/*
* (non-Javadoc)
- * @see org.jgentleframework.services.objectpooling.PoolType#close()
+ * @see org.jgentleframework.services.objectpooling.Pool#close()
*/
@Override
public void close() throws Throwable {
@@ -96,7 +96,7 @@
/*
* (non-Javadoc)
- * @see org.jgentleframework.services.objectpooling.PoolType#clear()
+ * @see org.jgentleframework.services.objectpooling.Pool#clear()
*/
@Override
public synchronized void clear() throws Throwable {
@@ -132,7 +132,7 @@
/*
* (non-Javadoc)
- * @see
org.jgentleframework.services.objectpooling.PoolType#obtainObject()
+ * @see org.jgentleframework.services.objectpooling.Pool#obtainObject()
*/
@Override
public Object obtainObject() throws NoSuchElementException {
@@ -186,7 +186,7 @@
/*
* (non-Javadoc)
* @see
- * org.jgentleframework.services.objectpooling.PoolType#returnObject(java
+ * org.jgentleframework.services.objectpooling.Pool#returnObject(java
* .lang.Object)
*/
@Override
@@ -210,7 +210,7 @@
/*
* (non-Javadoc)
- * @see org.jgentleframework.services.objectpooling.PoolType#isEmpty()
+ * @see org.jgentleframework.services.objectpooling.Pool#isEmpty()
*/
@Override
public boolean isEmpty() {
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/annotation/Pooling.java
Wed Jun 24 01:53:41 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/annotation/Pooling.java
Sun Aug 2 17:54:16 2009
@@ -22,7 +22,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.jgentleframework.services.objectpooling.PoolType;
+import org.jgentleframework.services.objectpooling.Pool;
/**
* This annotation provides some basic parameters that affect the pooling
@@ -83,16 +83,16 @@
/**
* The default maximum amount of time (in milliseconds) the
- * {@link PoolType#obtainObject()} method should block before throwing an
+ * {@link Pool#obtainObject()} method should block before throwing an
* exception when the pool is exhausted and the
* {@link SystemPooling#exhaustedActionType() "when exhausted" action} is
* {@link SystemPooling#EXHAUSTED_BLOCK}.
* <p>
* The values should be greater than <b>0</b>. When less than or equal to
0,
- * the {@link PoolType#obtainObject()} method may block indefinitely.
+ * the {@link Pool#obtainObject()} method may block indefinitely.
* <p>
* The default setting for this parameter is <b>-1</b> (the
- * {@link PoolType#obtainObject()} method is blocked indefinitely).
+ * {@link Pool#obtainObject()} method is blocked indefinitely).
*/
long creationTimeOut() default SystemPooling.DEFAULT_CREATION_TIME_OUT;
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/annotation/SystemPooling.java
Wed Jun 24 01:53:41 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/annotation/SystemPooling.java
Sun Aug 2 17:54:16 2009
@@ -23,7 +23,7 @@
import java.lang.annotation.Target;
import java.util.NoSuchElementException;
-import org.jgentleframework.services.objectpooling.PoolType;
+import org.jgentleframework.services.objectpooling.Pool;
import org.jgentleframework.services.objectpooling.context.Validate;
/**
@@ -188,7 +188,7 @@
/**
* When <tt>true</tt>, object beans will be {@link Validate#validate()
- * validated} before being returned by the {@link PoolType#obtainObject()}
+ * validated} before being returned by the {@link Pool#obtainObject()}
* method. If the object fails to validate, it will be dropped from the
* pool, and we will attempt to borrow another.
*/
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/context/PoolScope.java
Thu Jul 30 17:59:31 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/context/PoolScope.java
Sun Aug 2 17:54:16 2009
@@ -41,7 +41,7 @@
import org.jgentleframework.core.interceptor.ReturnScopeName;
import org.jgentleframework.core.reflection.metadata.Definition;
import org.jgentleframework.services.objectpooling.PoolOperationException;
-import org.jgentleframework.services.objectpooling.PoolType;
+import org.jgentleframework.services.objectpooling.Pool;
import org.jgentleframework.services.objectpooling.annotation.Pooling;
import
org.jgentleframework.services.objectpooling.support.PoolInvocationMethodInterceptor;
import org.jgentleframework.utils.Assertor;
@@ -81,11 +81,10 @@
*/
WeakPool;
/** The log. */
- private final Log log = LogFactory
- .getLog(getClass());
+ private final Log log = LogFactory.getLog(getClass());
/** The pool list */
- ConcurrentMap<String, PoolType> poolServices = new
ConcurrentHashMap<String, PoolType>();
+ ConcurrentMap<String, Pool> poolServices = new ConcurrentHashMap<String,
Pool>();
/*
* (non-Javadoc)
@@ -112,7 +111,7 @@
scope = (PoolScope) scopeList.get(scopeName);
}
synchronized (scopeName) {
- PoolType pool = this.poolServices.get(scopeName);
+ Pool pool = this.poolServices.get(scopeName);
if (pool != null) {
synchronized (pool) {
result = this.obtainInstance(pool, poolingConfig,
@@ -120,7 +119,7 @@
}
}
else {
- Class<? extends PoolType> clazz = null;
+ Class<? extends Pool> clazz = null;
switch (scope) {
case CommonPool:
clazz = org.jgentleframework.services.objectpooling.CommonPool.class;
@@ -143,7 +142,7 @@
poolingConfig, definition, selector).in(clazz).id(
clazz.toString()).scope(Scope.SINGLETON);
binder.flush();
- pool = (PoolType) provider.getBeanBoundToDefinition(clazz
+ pool = (Pool) provider.getBeanBoundToDefinition(clazz
.toString());
this.poolServices.put(scopeName, pool);
result = this.obtainInstance(pool, poolingConfig,
@@ -174,7 +173,7 @@
"The instance need to be returned must not be null !");
if (ReflectUtils.isCast(ReturnScopeName.class, instance)) {
String scopeName = ((ReturnScopeName) instance).returnsScopeName();
- PoolType pool = this.poolServices.get(scopeName);
+ Pool pool = this.poolServices.get(scopeName);
if (pool == null) {
if (log.isInfoEnabled()) {
log
@@ -206,6 +205,35 @@
}
return result;
}
+
+ /**
+ * Returns the pool service according to given object instance.
+ *
+ * @param instance
+ * the given instance
+ */
+ public Pool getPool(Object instance) {
+
+ Pool result = null;
+ Assertor.notNull(instance,
+ "The instance need to be returned must not be null !");
+ if (ReflectUtils.isCast(ReturnScopeName.class, instance)) {
+ String scopeName = ((ReturnScopeName) instance).returnsScopeName();
+ result = this.poolServices.get(scopeName);
+ }
+ else {
+ if (log.isErrorEnabled()) {
+ log.error("The instance bean was not created by this pool !!");
+ }
+ }
+ if (result == null) {
+ if (log.isErrorEnabled()) {
+ log.error("The instance bean was not created by this pool !!",
+ new PoolOperationException());
+ }
+ }
+ return result;
+ }
/**
* Obtain instance.
@@ -218,7 +246,7 @@
* the target class
* @return the object
*/
- private Object obtainInstance(PoolType pool, Pooling poolingConfig,
+ private Object obtainInstance(Pool pool, Pooling poolingConfig,
Class<?> targetClass) {
Object result = null;
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/support/PoolInvocationMethodInterceptor.java
Wed Jun 24 01:53:41 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/support/PoolInvocationMethodInterceptor.java
Sun Aug 2 17:54:16 2009
@@ -22,7 +22,7 @@
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
-import org.jgentleframework.services.objectpooling.PoolType;
+import org.jgentleframework.services.objectpooling.Pool;
/**
* The Class PoolInvocationMethodInterceptor.
@@ -33,7 +33,7 @@
*/
public class PoolInvocationMethodInterceptor implements MethodInterceptor {
/** The pool. */
- PoolType pool = null;
+ Pool pool = null;
/**
* Instantiates a new pool invocation method interceptor.
@@ -41,7 +41,7 @@
* @param pool
* the pool
*/
- public PoolInvocationMethodInterceptor(PoolType pool) {
+ public PoolInvocationMethodInterceptor(Pool pool) {
this.pool = pool;
}