Author: struberg
Date: Mon May 25 19:51:21 2015
New Revision: 1681646
URL: http://svn.apache.org/r1681646
Log:
OWB-1044 only fire @Destroyed and @Initialized if there are any observers for
them.
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=1681646&r1=1681645&r2=1681646&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
Mon May 25 19:51:21 2015
@@ -460,6 +460,17 @@ public class BeanManagerImpl implements
}
/**
+ * Fire @Initialized and @Destroyed events, but only IF any
observers do exist.
+ */
+ public void fireContextLifecyleEvent(Object payload, Annotation
lifecycleQualifier)
+ {
+ if
(notificationManager.hasContextLifecycleObserver(lifecycleQualifier))
+ {
+ fireEvent(payload, lifecycleQualifier);
+ }
+ }
+
+ /**
* Like {@link #fireEvent(Object, java.lang.annotation.Annotation...)} but
intended for
* internal CDI Container lifecycle events. The difference is that those
* events must only be delivered to CDI Extensions and not to normal beans.
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java?rev=1681646&r1=1681645&r2=1681646&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
Mon May 25 19:51:21 2015
@@ -195,7 +195,8 @@ public class ConversationManager
public void destroyConversationContext(ConversationContext ctx)
{
ctx.destroy();
-
webBeansContext.getBeanManagerImpl().fireEvent(getLifecycleEventPayload(ctx),
DestroyedLiteral.INSTANCE_CONVERSATION_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireEvent(
+ getLifecycleEventPayload(ctx),
DestroyedLiteral.INSTANCE_CONVERSATION_SCOPED);
}
public Object getLifecycleEventPayload(ConversationContext ctx)
@@ -208,7 +209,8 @@ public class ConversationManager
if (payLoad == null)
{
- RequestContext requestContext = (RequestContext)
webBeansContext.getContextsService().getCurrentContext(RequestScoped.class);
+ RequestContext requestContext
+ = (RequestContext)
webBeansContext.getContextsService().getCurrentContext(RequestScoped.class);
if (requestContext != null)
{
payLoad = requestContext.getRequestObject();
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java?rev=1681646&r1=1681645&r2=1681646&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
Mon May 25 19:51:21 2015
@@ -303,10 +303,12 @@ public class DefaultContextsService exte
applicationContext = ctx;
- // We do ALSO send the @Initialized(ApplicationScoped.class) at this
location but this is WAY to early for userland apps
+ // We do ALSO send the @Initialized(ApplicationScoped.class) at this
+ // location but this is WAY to early for userland apps
// This also gets sent in the application startup code after
AfterDeploymentValidation got fired.
// see AbstractLifecycle#afterStartApplication
- webBeansContext.getBeanManagerImpl().fireEvent(new Object(),
InitializedLiteral.INSTANCE_APPLICATION_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ new Object(), InitializedLiteral.INSTANCE_APPLICATION_SCOPED);
}
@@ -319,7 +321,8 @@ public class DefaultContextsService exte
if (ctx.getConversation().isTransient())
{
-
webBeansContext.getBeanManagerImpl().fireEvent(conversationManager.getLifecycleEventPayload(ctx),
InitializedLiteral.INSTANCE_CONVERSATION_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ conversationManager.getLifecycleEventPayload(ctx),
InitializedLiteral.INSTANCE_CONVERSATION_SCOPED);
}
}
@@ -331,7 +334,8 @@ public class DefaultContextsService exte
ctx.setActive(true);
requestContext.set(ctx);
- webBeansContext.getBeanManagerImpl().fireEvent(new Object(),
InitializedLiteral.INSTANCE_REQUEST_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ new Object(), InitializedLiteral.INSTANCE_REQUEST_SCOPED);
}
@@ -341,7 +345,8 @@ public class DefaultContextsService exte
ctx.setActive(true);
sessionContext.set(ctx);
- webBeansContext.getBeanManagerImpl().fireEvent(new Object(),
InitializedLiteral.INSTANCE_SESSION_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ new Object(), InitializedLiteral.INSTANCE_SESSION_SCOPED);
}
@@ -352,7 +357,8 @@ public class DefaultContextsService exte
ctx.setActive(true);
singletonContext.set(ctx);
- webBeansContext.getBeanManagerImpl().fireEvent(new Object(),
InitializedLiteral.INSTANCE_SINGLETON_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ new Object(), InitializedLiteral.INSTANCE_SINGLETON_SCOPED);
}
@@ -364,7 +370,8 @@ public class DefaultContextsService exte
// this is needed to get rid of ApplicationScoped beans which are
cached inside the proxies...
WebBeansContext.currentInstance().getBeanManagerImpl().clearCacheProxies();
- webBeansContext.getBeanManagerImpl().fireEvent(new Object(),
DestroyedLiteral.INSTANCE_APPLICATION_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ new Object(), DestroyedLiteral.INSTANCE_APPLICATION_SCOPED);
}
}
@@ -399,7 +406,8 @@ public class DefaultContextsService exte
requestContext.set(null);
requestContext.remove();
- webBeansContext.getBeanManagerImpl().fireEvent(new Object(),
DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ new Object(), DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
}
@@ -412,7 +420,8 @@ public class DefaultContextsService exte
sessionContext.set(null);
sessionContext.remove();
- webBeansContext.getBeanManagerImpl().fireEvent(new Object(),
DestroyedLiteral.INSTANCE_SESSION_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ new Object(), DestroyedLiteral.INSTANCE_SESSION_SCOPED);
}
@@ -425,7 +434,8 @@ public class DefaultContextsService exte
singletonContext.set(null);
singletonContext.remove();
- webBeansContext.getBeanManagerImpl().fireEvent(new Object(),
DestroyedLiteral.INSTANCE_SINGLETON_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ new Object(), DestroyedLiteral.INSTANCE_SINGLETON_SCOPED);
}
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java?rev=1681646&r1=1681645&r2=1681646&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
Mon May 25 19:51:21 2015
@@ -87,7 +87,7 @@ public final class NotificationManager
/**
* Contains information whether certain Initialized and Destroyed events
have observer methods.
*/
- private final ConcurrentMap<Annotation, Boolean> hasLifecycleEventObservers
+ private final ConcurrentMap<Annotation, Boolean>
hasContextLifecycleEventObservers
= new ConcurrentHashMap<Annotation, Boolean>();
/**
@@ -132,7 +132,7 @@ public final class NotificationManager
public void clearCaches()
{
observersByRawType.clear();
- hasLifecycleEventObservers.clear();
+ hasContextLifecycleEventObservers.clear();
}
/**
@@ -140,9 +140,9 @@ public final class NotificationManager
* @param lifecycleEvent e.g. {@link
org.apache.webbeans.annotation.DestroyedLiteral#INSTANCE_REQUEST_SCOPED}
* @return whether the given Initialized or Destroyed event has observer
methods.
*/
- public boolean hasLifecycleObserver(Annotation lifecycleEvent)
+ public boolean hasContextLifecycleObserver(Annotation lifecycleEvent)
{
- Boolean hasObserver = hasLifecycleEventObservers.get(lifecycleEvent);
+ Boolean hasObserver =
hasContextLifecycleEventObservers.get(lifecycleEvent);
if (hasObserver == null)
{
hasObserver = Boolean.FALSE;
@@ -154,7 +154,7 @@ public final class NotificationManager
break;
}
}
- hasLifecycleEventObservers.putIfAbsent(lifecycleEvent,
hasObserver);
+ hasContextLifecycleEventObservers.putIfAbsent(lifecycleEvent,
hasObserver);
}
return hasObserver;
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java?rev=1681646&r1=1681645&r2=1681646&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java
Mon May 25 19:51:21 2015
@@ -58,8 +58,10 @@ public class StandaloneLifeCycle extends
@Override
protected void afterStartApplication(Object startupObject)
{
- // the ApplicationContext is already started, but we fire the event
again as the userland beans are only available now
- webBeansContext.getBeanManagerImpl().fireEvent(new Object(),
InitializedLiteral.INSTANCE_APPLICATION_SCOPED);
+ // the ApplicationContext is already started, but we fire
+ // the event again as the userland beans are only available now
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ new Object(), InitializedLiteral.INSTANCE_APPLICATION_SCOPED);
webBeansContext.getContextsService().startContext(RequestScoped.class,
null);
webBeansContext.getContextsService().startContext(SessionScoped.class,
null);
Modified:
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java?rev=1681646&r1=1681645&r2=1681646&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
(original)
+++
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
Mon May 25 19:51:21 2015
@@ -359,7 +359,8 @@ public class WebContextsService extends
}
}
}
- webBeansContext.getBeanManagerImpl().fireEvent(payload != null ?
payload : new Object(), InitializedLiteral.INSTANCE_REQUEST_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ payload != null ? payload : new Object(),
InitializedLiteral.INSTANCE_REQUEST_SCOPED);
}
protected boolean shouldEagerlyInitializeSession(HttpServletRequest
request)
@@ -404,7 +405,8 @@ public class WebContextsService extends
payload = context.getServletRequest().getSession();
}
- webBeansContext.getBeanManagerImpl().fireEvent(payload != null ?
payload : new Object(), DestroyedLiteral.INSTANCE_SESSION_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ payload != null ? payload : new Object(),
DestroyedLiteral.INSTANCE_SESSION_SCOPED);
}
@@ -423,7 +425,8 @@ public class WebContextsService extends
{
payload = ((ServletRequestEvent) endObject).getServletRequest();
}
- webBeansContext.getBeanManagerImpl().fireEvent(payload != null ?
payload : new Object(), DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ payload != null ? payload : new Object(),
DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
//Clear thread locals
conversationContexts.set(null);
@@ -464,7 +467,8 @@ public class WebContextsService extends
{
currentSessionContext = new SessionContext();
currentSessionContext.setActive(true);
-
webBeansContext.getBeanManagerImpl().fireEvent(session,
InitializedLiteral.INSTANCE_SESSION_SCOPED);
+
webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ session,
InitializedLiteral.INSTANCE_SESSION_SCOPED);
session.setAttribute(OWB_SESSION_CONTEXT_ATTRIBUTE_NAME, currentSessionContext);
}
}
@@ -518,11 +522,13 @@ public class WebContextsService extends
ServletRequestContext requestContext = getRequestContext(true);
if (destroySessionImmediately
- || requestContext == null ||
requestContext.getServletRequest() == null ||
requestContext.getServletRequest().getSession() == null
+ || requestContext == null ||
requestContext.getServletRequest() == null
+ || requestContext.getServletRequest().getSession() == null
|| sessionIsExpiring)
{
context.destroy();
- webBeansContext.getBeanManagerImpl().fireEvent(session != null
? session : new Object(), DestroyedLiteral.INSTANCE_SESSION_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ session != null ? session : new Object(),
DestroyedLiteral.INSTANCE_SESSION_SCOPED);
// Clear thread locals
sessionContexts.set(null);
@@ -591,7 +597,8 @@ public class WebContextsService extends
webBeansContext.getBeanManagerImpl().clearCacheProxies();
Object payload = endObject != null && endObject instanceof
ServletContext ? endObject : new Object();
- webBeansContext.getBeanManagerImpl().fireEvent(payload,
DestroyedLiteral.INSTANCE_APPLICATION_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ payload, DestroyedLiteral.INSTANCE_APPLICATION_SCOPED);
}
}
@@ -612,8 +619,10 @@ public class WebContextsService extends
{
singletonContext = new SingletonContext();
singletonContext.setActive(true);
- Object payLoad = startupObject != null && startupObject
instanceof ServletContext ? (ServletContext) startupObject : new Object();
- webBeansContext.getBeanManagerImpl().fireEvent(payLoad,
InitializedLiteral.INSTANCE_SINGLETON_SCOPED);
+ Object payLoad = startupObject != null && startupObject
instanceof ServletContext
+ ? (ServletContext) startupObject : new Object();
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ payLoad, InitializedLiteral.INSTANCE_SINGLETON_SCOPED);
}
}
}
@@ -629,7 +638,8 @@ public class WebContextsService extends
singletonContext.destroy();
singletonContext = null;
Object payload = endObject != null ? endObject : new Object();
- webBeansContext.getBeanManagerImpl().fireEvent(payload,
DestroyedLiteral.INSTANCE_SINGLETON_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ payload, DestroyedLiteral.INSTANCE_SINGLETON_SCOPED);
}
}
@@ -668,7 +678,8 @@ public class WebContextsService extends
if (context != null)
{
context.destroy();
- webBeansContext.getBeanManagerImpl().fireEvent(new Object(),
DestroyedLiteral.INSTANCE_SINGLETON_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+ new Object(), DestroyedLiteral.INSTANCE_SINGLETON_SCOPED);
}
conversationContexts.set(null);
@@ -726,8 +737,9 @@ public class WebContextsService extends
if (conversationContext.getConversation().isTransient())
{
-
webBeansContext.getBeanManagerImpl().fireEvent(conversationManager.getLifecycleEventPayload(conversationContext),
- InitializedLiteral.INSTANCE_CONVERSATION_SCOPED);
+
webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
+
conversationManager.getLifecycleEventPayload(conversationContext),
+ InitializedLiteral.INSTANCE_CONVERSATION_SCOPED);
}
Modified:
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java?rev=1681646&r1=1681645&r2=1681646&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
(original)
+++
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
Mon May 25 19:51:21 2015
@@ -118,12 +118,14 @@ public final class WebContainerLifecycle
servletContext.setAttribute(BeanManager.class.getName(),
getBeanManager());
// fire @Initialized(ApplicationScoped.class) if any observer for it
exists
- if
(webBeansContext.getBeanManagerImpl().getNotificationManager().hasLifecycleObserver(InitializedLiteral.INSTANCE_APPLICATION_SCOPED))
+ if (webBeansContext.getBeanManagerImpl().getNotificationManager().
+
hasContextLifecycleObserver(InitializedLiteral.INSTANCE_APPLICATION_SCOPED))
{
// we need to temporarily start the ReqeustContext
webBeansContext.getContextsService().startContext(RequestScoped.class, null);
- webBeansContext.getBeanManagerImpl().fireEvent(servletContext !=
null ? servletContext : new Object(),
InitializedLiteral.INSTANCE_APPLICATION_SCOPED);
+ webBeansContext.getBeanManagerImpl().fireEvent(
+ servletContext != null ? servletContext : new Object(),
InitializedLiteral.INSTANCE_APPLICATION_SCOPED);
// shut down the RequestContext again
webBeansContext.getContextsService().endContext(RequestScoped.class, null);