Revision: 77
Author: Skydunkpro
Date: Wed Jul 29 17:21:08 2009
Log: completed CommonPool, optimize code and provide scope name accessing
ability to JGentle bean.
http://code.google.com/p/jgentle/source/detail?r=77
Added:
/trunk/JGentleProject/src/org/jgentleframework/core/interceptor/ReturnScopeName.java
/trunk/JGentleProject/src/org/jgentleframework/core/interceptor/ReturnScopeNameMethodInterceptor.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/PoolOperationException.java
Deleted:
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/PoolInstanceOperationException.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/support/ObjectPoolService.java
Modified:
/trunk/JGentleProject/src/org/jgentleframework/configure/enums/Scope.java
/trunk/JGentleProject/src/org/jgentleframework/configure/objectmeta/Binder.java
/trunk/JGentleProject/src/org/jgentleframework/context/AbstractInitLoading.java
/trunk/JGentleProject/src/org/jgentleframework/context/injecting/AbstractBeanFactory.java
/trunk/JGentleProject/src/org/jgentleframework/context/injecting/IAbstractBeanFactory.java
/trunk/JGentleProject/src/org/jgentleframework/context/injecting/autodetect/AbstractDetector.java
/trunk/JGentleProject/src/org/jgentleframework/context/injecting/autodetect/AutoLoadingDefinitionDetector.java
/trunk/JGentleProject/src/org/jgentleframework/context/injecting/autodetect/ExtensionPointsDetector.java
/trunk/JGentleProject/src/org/jgentleframework/context/support/Selector.java
/trunk/JGentleProject/src/org/jgentleframework/context/support/SelectorImpl.java
/trunk/JGentleProject/src/org/jgentleframework/core/factory/support/AbstractProcesserChecker.java
/trunk/JGentleProject/src/org/jgentleframework/core/factory/support/CoreProcessorImpl.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/AbstractBaseController.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/AbstractBasePooling.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/CommonPool.java
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/context/PoolScope.java
=======================================
--- /dev/null
+++
/trunk/JGentleProject/src/org/jgentleframework/core/interceptor/ReturnScopeName.java
Wed Jul 29 17:21:08 2009
@@ -0,0 +1,32 @@
+/*
+ * 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.core.interceptor;
+
+/**
+ * The Interface ReturnScopeName.
+ *
+ * @author Quoc Chung - mailto: <a
+ * href="mailto:
skydu...@yahoo.com">
skydu...@yahoo.com</a>
+ * @date Jul 30, 2009
+ */
+public interface ReturnScopeName {
+ /**
+ * Returns scope name of current bean instance.
+ */
+ String returnsScopeName();
+}
=======================================
--- /dev/null
+++
/trunk/JGentleProject/src/org/jgentleframework/core/interceptor/ReturnScopeNameMethodInterceptor.java
Wed Jul 29 17:21:08 2009
@@ -0,0 +1,59 @@
+/*
+ * 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.core.interceptor;
+
+import java.lang.reflect.Method;
+
+import net.sf.cglib.proxy.MethodProxy;
+
+/**
+ * The Class ReturnScopeNameMethodInterceptor.
+ *
+ * @author Quoc Chung - mailto: <a
+ * href="mailto:
skydu...@yahoo.com">
skydu...@yahoo.com</a>
+ * @date Jul 30, 2009
+ */
+public class ReturnScopeNameMethodInterceptor implements
+ net.sf.cglib.proxy.MethodInterceptor {
+ /** The scope name. */
+ String scopeName = null;
+
+ /**
+ * Instantiates a new return scope name method interceptor.
+ *
+ * @param scopeName
+ * the scope name
+ */
+ public ReturnScopeNameMethodInterceptor(String scopeName) {
+
+ this.scopeName = scopeName;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.sf.cglib.proxy.MethodInterceptor#intercept(java.lang.Object,
+ * java.lang.reflect.Method, java.lang.Object[],
+ * net.sf.cglib.proxy.MethodProxy)
+ */
+ @Override
+ public Object intercept(Object arg0, Method arg1, Object[] arg2,
+ MethodProxy arg3) throws Throwable {
+
+ return scopeName;
+ }
+}
=======================================
--- /dev/null
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/PoolOperationException.java
Wed Jul 29 17:21:08 2009
@@ -0,0 +1,77 @@
+/*
+ * 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 org.jgentleframework.core.JGentleRuntimeException;
+import org.jgentleframework.services.ServiceRunningException;
+
+/**
+ * The Class PoolOperationException.
+ *
+ * @author Quoc Chung - mailto: <a
+ * href="mailto:
skydu...@yahoo.com">
skydu...@yahoo.com</a>
+ * @date Jun 22, 2009
+ * @see JGentleRuntimeException
+ */
+public class PoolOperationException extends ServiceRunningException {
+ /** The Constant serialVersionUID. */
+ private static final long serialVersionUID = -6864730311259949370L;
+
+ /**
+ * Instantiates a new pool instance operation exception.
+ */
+ public PoolOperationException() {
+
+ super();
+ }
+
+ /**
+ * The Constructor.
+ *
+ * @param strEx
+ * the str ex
+ */
+ public PoolOperationException(String strEx) {
+
+ super(strEx);
+ }
+
+ /**
+ * The Constructor.
+ *
+ * @param message
+ * the message
+ * @param cause
+ * the cause
+ */
+ public PoolOperationException(String message, Throwable cause) {
+
+ super(message, cause);
+ }
+
+ /**
+ * The Constructor.
+ *
+ * @param cause
+ * the cause
+ */
+ public PoolOperationException(Throwable cause) {
+
+ super(cause);
+ }
+}
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/PoolInstanceOperationException.java
Wed Jun 24 03:14:27 2009
+++ /dev/null
@@ -1,77 +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 org.jgentleframework.core.JGentleRuntimeException;
-import org.jgentleframework.services.ServiceRunningException;
-
-/**
- * The Class PoolInstanceOperationException.
- *
- * @author Quoc Chung - mailto: <a
- * href="mailto:
skydu...@yahoo.com">
skydu...@yahoo.com</a>
- * @date Jun 22, 2009
- * @see JGentleRuntimeException
- */
-public class PoolInstanceOperationException extends
ServiceRunningException {
- /** The Constant serialVersionUID. */
- private static final long serialVersionUID = -6864730311259949370L;
-
- /**
- * Instantiates a new pool instance operation exception.
- */
- public PoolInstanceOperationException() {
-
- super();
- }
-
- /**
- * The Constructor.
- *
- * @param strEx
- * the str ex
- */
- public PoolInstanceOperationException(String strEx) {
-
- super(strEx);
- }
-
- /**
- * The Constructor.
- *
- * @param message
- * the message
- * @param cause
- * the cause
- */
- public PoolInstanceOperationException(String message, Throwable cause) {
-
- super(message, cause);
- }
-
- /**
- * The Constructor.
- *
- * @param cause
- * the cause
- */
- public PoolInstanceOperationException(Throwable cause) {
-
- super(cause);
- }
-}
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/support/ObjectPoolService.java
Wed Jun 24 01:53:41 2009
+++ /dev/null
@@ -1,38 +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.support;
-
-import org.jgentleframework.configure.Configurable;
-
-/**
- * The Class ObjectPoolService.
- *
- * @author Quoc Chung - mailto: <a
- * href="mailto:
skydu...@yahoo.com">
skydu...@yahoo.com</a>
- * @date Jun 22, 2009
- */
-public abstract class ObjectPoolService implements Configurable {
- /*
- * (non-Javadoc)
- * @see org.jgentleframework.configure.Configurable#configure()
- */
- @Override
- public void configure() {
-
- }
-}
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/configure/enums/Scope.java
Tue Jul 28 06:32:23 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/configure/enums/Scope.java
Wed Jul 29 17:21:08 2009
@@ -162,12 +162,12 @@
CoreInstantiationSelector coreSelector = null;
String referenceName = null;
if (selector instanceof CoreInstantiationSelectorImpl) {
+ coreSelector = (CoreInstantiationSelector) selector;
Pair<Class<?>[], Object[]> pairCons = DefinitionUtils
.findArgsOfDefaultConstructor(selector
.getDefinition(), provider);
Class<?>[] argTypes = pairCons.getKeyPair();
Object[] args = pairCons.getValuePair();
- coreSelector = (CoreInstantiationSelector) selector;
coreSelector.setArgTypes(argTypes);
coreSelector.setArgs(args);
referenceName = coreSelector.getReferenceName();
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/configure/objectmeta/Binder.java
Sun Jun 28 00:49:21 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/configure/objectmeta/Binder.java
Wed Jul 29 17:21:08 2009
@@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.jgentleframework.configure.AbstractConfig;
@@ -193,7 +194,7 @@
*/
public void flush() {
- ArrayList<Map<String, Object>> OLArray = new ArrayList<Map<String,
Object>>();
+ List<Map<String, Object>> OLArray = new ArrayList<Map<String, Object>>();
OLArray.add(this.getOptionsList());
AbstractInitLoading.loading(this.provider, OLArray);
clearAllBinding();
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/context/AbstractInitLoading.java
Thu Jul 23 18:03:29 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/context/AbstractInitLoading.java
Wed Jul 29 17:21:08 2009
@@ -65,14 +65,14 @@
: null);
// query option list
List<DefinitionPostProcessor> dppList = new
LinkedList<DefinitionPostProcessor>();
- HashMap<Class, AnnotationBeanProcessor> abpHash = new HashMap<Class,
AnnotationBeanProcessor>();
+ Map<Class, AnnotationBeanProcessor> abpHash = new HashMap<Class,
AnnotationBeanProcessor>();
List<ObjectAttach<?>> oaList = new LinkedList<ObjectAttach<?>>();
List<Class<?>> beanClassList = new LinkedList<Class<?>>();
List<ObjectBindingConstant> obcList = new
LinkedList<ObjectBindingConstant>();
List<ObjectConstant> ocList = new LinkedList<ObjectConstant>();
for (Map<String, Object> optionsList : OLArray) {
/***************/
- List<DefinitionPostProcessor> dpp = (List<DefinitionPostProcessor>)
optionsList
+ List<DefinitionPostProcessor> dpp = (List<DefinitionPostProcessor>)
optionsList
.get(AbstractConfig.DEFINITION_POST_PROCESSOR);
if (dpp != null)
dppList.addAll(dpp);
@@ -97,7 +97,7 @@
if (obc != null)
obcList.addAll(obc);
/***************/
- List<ObjectConstant> oc = (List<ObjectConstant>) optionsList
+ List<ObjectConstant> oc = (List<ObjectConstant>) optionsList
.get(AbstractConfig.OBJECT_CONSTANT_LIST);
if (oc != null)
ocList.addAll(oc);
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/context/injecting/AbstractBeanFactory.java
Sun Jul 26 11:58:11 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/context/injecting/AbstractBeanFactory.java
Wed Jul 29 17:21:08 2009
@@ -360,7 +360,8 @@
coreSelector.setCachingList(cachingList);
// If not Singleton scope
try {
- if (scope != null && !scope.equals(Scope.SINGLETON)) {
+ if (scope != null && !scope.equals(Scope.SINGLETON)
+ && !isCustomizedScope(scope)) {
result = returnsCachingResult(coreSelector);
if (result != AbstractBeanCacher.NULL_SHAREDOBJECT) {
return result;
@@ -425,6 +426,8 @@
}
scopeName = Utils.createScopeName(type, targetClass, definition,
mappingName);
+ // setup scopeName to selector
+ selector.setScopeName(scopeName);
// creates scope info, default is SINGLETON
synchronized (scopeList) {
if (!scopeList.containsKey(scopeName)) {
@@ -594,6 +597,25 @@
return false;
}
}
+
+ /*
+ * (non-Javadoc)
+ * @see
+ *
org.jgentleframework.context.injecting.IAbstractBeanFactory#isCustomizedScope
+ * (org.jgentleframework.context.injecting.scope.ScopeInstance)
+ */
+ @Override
+ public boolean isCustomizedScope(ScopeInstance scope) {
+
+ boolean result = true;
+ for (ScopeInstance scopeObj : Scope.class.getEnumConstants()) {
+ if (scopeObj == scope) {
+ result = false;
+ break;
+ }
+ }
+ return result;
+ }
/*
* (non-Javadoc)
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/context/injecting/IAbstractBeanFactory.java
Thu Jul 23 01:43:47 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/context/injecting/IAbstractBeanFactory.java
Wed Jul 29 17:21:08 2009
@@ -18,6 +18,7 @@
package org.jgentleframework.context.injecting;
import org.jgentleframework.context.injecting.scope.ScopeController;
+import org.jgentleframework.context.injecting.scope.ScopeInstance;
import org.jgentleframework.context.services.ServiceHandler;
import org.jgentleframework.core.handling.DefinitionManager;
import org.jgentleframework.core.reflection.metadata.Definition;
@@ -157,6 +158,14 @@
*/
public boolean isSingleton(String ID);
+ /**
+ * Returns <code>true</code> if the given scope is a customized scope.
+ *
+ * @param scope
+ * the given scope
+ */
+ public boolean isCustomizedScope(ScopeInstance scope);
+
/**
* Returns the object bean corresponding to represented String.
*
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/context/injecting/autodetect/AbstractDetector.java
Fri May 15 05:16:41 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/context/injecting/autodetect/AbstractDetector.java
Wed Jul 29 17:21:08 2009
@@ -21,6 +21,9 @@
import java.util.Map;
import org.jgentleframework.context.injecting.Provider;
+import org.jgentleframework.context.injecting.scope.ScopeController;
+import org.jgentleframework.context.services.ServiceHandler;
+import org.jgentleframework.core.handling.DefinitionManager;
/**
* This abstract class represents the detector in the chain.
@@ -32,12 +35,20 @@
* @see FirstDetector
*/
public abstract class AbstractDetector implements Detector {
- protected Provider provider = null;
-
- /**
- * The next detector of this detector in the chain.
- */
- Detector detectModule = null;
+ /** The provider. */
+ protected Provider provider = null;
+
+ /** The definition manager. */
+ DefinitionManager definitionManager = null;
+
+ /** The service handler. */
+ ServiceHandler serviceHandler = null;
+
+ /** The scope controller. */
+ ScopeController scopeController = null;
+
+ /** The next detector of this detector in the chain. */
+ Detector detectModule = null;
/**
* The Constructor.
@@ -48,6 +59,9 @@
public AbstractDetector(Provider provider) {
this.provider = provider;
+ definitionManager = this.provider.getDefinitionManager();
+ this.serviceHandler = this.provider.getServiceHandler();
+ this.scopeController = this.provider.getScopeController();
}
/*
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/context/injecting/autodetect/AutoLoadingDefinitionDetector.java
Thu Jul 23 05:38:37 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/context/injecting/autodetect/AutoLoadingDefinitionDetector.java
Wed Jul 29 17:21:08 2009
@@ -73,11 +73,11 @@
/*
* Lấy ra danh sách các đối tượng cất trữ thông tin cấu hình.
*/
- List<ObjectAttach<?>> othList = (List<ObjectAttach<?>>) optionsList
+ List<ObjectAttach<?>> othList = (List<ObjectAttach<?>>) optionsList
.get(AbstractConfig.OBJECT_ATTACH_LIST);
- List<ObjectConstant> ocstList = (List<ObjectConstant>) optionsList
+ List<ObjectConstant> ocstList = (List<ObjectConstant>) optionsList
.get(AbstractConfig.OBJECT_CONSTANT_LIST);
- List<Class<?>> bclist = (List<Class<?>>) optionsList
+ List<Class<?>> bclist = (List<Class<?>>) optionsList
.get(AbstractConfig.BEAN_CLASS_LIST);
List<ObjectBindingConstant> obcList = (List<ObjectBindingConstant>)
optionsList
.get(AbstractConfig.OBJECT_BINDING_CONSTANT_LIST);
@@ -99,7 +99,6 @@
}
}
// Khởi nạp diễn dịch thông tin Definition
- Provider provider = (Provider) this.provider;
DefinitionManager defManager = provider.getDefinitionManager();
synchronized (defManager) {
for (Class<?> clazz : list) {
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/context/injecting/autodetect/ExtensionPointsDetector.java
Thu Jul 23 18:03:29 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/context/injecting/autodetect/ExtensionPointsDetector.java
Wed Jul 29 17:21:08 2009
@@ -75,7 +75,7 @@
*/
private String getIDFromBeanClass(Class<?> clazz) {
- Definition def = provider.getDefinitionManager().getDefinition(clazz);
+ Definition def = definitionManager.getDefinition(clazz);
String ID = "";
if (def.isAnnotationPresent(Bean.class)) {
String value = def.getAnnotation(Bean.class).value();
@@ -98,8 +98,8 @@
// Detects BeanPostInstantiation
if (BeanPostInstantiation.class.isAssignableFrom(clazz)) {
String ID = getIDFromBeanClass(clazz);
- Domain domain = this.provider.getServiceHandler().getDomain(
- BeanServices.DEFAULT_DOMAIN);
+ Domain domain = this.serviceHandler
+ .getDomain(BeanServices.DEFAULT_DOMAIN);
BeanPostInstantiationSupportInterface bcp = domain
.getServiceInstance(BeanCreationProcessor.class);
bcp.addBeanPostInstantiation(REF.ref(ID));
@@ -108,14 +108,14 @@
else if (DefinitionPostProcessor.class.isAssignableFrom(clazz)) {
DefinitionPostProcessor dpp = (DefinitionPostProcessor) provider
.getBeanBoundToDefinition(getIDFromBeanClass(clazz));
- provider.getDefinitionManager().addDefinitionPostProcessor(dpp);
+ definitionManager.addDefinitionPostProcessor(dpp);
}
// Detects AnnotationBeanProcessor
else if (AnnotationBeanProcessor.class.isAssignableFrom(clazz)) {
AnnotationBeanProcessor<?> abp = (AnnotationBeanProcessor<?>) provider
.getBeanBoundToDefinition(getIDFromBeanClass(clazz));
try {
- provider.getDefinitionManager().addAnnotationBeanProcessor(abp);
+ definitionManager.addAnnotationBeanProcessor(abp);
}
catch (ClassNotFoundException e) {
throw new AutoDetectException(e.getMessage());
@@ -128,8 +128,7 @@
"Does not support enum type to mapping class.");
}
else {
- Definition def = provider.getDefinitionManager().getDefinition(
- clazz);
+ Definition def = definitionManager.getDefinition(clazz);
String ID = getIDFromBeanClass(clazz);
if (def.getAnnotation(Bean.class).scope().equals(
Scope.SINGLETON)) {
@@ -140,8 +139,8 @@
}
ScopeImplementation scopeInstance = (ScopeImplementation) provider
.getBeanBoundToDefinition(ID);
- synchronized (provider.getScopeController()) {
- provider.getScopeController().addScope(scopeInstance);
+ synchronized (scopeController) {
+ scopeController.addScope(scopeInstance);
}
}
}
@@ -159,8 +158,8 @@
// Detects BeanPostInstantiation
if (BeanPostInstantiation.class.isAssignableFrom(clazz)) {
String ID = obc.getID();
- Domain domain = this.provider.getServiceHandler().getDomain(
- BeanServices.DEFAULT_DOMAIN);
+ Domain domain = serviceHandler
+ .getDomain(BeanServices.DEFAULT_DOMAIN);
BeanPostInstantiationSupportInterface bcp = domain
.getServiceInstance(BeanCreationProcessor.class);
bcp.addBeanPostInstantiation(REF.ref(ID));
@@ -169,14 +168,14 @@
else if (DefinitionPostProcessor.class.isAssignableFrom(clazz)) {
DefinitionPostProcessor dpp = (DefinitionPostProcessor) provider
.getBeanBoundToDefinition(obc.getID());
- provider.getDefinitionManager().addDefinitionPostProcessor(dpp);
+ definitionManager.addDefinitionPostProcessor(dpp);
}
// Detects AnnotationBeanProcessor
else if (AnnotationBeanProcessor.class.isAssignableFrom(clazz)) {
AnnotationBeanProcessor<?> abp = (AnnotationBeanProcessor<?>) provider
.getBeanBoundToDefinition(obc.getID());
try {
- provider.getDefinitionManager().addAnnotationBeanProcessor(abp);
+ definitionManager.addAnnotationBeanProcessor(abp);
}
catch (ClassNotFoundException e) {
throw new AutoDetectException(e.getMessage());
@@ -191,10 +190,9 @@
}
// Nếu class là enum
if (clazz.isEnum()) {
- synchronized (provider.getScopeController()) {
+ synchronized (scopeController) {
for (Object scope : clazz.getEnumConstants()) {
- provider.getScopeController().addScope(
- (ScopeImplementation) scope);
+ scopeController.addScope((ScopeImplementation) scope);
}
}
}
@@ -202,8 +200,8 @@
else {
ScopeImplementation scopeInstance = (ScopeImplementation) provider
.getBeanBoundToDefinition(obc.getID());
- synchronized (provider.getScopeController()) {
- provider.getScopeController().addScope(scopeInstance);
+ synchronized (scopeController) {
+ scopeController.addScope(scopeInstance);
}
}
}
@@ -223,8 +221,8 @@
* Detects BeanPostInstantiation
*/
if (BeanPostInstantiation.class.isAssignableFrom(entry.getValue())) {
- Domain domain = this.provider.getServiceHandler().getDomain(
- BeanServices.DEFAULT_DOMAIN);
+ Domain domain = serviceHandler
+ .getDomain(BeanServices.DEFAULT_DOMAIN);
BeanPostInstantiationSupportInterface bcp = domain
.getServiceInstance(BeanCreationProcessor.class);
if (oa.getName() != null && !oa.getName().isEmpty()
@@ -245,7 +243,7 @@
.getBeanBoundToMapping(oa.getName())
: (DefinitionPostProcessor) provider.getBean(entry
.getKey());
- provider.getDefinitionManager().addDefinitionPostProcessor(dpp);
+ definitionManager.addDefinitionPostProcessor(dpp);
}
/*
* Detects AnnotationBeanProcessor
@@ -258,8 +256,7 @@
: (AnnotationBeanProcessor<?>) provider.getBean(entry
.getKey());
try {
- provider.getDefinitionManager().addAnnotationBeanProcessor(
- abp);
+ definitionManager.addAnnotationBeanProcessor(abp);
}
catch (ClassNotFoundException e) {
throw new AutoDetectException(e.getMessage());
@@ -279,11 +276,11 @@
}
// Nếu class là enum
if (entry.getValue().isEnum()) {
- synchronized (provider.getScopeController()) {
+ synchronized (scopeController) {
for (Object objScope : entry.getValue()
.getEnumConstants()) {
- provider.getScopeController().addScope(
- (ScopeImplementation) objScope);
+ scopeController
+ .addScope((ScopeImplementation) objScope);
}
}
}
@@ -294,8 +291,8 @@
.getBeanBoundToMapping(oa.getName())
: (ScopeImplementation) provider.getBean(entry
.getKey());
- synchronized (provider.getScopeController()) {
- provider.getScopeController().addScope(scopeInstance);
+ synchronized (scopeController) {
+ scopeController.addScope(scopeInstance);
}
}
}
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/context/support/Selector.java
Fri May 15 05:16:41 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/context/support/Selector.java
Wed Jul 29 17:21:08 2009
@@ -58,4 +58,19 @@
* the new target class
*/
public void setTargetClass(Class<?> targetClass);
-}
+
+ /**
+ * Sets the scope name.
+ *
+ * @param scopeName
+ * the new scope name
+ */
+ public void setScopeName(String scopeName);
+
+ /**
+ * Gets the scope name.
+ *
+ * @return the scope name
+ */
+ public String getScopeName();
+}
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/context/support/SelectorImpl.java
Fri May 15 05:16:41 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/context/support/SelectorImpl.java
Wed Jul 29 17:21:08 2009
@@ -30,9 +30,12 @@
public class SelectorImpl implements Selector {
/** The definition. */
protected Definition definition = null;
+
/** The target class. */
protected Class<?> targetClass = null;
+ protected String scopeName = null;
+
/**
* Instantiates a new selector impl.
*/
@@ -48,15 +51,16 @@
* @param targetClass
* the target class
*/
- public SelectorImpl(Definition definition, Class<?> targetClass) {
+ public SelectorImpl(Definition definition, Class<?> targetClass,
+ String scopeName) {
this.definition = definition;
this.targetClass = targetClass;
+ this.scopeName = scopeName;
}
/*
* (non-Javadoc)
- *
* @see org.jgentleframework.context.support.Selector#getDefinition()
*/
@Override
@@ -67,7 +71,6 @@
/*
* (non-Javadoc)
- *
* @see org.jgentleframework.context.support.Selector#getTargetClass()
*/
@Override
@@ -78,8 +81,8 @@
/*
* (non-Javadoc)
- *
- * @see
org.jgentleframework.context.support.Selector#setDefinition(org.jgentleframework.core.reflection.metadata.Definition)
+ * @seeorg.jgentleframework.context.support.Selector#setDefinition(org.
+ * jgentleframework.core.reflection.metadata.Definition)
*/
@Override
public void setDefinition(Definition definition) {
@@ -89,12 +92,35 @@
/*
* (non-Javadoc)
- *
- * @see
org.jgentleframework.context.support.Selector#setTargetClass(java.lang.Class)
+ * @see
+ * org.jgentleframework.context.support.Selector#setTargetClass(java.lang
+ * .Class)
*/
@Override
public void setTargetClass(Class<?> targetClass) {
this.targetClass = targetClass;
}
-}
+
+ /*
+ * (non-Javadoc)
+ * @see org.jgentleframework.context.support.Selector#getScopeName()
+ */
+ @Override
+ public String getScopeName() {
+
+ return this.scopeName;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.jgentleframework.context.support.Selector#setScopeName(java.lang.
+ * String)
+ */
+ @Override
+ public void setScopeName(String scopeName) {
+
+ this.scopeName = scopeName;
+ }
+}
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/core/factory/support/AbstractProcesserChecker.java
Thu Jul 23 01:43:47 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/core/factory/support/AbstractProcesserChecker.java
Wed Jul 29 17:21:08 2009
@@ -142,7 +142,8 @@
* @return the cached constructor
*/
abstract protected CachedConstructor createConstructionProxy(
- CoreInstantiationSelector selector, MetaDefObject mdo);
+ CoreInstantiationSelector selector, MetaDefObject mdo)
+ throws SecurityException, NoSuchMethodException;
/**
* Creates the construction proxy.
@@ -160,7 +161,8 @@
abstract protected CachedConstructor createConstructionProxy(
CoreInstantiationSelector selector, Class<?> interfaze,
net.sf.cglib.proxy.MethodInterceptor interceptor,
- final List<Method> methodList, MetaDefObject mdo);
+ final List<Method> methodList, MetaDefObject mdo)
+ throws SecurityException, NoSuchMethodException;
/**
* Creates the pure bean instance.
@@ -213,8 +215,8 @@
inoutInterceptor);
final List<Method> methodList = new ArrayList<Method>();
Enhancer.getMethods(targetClass, null, methodList);
- cons = createConstructionProxy(selector, null, intercept,
- methodList, metaObj);
+ cons = createConstructionProxy(selector, selector.getType(),
+ intercept, methodList, metaObj);
}
else {
cons = createConstructionProxy(selector, metaObj);
@@ -378,9 +380,9 @@
.getReferenceName());
Map<String, ScopeInstance> scopeList = provider.getObjectBeanFactory()
.getScopeList();
- Scope scope = null;
+ ScopeInstance scope = null;
synchronized (scopeList) {
- scope = (Scope) scopeList.get(scopeName);
+ scope = scopeList.get(scopeName);
}
if (scope != null && scope.equals(Scope.SINGLETON)) {
synchronized (provider.getObjectBeanFactory().getMapDirectList()) {
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/core/factory/support/CoreProcessorImpl.java
Tue Jul 21 21:08:46 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/core/factory/support/CoreProcessorImpl.java
Wed Jul 29 17:21:08 2009
@@ -50,6 +50,8 @@
import org.jgentleframework.core.intercept.MethodInterceptorStackCallback;
import org.jgentleframework.core.intercept.support.Matcher;
import org.jgentleframework.core.interceptor.InterceptorUtils;
+import org.jgentleframework.core.interceptor.ReturnScopeName;
+import
org.jgentleframework.core.interceptor.ReturnScopeNameMethodInterceptor;
import org.jgentleframework.core.provider.ServiceClass;
import org.jgentleframework.core.reflection.metadata.Definition;
import org.jgentleframework.utils.Assertor;
@@ -232,9 +234,9 @@
executesInOut(targetClass, definition, provider,
runtimeLoading, methodAspectList, invocationINOUT);
// Creates callbacks.
- Callback[] callbacks = new Callback[methodList.size()];
+ Callback[] callbacks = new Callback[methodList.size() + 1];
Class<? extends Callback>[] callbackTypes = new Class[methodList
- .size()];
+ .size() + 1];
for (int i = 0; i < methodList.size(); i++) {
MethodAspectPair pair = methodAspectList.get(methodList
.get(i));
@@ -252,20 +254,31 @@
callbackTypes[i] = net.sf.cglib.proxy.MethodInterceptor.class;
}
}
+ callbacks[methodList.size()] = new ReturnScopeNameMethodInterceptor(
+ selector.getScopeName());
+ callbackTypes[methodList.size()] =
net.sf.cglib.proxy.MethodInterceptor.class;
// Nếu không tìm thấy bất kì chỉ định khởi tạo interceptor nào
// ==> tự động return null.
if (methodAspectList.size() == 0 && (targetClass.isInterface())) {
return NullClass.class;
}
// Create the proxied class.
+ final Method returnScopeNameMethod = ReturnScopeName.class
+ .getDeclaredMethod("returnsScopeName");
Enhancer enhancer = new Enhancer();
if (targetClass.isAnnotation() || targetClass.isInterface())
- enhancer.setInterfaces(new Class<?>[] { targetClass });
- else
+ enhancer.setInterfaces(new Class<?>[] { targetClass,
+ ReturnScopeName.class });
+ else {
enhancer.setSuperclass(targetClass);
+ enhancer
+ .setInterfaces(new Class<?>[] { ReturnScopeName.class });
+ }
enhancer.setCallbackFilter(new CallbackFilter() {
public int accept(Method method) {
+ if (method.equals(returnScopeNameMethod))
+ return methodList.size();
return methodList.indexOf(method);
}
});
@@ -305,7 +318,8 @@
@SuppressWarnings("unchecked")
@Override
protected CachedConstructor createConstructionProxy(
- CoreInstantiationSelector selector, MetaDefObject mdo) {
+ CoreInstantiationSelector selector, MetaDefObject mdo)
+ throws SecurityException, NoSuchMethodException {
Assertor.notNull(selector, "The selector ["
+ CoreInstantiationSelector.class.toString()
@@ -313,12 +327,19 @@
// Create
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(selector.getTargetClass());
- Callback[] callbacks = new Callback[] { NoOp.INSTANCE };
- Class<? extends Callback>[] callbackTypes = new Class[] { NoOp.class };
+ enhancer.setInterfaces(new Class<?>[] { ReturnScopeName.class });
+ Callback[] callbacks = new Callback[] { NoOp.INSTANCE,
+ new ReturnScopeNameMethodInterceptor(selector.getScopeName()) };
+ final Method returnScopeNameMethod = ReturnScopeName.class
+ .getDeclaredMethod("returnsScopeName");
+ Class<? extends Callback>[] callbackTypes = new Class[] { NoOp.class,
+ net.sf.cglib.proxy.MethodInterceptor.class };
enhancer.setCallbackFilter(new CallbackFilter() {
@Override
public int accept(Method method) {
+ if (method.equals(returnScopeNameMethod))
+ return 1;
return 0;
}
});
@@ -346,7 +367,8 @@
protected CachedConstructor createConstructionProxy(
final CoreInstantiationSelector selector, Class<?> interfaze,
net.sf.cglib.proxy.MethodInterceptor interceptor,
- final List<Method> methodList, MetaDefObject mdo) {
+ final List<Method> methodList, MetaDefObject mdo)
+ throws SecurityException, NoSuchMethodException {
Assertor.notNull(interceptor,
"The given interceptor must not be null !");
@@ -356,12 +378,20 @@
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(selector.getTargetClass());
if (interfaze != null && interfaze.isAnnotation())
- enhancer
- .setInterfaces(new Class<?>[] { interfaze, Annotation.class });
+ enhancer.setInterfaces(new Class<?>[] { interfaze,
+ Annotation.class, ReturnScopeName.class });
else if (interfaze != null && interfaze.isInterface())
- enhancer.setInterfaces(new Class<?>[] { interfaze });
- Callback[] callbacks = new Callback[] { NoOp.INSTANCE, interceptor };
+ enhancer.setInterfaces(new Class<?>[] { interfaze,
+ ReturnScopeName.class });
+ else {
+ enhancer.setInterfaces(new Class<?>[] { ReturnScopeName.class });
+ }
+ final Method returnScopeNameMethod = ReturnScopeName.class
+ .getDeclaredMethod("returnsScopeName");
+ Callback[] callbacks = new Callback[] { NoOp.INSTANCE, interceptor,
+ new ReturnScopeNameMethodInterceptor(selector.getScopeName()) };
Class<? extends Callback>[] callbackTypes = new Class[] { NoOp.class,
+ net.sf.cglib.proxy.MethodInterceptor.class,
net.sf.cglib.proxy.MethodInterceptor.class };
enhancer.setCallbackFilter(new CallbackFilter() {
@Override
@@ -372,6 +402,8 @@
return 1;
else if (selector.getTargetClass().isAnnotation())
return 1;
+ else if (method.equals(returnScopeNameMethod))
+ return 2;
else
return 0;
}
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/AbstractBaseController.java
Wed Jul 15 04:51:31 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/AbstractBaseController.java
Wed Jul 29 17:21:08 2009
@@ -19,6 +19,7 @@
import java.lang.reflect.Method;
import java.util.List;
+import java.util.TooManyListenersException;
import org.jgentleframework.context.beans.Disposable;
import org.jgentleframework.context.beans.Initializing;
@@ -26,6 +27,9 @@
import org.jgentleframework.context.beans.annotation.DisposableMethod;
import org.jgentleframework.context.beans.annotation.InitializingMethod;
import org.jgentleframework.context.injecting.Provider;
+import org.jgentleframework.context.support.CoreInstantiationSelector;
+import org.jgentleframework.context.support.CoreInstantiationSelectorImpl;
+import org.jgentleframework.core.factory.BeanCreationProcessor;
import
org.jgentleframework.services.objectpooling.annotation.CanBePooledMethod;
import
org.jgentleframework.services.objectpooling.annotation.DeactivateMethod;
import
org.jgentleframework.services.objectpooling.annotation.SystemPooling;
@@ -33,7 +37,9 @@
import org.jgentleframework.services.objectpooling.context.CanBePooled;
import org.jgentleframework.services.objectpooling.context.Deactivate;
import org.jgentleframework.services.objectpooling.context.Validate;
+import org.jgentleframework.utils.DefinitionUtils;
import org.jgentleframework.utils.ReflectUtils;
+import org.jgentleframework.utils.data.Pair;
import org.jgentleframework.utils.data.TimestampObjectBean;
/**
@@ -140,12 +146,31 @@
}
// create new object when needed
boolean newlyCreated = false;
- Object obj = null;
+ Object result = null;
TimestampObjectBean<Object> pair = null;
try {
- obj = this.provider.getBean(this.definition);
- if (obj != null) {
- pair = new TimestampObjectBean<Object>(obj);
+ CoreInstantiationSelector coreSelector = null;
+ if (selector instanceof CoreInstantiationSelectorImpl) {
+ coreSelector = (CoreInstantiationSelector) selector;
+ Pair<Class<?>[], Object[]> pairCons = DefinitionUtils
+ .findArgsOfDefaultConstructor(selector.getDefinition(),
+ provider);
+ Class<?>[] argTypes = pairCons.getKeyPair();
+ Object[] args = pairCons.getValuePair();
+ coreSelector.setArgTypes(argTypes);
+ coreSelector.setArgs(args);
+ }
+ try {
+ result = this.provider.getServiceHandler().getService(this,
+ BeanCreationProcessor.class, selector);
+ }
+ catch (TooManyListenersException e) {
+ if (log.isFatalEnabled()) {
+ log.fatal("Could not get service !", e);
+ }
+ }
+ if (result != null) {
+ pair = new TimestampObjectBean<Object>(result);
newlyCreated = true;
}
}
@@ -165,7 +190,7 @@
}
}
// validate the object bean
- validatesObject(obj);
+ validatesObject(result);
return pair != null ? pair.getValue() : null;
}
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/AbstractBasePooling.java
Wed Jun 24 03:14:27 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/AbstractBasePooling.java
Wed Jul 29 17:21:08 2009
@@ -22,6 +22,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jgentleframework.context.beans.Initializing;
+import org.jgentleframework.context.support.Selector;
import org.jgentleframework.core.reflection.metadata.Definition;
import org.jgentleframework.services.objectpooling.annotation.Pooling;
import
org.jgentleframework.services.objectpooling.annotation.SystemPooling;
@@ -93,6 +94,9 @@
/** The definition. */
protected Definition definition = null;
+ /** The selector. */
+ protected Selector selector = null;
+
/** The log. */
protected final Log log = LogFactory
.getLog(getClass());
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/CommonPool.java
Wed Jul 15 04:51:31 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/CommonPool.java
Wed Jul 29 17:21:08 2009
@@ -98,7 +98,7 @@
.poll());
if (pair == null) {
if (this.maxPoolSize < 0
- || this.getNumActive() < this.maxPoolSize) {
+ || this.getNumActive() <= this.maxPoolSize) {
return createsBean();
}
else {
=======================================
---
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/context/PoolScope.java
Wed Jul 15 04:51:31 2009
+++
/trunk/JGentleProject/src/org/jgentleframework/services/objectpooling/context/PoolScope.java
Wed Jul 29 17:21:08 2009
@@ -38,10 +38,13 @@
import org.jgentleframework.context.injecting.scope.ScopeInstance;
import org.jgentleframework.context.support.Selector;
import org.jgentleframework.core.intercept.JGentleNamingPolicy;
+import org.jgentleframework.core.interceptor.ReturnScopeName;
import org.jgentleframework.core.reflection.metadata.Definition;
import org.jgentleframework.services.objectpooling.PoolType;
import org.jgentleframework.services.objectpooling.annotation.Pooling;
import
org.jgentleframework.services.objectpooling.support.PoolInvocationMethodInterceptor;
+import org.jgentleframework.utils.Assertor;
+import org.jgentleframework.utils.ReflectUtils;
/**
* This enum contains some constants representing supported pooling scopes
of
@@ -135,9 +138,9 @@
}
if (clazz != null) {
Binder binder = new Binder(provider);
- binder.bind("config", "definition").to(poolingConfig,
- definition).in(clazz).id(clazz.toString()).scope(
- Scope.SINGLETON);
+ binder.bind("config", "definition", "selector").to(
+ poolingConfig, definition, selector).in(clazz).id(
+ clazz.toString()).scope(Scope.SINGLETON);
binder.flush();
pool = (PoolType) provider.getBeanBoundToDefinition(clazz
.toString());
@@ -145,10 +148,61 @@
result = this.obtainInstance(pool, poolingConfig,
targetClass);
}
+ else {
+ if (log.isErrorEnabled()) {
+ log.error("The specified scope is invalid !",
+ new IllegalStateException());
+ }
+ }
}
}
return result;
}
+
+ /**
+ * Return instance to the pool.
+ *
+ * @param instance
+ * the instance
+ * @return true, if successful
+ */
+ public boolean returnInstance(Object instance) {
+
+ boolean result = true;
+ Assertor.notNull(instance,
+ "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);
+ if (pool == null) {
+ if (log.isInfoEnabled()) {
+ log
+ .info("The instance bean was not created by this pool !!");
+ }
+ return false;
+ }
+ else {
+ try {
+ pool.returnObject(instance);
+ }
+ catch (Throwable e) {
+ if (log.isErrorEnabled()) {
+ log.error(
+ "Could not return bean instance to the pool !",
+ e);
+ }
+ return false;
+ }
+ }
+ }
+ else {
+ if (log.isInfoEnabled()) {
+
log.info("The instance bean was not created by this pool !!");
+ }
+ return false;
+ }
+ return result;
+ }
/**
* Obtain instance.