This is an automated email from the ASF dual-hosted git repository.
rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 3ad1739 [OWB-1382] specific handling for beanmanager observer
injection (speed boost) from user report
3ad1739 is described below
commit 3ad1739186c37c7b019b7e33a0a99cd6be73d563
Author: Romain Manni-Bucau <[email protected]>
AuthorDate: Thu Mar 25 19:24:20 2021 +0100
[OWB-1382] specific handling for beanmanager observer injection (speed
boost) from user report
---
.../org/apache/webbeans/config/BeansDeployer.java | 2 +-
.../apache/webbeans/config/WebBeansContext.java | 18 ++++++++
.../apache/webbeans/event/ObserverMethodImpl.java | 50 ++++++++++++++--------
3 files changed, 50 insertions(+), 20 deletions(-)
diff --git
a/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
b/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
index 576335f..e29302e 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
@@ -232,7 +232,7 @@ public class BeansDeployer
}
// Register Manager built-in component
-
webBeansContext.getBeanManagerImpl().addInternalBean(webBeansContext.getWebBeansUtil().getManagerBean());
+
webBeansContext.getBeanManagerImpl().addInternalBean(webBeansContext.getBeanManagerBean());
// Register built-in RequestContextController
webBeansContext.getBeanManagerImpl().addInternalBean(webBeansContext.getWebBeansUtil().getRequestContextControllerBean());
webBeansContext.getInterceptorsManager().addCdiInterceptor(webBeansContext.getWebBeansUtil().getRequestContextInterceptorBean());
diff --git
a/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
b/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
index 2504ed0..500fc8c 100644
---
a/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
+++
b/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
@@ -32,6 +32,7 @@ import java.util.logging.Level;
import org.apache.webbeans.annotation.AnnotationManager;
import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.container.InjectableBeanManager;
import org.apache.webbeans.container.SerializableBeanVault;
import org.apache.webbeans.context.creational.CreationalContextFactory;
import org.apache.webbeans.conversation.ConversationManager;
@@ -71,6 +72,9 @@ import org.apache.webbeans.util.ClassUtil;
import org.apache.webbeans.util.WebBeansUtil;
import org.apache.webbeans.xml.DefaultBeanArchiveService;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
/**
* This is the central point to manage the whole CDI container
* for a single application There is one WebBeansContext per BeanManagerImpl.
@@ -103,6 +107,8 @@ public class WebBeansContext
private final InterceptorUtil interceptorUtil = new InterceptorUtil(this);
private final SecurityService securityService;
private final LoaderService loaderService;
+ private final InjectableBeanManager injectableBeanManager;
+ private final Bean<BeanManager> beanManagerBean;
private BeanArchiveService beanArchiveService;
private final InterceptorResolutionService interceptorResolutionService =
new InterceptorResolutionService(this);
private final DeploymentValidationService deploymentValidationService =
new DeploymentValidationService(this);
@@ -172,6 +178,18 @@ public class WebBeansContext
beanManagerImpl.getInjectionResolver().setFastMatching(!"false".equalsIgnoreCase(getOpenWebBeansConfiguration()
.getProperty(OpenWebBeansConfiguration.FAST_MATCHING)));
+ injectableBeanManager = new InjectableBeanManager(beanManagerImpl);
+ beanManagerBean = getWebBeansUtil().getManagerBean();
+ }
+
+ public Bean<BeanManager> getBeanManagerBean()
+ {
+ return beanManagerBean;
+ }
+
+ public InjectableBeanManager getInjectableBeanManager()
+ {
+ return injectableBeanManager;
}
public static WebBeansContext getInstance()
diff --git
a/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
b/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
index 7061714..cae44f4 100644
---
a/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
+++
b/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
@@ -43,12 +43,14 @@ import javax.enterprise.event.TransactionPhase;
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedParameter;
import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.EventContext;
import javax.enterprise.inject.spi.EventMetadata;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.ObserverMethod;
import javax.enterprise.inject.spi.WithAnnotations;
+import org.apache.webbeans.annotation.DefaultLiteral;
import org.apache.webbeans.component.AbstractOwbBean;
import org.apache.webbeans.component.WebBeansType;
import org.apache.webbeans.config.OWBLogConst;
@@ -432,29 +434,39 @@ public class ObserverMethodImpl<T> implements
OwbObserverMethod<T>
for (InjectionPoint injectionPoint: injectionPoints)
{
- Bean<Object> injectedBean =
(Bean<Object>)manager.getInjectionResolver().getInjectionPointBean(injectionPoint);
-
- CreationalContextImpl<Object> creational =
manager.createCreationalContext(injectedBean);
- creational.putInjectionPoint(metadata.getInjectionPoint());
- creational.putInjectionPoint(injectionPoint);
- creational.putEventMetadata(metadata);
- Object instance;
- try
+ ObserverParams param = new ObserverParams();
+ param.isBean = true;
+ if (injectionPoint.getType() == BeanManager.class &&
+
injectionPoint.getQualifiers().contains(DefaultLiteral.INSTANCE))
{
- instance = manager.getReference(injectedBean, null,
creational);
+ param.instance = webBeansContext.getInjectableBeanManager();
+ param.isBean = false; // no need to release
}
- finally
+ else
{
- creational.removeEventMetadata();
- creational.removeInjectionPoint();
- creational.removeInjectionPoint();
+ Bean<Object> injectedBean = (Bean<Object>)
manager.getInjectionResolver().getInjectionPointBean(injectionPoint);
+
+ CreationalContextImpl<Object> creational =
manager.createCreationalContext(injectedBean);
+ creational.putInjectionPoint(metadata.getInjectionPoint());
+ creational.putInjectionPoint(injectionPoint);
+ creational.putEventMetadata(metadata);
+ Object instance;
+ try
+ {
+ instance = manager.getReference(injectedBean, null,
creational);
+ }
+ finally
+ {
+ creational.removeEventMetadata();
+ creational.removeInjectionPoint();
+ creational.removeInjectionPoint();
+ }
+
+ param.creational = creational;
+ param.instance = instance;
+ param.bean = injectedBean;
}
-
- ObserverParams param = new ObserverParams();
- param.isBean = true;
- param.creational = creational;
- param.instance = instance;
- param.bean = injectedBean;
+
list.add(param);
if (list.size() == annotatedObservesParameter.getPosition())