diff --git a/environments/se/core/src/main/java/org/jboss/weld/environment/se/WeldContainer.java b/environments/se/core/src/main/java/org/jboss/weld/environment/se/WeldContainer.java index 9b1db5ca686..a8e39b0fcb5 100644 --- a/environments/se/core/src/main/java/org/jboss/weld/environment/se/WeldContainer.java +++ b/environments/se/core/src/main/java/org/jboss/weld/environment/se/WeldContainer.java @@ -20,6 +20,9 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import javax.enterprise.context.BeforeDestroyed; +import javax.enterprise.context.Destroyed; +import javax.enterprise.context.Initialized; import javax.enterprise.context.spi.CreationalContext; import javax.enterprise.event.Event; import javax.enterprise.inject.Instance; @@ -36,12 +39,11 @@ import org.jboss.weld.bootstrap.spi.Deployment; import org.jboss.weld.environment.ContainerInstance; import org.jboss.weld.environment.deployment.WeldDeployment; +import org.jboss.weld.environment.se.events.ContainerBeforeShutdown; import org.jboss.weld.environment.se.events.ContainerInitialized; import org.jboss.weld.environment.se.events.ContainerShutdown; import org.jboss.weld.environment.se.logging.WeldSELogger; import org.jboss.weld.inject.WeldInstance; -import org.jboss.weld.literal.DestroyedLiteral; -import org.jboss.weld.literal.InitializedLiteral; import org.jboss.weld.manager.BeanManagerImpl; import org.jboss.weld.util.collections.ImmutableList; @@ -207,7 +209,7 @@ private void complete() { this.creationalContext = beanManager().createCreationalContext(null); this.instance = beanManager().getInstance(creationalContext); this.event = beanManager().event(); - beanManager().fireEvent(new ContainerInitialized(id), InitializedLiteral.APPLICATION); + beanManager().fireEvent(new ContainerInitialized(id), Initialized.Literal.APPLICATION); WeldSELogger.LOG.weldContainerInitialized(id); } @@ -260,11 +262,12 @@ public BeanManager getBeanManager() { public synchronized void shutdown() { checkIsRunning(); try { - beanManager().fireEvent(new ContainerShutdown(id), DestroyedLiteral.APPLICATION); + beanManager().fireEvent(new ContainerBeforeShutdown(id), BeforeDestroyed.Literal.APPLICATION); } finally { discard(id); // Destroy all the dependent beans correctly creationalContext.release(); + beanManager().fireEvent(new ContainerShutdown(id), Destroyed.Literal.APPLICATION); bootstrap.shutdown(); WeldSELogger.LOG.weldContainerShutdown(id); } diff --git a/environments/se/core/src/main/java/org/jboss/weld/environment/se/events/ContainerBeforeShutdown.java b/environments/se/core/src/main/java/org/jboss/weld/environment/se/events/ContainerBeforeShutdown.java new file mode 100644 index 00000000000..2f9c48d8f08 --- /dev/null +++ b/environments/se/core/src/main/java/org/jboss/weld/environment/se/events/ContainerBeforeShutdown.java @@ -0,0 +1,30 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2016, Red Hat, Inc., and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * 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. + */ +package org.jboss.weld.environment.se.events; + +/** + * An event that is fired when the Weld SE container is about to be shut down. + * + * @author Matej Novotny + */ +public class ContainerBeforeShutdown extends WeldContainerEvent { + + public ContainerBeforeShutdown(String containerId) { + super(containerId); + } + +} diff --git a/environments/se/core/src/main/java/org/jboss/weld/environment/se/events/ContainerShutdown.java b/environments/se/core/src/main/java/org/jboss/weld/environment/se/events/ContainerShutdown.java index 329d641b2f9..72f9b88eb0d 100644 --- a/environments/se/core/src/main/java/org/jboss/weld/environment/se/events/ContainerShutdown.java +++ b/environments/se/core/src/main/java/org/jboss/weld/environment/se/events/ContainerShutdown.java @@ -17,7 +17,7 @@ package org.jboss.weld.environment.se.events; /** - * An event that is fired when the Weld SE container is about to be shut down. + * An event that is fired after Weld SE container shutdown. * * @author Martin Kouba */ diff --git a/environments/se/core/src/test/java/org/jboss/weld/environment/se/test/container/events/ContainerEventsTest.java b/environments/se/core/src/test/java/org/jboss/weld/environment/se/test/container/events/ContainerEventsTest.java index 5ba43c1f05a..471933dfa7f 100644 --- a/environments/se/core/src/test/java/org/jboss/weld/environment/se/test/container/events/ContainerEventsTest.java +++ b/environments/se/core/src/test/java/org/jboss/weld/environment/se/test/container/events/ContainerEventsTest.java @@ -26,6 +26,7 @@ import org.jboss.weld.environment.se.Weld; import org.jboss.weld.environment.se.WeldContainer; +import org.jboss.weld.environment.se.events.ContainerBeforeShutdown; import org.jboss.weld.environment.se.events.ContainerInitialized; import org.jboss.weld.environment.se.events.ContainerShutdown; import org.jboss.weld.test.util.ActionSequence; @@ -45,16 +46,19 @@ public void testEventsFired() { assertFalse(container.select(ContainerObserver.class).isUnsatisfied()); } List sequenceData = ActionSequence.getSequenceData(); - assertEquals(4, sequenceData.size()); + assertEquals(6, sequenceData.size()); assertTrue(sequenceData.contains(ContainerInitialized.class.getName() + id)); assertTrue(sequenceData.contains(ContainerInitialized.class.getName() + ApplicationScoped.class.getName() + id)); + assertTrue(sequenceData.contains(ContainerBeforeShutdown.class.getName() + id)); + assertTrue(sequenceData.contains(ContainerBeforeShutdown.class.getName() + ApplicationScoped.class.getName() + id)); assertTrue(sequenceData.contains(ContainerShutdown.class.getName() + id)); assertTrue(sequenceData.contains(ContainerShutdown.class.getName() + ApplicationScoped.class.getName() + id)); sequenceData = ActionSequence.getSequenceData(ApplicationScoped.class.getName()); - assertEquals(2, sequenceData.size()); + assertEquals(3, sequenceData.size()); assertTrue(sequenceData.get(0).equals(ContainerInitialized.class.getName() + ApplicationScoped.class.getName())); - assertTrue(sequenceData.get(1).equals(ContainerShutdown.class.getName() + ApplicationScoped.class.getName())); + assertTrue(sequenceData.get(1).equals(ContainerBeforeShutdown.class.getName() + ApplicationScoped.class.getName())); + assertTrue(sequenceData.get(2).equals(ContainerShutdown.class.getName() + ApplicationScoped.class.getName())); } } diff --git a/environments/se/core/src/test/java/org/jboss/weld/environment/se/test/container/events/ContainerObserver.java b/environments/se/core/src/test/java/org/jboss/weld/environment/se/test/container/events/ContainerObserver.java index 846f8341be7..f7302bff08d 100644 --- a/environments/se/core/src/test/java/org/jboss/weld/environment/se/test/container/events/ContainerObserver.java +++ b/environments/se/core/src/test/java/org/jboss/weld/environment/se/test/container/events/ContainerObserver.java @@ -17,10 +17,12 @@ package org.jboss.weld.environment.se.test.container.events; import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.context.BeforeDestroyed; import javax.enterprise.context.Destroyed; import javax.enterprise.context.Initialized; import javax.enterprise.event.Observes; +import org.jboss.weld.environment.se.events.ContainerBeforeShutdown; import org.jboss.weld.environment.se.events.ContainerInitialized; import org.jboss.weld.environment.se.events.ContainerShutdown; import org.jboss.weld.test.util.ActionSequence; @@ -36,6 +38,10 @@ public void onAppScopeDestroy(@Observes @Destroyed(ApplicationScoped.class) Obje ActionSequence.addAction(ApplicationScoped.class.getName(), event.getClass().getName() + ApplicationScoped.class.getName()); } + public void onAppScopeBeforeDestroy(@Observes @BeforeDestroyed(ApplicationScoped.class) Object event) { + ActionSequence.addAction(ApplicationScoped.class.getName(), event.getClass().getName() + ApplicationScoped.class.getName()); + } + public void onContainerInitWithQualifier(@Observes @Initialized(ApplicationScoped.class) ContainerInitialized event) { ActionSequence.addAction(event.getClass().getName() + ApplicationScoped.class.getName() + event.getContainerId()); } @@ -52,4 +58,12 @@ public void onContainerShutdown(@Observes ContainerShutdown event) { ActionSequence.addAction(event.getClass().getName() + event.getContainerId()); } + public void onContainerBeforeShutdown(@Observes ContainerBeforeShutdown event) { + ActionSequence.addAction(event.getClass().getName() + event.getContainerId()); + } + + public void onContainerBeforeShutdownWithQualifier(@Observes @BeforeDestroyed(ApplicationScoped.class) ContainerBeforeShutdown event) { + ActionSequence.addAction(event.getClass().getName() + ApplicationScoped.class.getName() + event.getContainerId()); + } + } \ No newline at end of file diff --git a/impl/src/main/java/org/jboss/weld/bootstrap/WeldRuntime.java b/impl/src/main/java/org/jboss/weld/bootstrap/WeldRuntime.java index e3b58f6fc66..eb8db0d3708 100644 --- a/impl/src/main/java/org/jboss/weld/bootstrap/WeldRuntime.java +++ b/impl/src/main/java/org/jboss/weld/bootstrap/WeldRuntime.java @@ -16,8 +16,13 @@ */ package org.jboss.weld.bootstrap; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; import java.util.concurrent.ConcurrentMap; +import javax.enterprise.context.BeforeDestroyed; +import javax.enterprise.context.Destroyed; + import org.jboss.weld.Container; import org.jboss.weld.ContainerState; import org.jboss.weld.bootstrap.events.BeforeShutdownImpl; @@ -25,7 +30,6 @@ import org.jboss.weld.context.ApplicationContext; import org.jboss.weld.context.SingletonContext; import org.jboss.weld.event.ContextEvent; -import org.jboss.weld.literal.DestroyedLiteral; import org.jboss.weld.manager.BeanManagerImpl; /** @@ -51,32 +55,42 @@ public BeanManagerImpl getManager(BeanDeploymentArchive beanDeploymentArchive) { public void shutdown() { try { - // First, the container must destroy all contexts. + // The container must destroy all contexts. + // For non-web modules, fire @BeforeDestroyed event + fireEventForNonWebModules(Object.class, ContextEvent.APPLICATION_BEFORE_DESTROYED, BeforeDestroyed.Literal.APPLICATION); deploymentManager.instance().select(ApplicationContext.class).get().invalidate(); deploymentManager.instance().select(SingletonContext.class).get().invalidate(); } finally { + // fire @Destroyed(ApplicationScope.class) for non-web modules + fireEventForNonWebModules(Object.class, ContextEvent.APPLICATION_DESTROYED, Destroyed.Literal.APPLICATION); try { + // Finally, the container must fire an event of type BeforeShutdown. + BeforeShutdownImpl.fire(deploymentManager); + } finally { + Container container = Container.instance(contextId); + container.setState(ContainerState.SHUTDOWN); + container.cleanup(); + } + } + } + + /** + * Fires given event for non-web modules. Used for @BeforeDestroyed and @Destroyed events. + */ + private void fireEventForNonWebModules(Type eventType, Object event, Annotation... qualifiers) { + try { BeanDeploymentModules modules = deploymentManager.getServices().get(BeanDeploymentModules.class); if (modules != null) { - // fire @Destroyed(ApplicationScoped.class) for non-web modules + // fire event for non-web modules // web modules are handled by HttpContextLifecycle for (BeanDeploymentModule module : modules) { if (!module.isWebModule()) { - module.fireEvent(Object.class, ContextEvent.APPLICATION_DESTROYED, DestroyedLiteral.APPLICATION); + module.fireEvent(eventType, event, qualifiers); } } } } catch (Exception ignored) { } - try { - // Finally, the container must fire an event of type BeforeShutdown. - BeforeShutdownImpl.fire(deploymentManager); - } finally { - Container container = Container.instance(contextId); - container.setState(ContainerState.SHUTDOWN); - container.cleanup(); - } - } } } diff --git a/impl/src/main/java/org/jboss/weld/bootstrap/WeldStartup.java b/impl/src/main/java/org/jboss/weld/bootstrap/WeldStartup.java index abe6325d5b9..27f0c12e079 100644 --- a/impl/src/main/java/org/jboss/weld/bootstrap/WeldStartup.java +++ b/impl/src/main/java/org/jboss/weld/bootstrap/WeldStartup.java @@ -28,6 +28,7 @@ import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.ConversationScoped; import javax.enterprise.context.Dependent; +import javax.enterprise.context.Initialized; import javax.enterprise.context.NormalScope; import javax.enterprise.context.RequestScoped; import javax.enterprise.context.SessionScoped; @@ -98,7 +99,6 @@ import org.jboss.weld.injection.CurrentInjectionPoint; import org.jboss.weld.injection.ResourceInjectionFactory; import org.jboss.weld.injection.producer.InjectionTargetService; -import org.jboss.weld.literal.InitializedLiteral; import org.jboss.weld.logging.BootstrapLogger; import org.jboss.weld.logging.VersionLogger; import org.jboss.weld.manager.BeanManagerImpl; @@ -522,7 +522,7 @@ public void endInitialization() { // web modules are handled by HttpContextLifecycle for (BeanDeploymentModule module : modules) { if (!module.isWebModule()) { - module.fireEvent(Object.class, ContextEvent.APPLICATION_INITIALIZED, InitializedLiteral.APPLICATION); + module.fireEvent(Object.class, ContextEvent.APPLICATION_INITIALIZED, Initialized.Literal.APPLICATION); } } } diff --git a/impl/src/main/java/org/jboss/weld/context/AbstractConversationContext.java b/impl/src/main/java/org/jboss/weld/context/AbstractConversationContext.java index 1346d0c0f18..8ff4efcf08f 100644 --- a/impl/src/main/java/org/jboss/weld/context/AbstractConversationContext.java +++ b/impl/src/main/java/org/jboss/weld/context/AbstractConversationContext.java @@ -38,7 +38,9 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; +import javax.enterprise.context.BeforeDestroyed; import javax.enterprise.context.ConversationScoped; +import javax.enterprise.context.Destroyed; import org.jboss.weld.Container; import org.jboss.weld.bootstrap.api.ServiceRegistry; @@ -51,7 +53,6 @@ import org.jboss.weld.context.conversation.ConversationIdGenerator; import org.jboss.weld.context.conversation.ConversationImpl; import org.jboss.weld.event.FastEvent; -import org.jboss.weld.literal.DestroyedLiteral; import org.jboss.weld.logging.ConversationLogger; import org.jboss.weld.manager.BeanManagerImpl; import org.jboss.weld.serialization.BeanIdentifierIndex; @@ -83,10 +84,16 @@ public abstract class AbstractConversationContext extends AbstractBoundCon private final BeanManagerImpl manager; private final BeanIdentifierIndex beanIdentifierIndex; + private final LazyValueHolder> conversationBeforeDestroyedEvent = new LazyValueHolder>() { + @Override + protected FastEvent computeValue() { + return FastEvent.of(String.class, manager, manager.getGlobalLenientObserverNotifier(), BeforeDestroyed.Literal.CONVERSATION); + } + }; private final LazyValueHolder> conversationDestroyedEvent = new LazyValueHolder>() { @Override protected FastEvent computeValue() { - return FastEvent.of(String.class, manager, manager.getGlobalLenientObserverNotifier(), DestroyedLiteral.CONVERSATION); + return FastEvent.of(String.class, manager, manager.getGlobalLenientObserverNotifier(), Destroyed.Literal.CONVERSATION); } }; @@ -392,6 +399,7 @@ private void setDestructionQueue(Map conversations, protected void destroyConversation(S session, String id) { if (session != null) { + conversationBeforeDestroyedEvent.get().fire(id); setBeanStore(createSessionBeanStore(new ConversationNamingScheme(getNamingSchemePrefix(), id, beanIdentifierIndex), session)); getBeanStore().attach(); destroy(); diff --git a/impl/src/main/java/org/jboss/weld/context/activator/AbstractActivateRequestContextInterceptor.java b/impl/src/main/java/org/jboss/weld/context/activator/AbstractActivateRequestContextInterceptor.java index 7baca28a842..2e80a52bb9e 100644 --- a/impl/src/main/java/org/jboss/weld/context/activator/AbstractActivateRequestContextInterceptor.java +++ b/impl/src/main/java/org/jboss/weld/context/activator/AbstractActivateRequestContextInterceptor.java @@ -17,14 +17,14 @@ package org.jboss.weld.context.activator; import javax.enterprise.context.BeforeDestroyed; +import javax.enterprise.context.Destroyed; +import javax.enterprise.context.Initialized; import javax.enterprise.context.RequestScoped; import javax.interceptor.AroundInvoke; import javax.interceptor.InvocationContext; import org.jboss.weld.context.RequestContext; import org.jboss.weld.event.FastEvent; -import org.jboss.weld.literal.DestroyedLiteral; -import org.jboss.weld.literal.InitializedLiteral; import org.jboss.weld.manager.BeanManagerImpl; /** @@ -44,9 +44,9 @@ public abstract class AbstractActivateRequestContextInterceptor { public AbstractActivateRequestContextInterceptor(RequestContext requestContext, BeanManagerImpl beanManager) { this.beanManager = beanManager; this.requestContext = requestContext; - fastEventInit = FastEvent.of(Object.class, beanManager, InitializedLiteral.REQUEST); + fastEventInit = FastEvent.of(Object.class, beanManager, Initialized.Literal.REQUEST); fastEventBeforeDestroyed = FastEvent.of(Object.class, beanManager, BeforeDestroyed.Literal.REQUEST); - fastEventDestroyed = FastEvent.of(Object.class, beanManager, DestroyedLiteral.REQUEST); + fastEventDestroyed = FastEvent.of(Object.class, beanManager, Destroyed.Literal.REQUEST); } @AroundInvoke diff --git a/impl/src/main/java/org/jboss/weld/event/ContextEvent.java b/impl/src/main/java/org/jboss/weld/event/ContextEvent.java index 047215455d8..e9e8b24f9c6 100644 --- a/impl/src/main/java/org/jboss/weld/event/ContextEvent.java +++ b/impl/src/main/java/org/jboss/weld/event/ContextEvent.java @@ -33,8 +33,10 @@ public final class ContextEvent implements Serializable { private static final long serialVersionUID = -1197351184144276424L; public static final ContextEvent APPLICATION_INITIALIZED = new ContextEvent("Application context initialized."); + public static final ContextEvent APPLICATION_BEFORE_DESTROYED = new ContextEvent("Application context is about to be destroyed."); public static final ContextEvent APPLICATION_DESTROYED = new ContextEvent("Application context destroyed."); public static final Object REQUEST_INITIALIZED_EJB = new ContextEvent("Request context initialized for EJB invocation"); + public static final Object REQUEST_BEFORE_DESTROYED_EJB = new ContextEvent("Request context is about to be destroyed after EJB invocation"); public static final Object REQUEST_DESTROYED_EJB = new ContextEvent("Request context destroyed after EJB invocation"); private final String message; diff --git a/impl/src/main/java/org/jboss/weld/literal/DestroyedLiteral.java b/impl/src/main/java/org/jboss/weld/literal/DestroyedLiteral.java deleted file mode 100644 index 3072d5105b9..00000000000 --- a/impl/src/main/java/org/jboss/weld/literal/DestroyedLiteral.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * 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. - */ -package org.jboss.weld.literal; - -import java.lang.annotation.Annotation; - -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.context.ConversationScoped; -import javax.enterprise.context.Destroyed; -import javax.enterprise.context.RequestScoped; -import javax.enterprise.context.SessionScoped; -import javax.enterprise.util.AnnotationLiteral; - -/** - * Annotation literal for {@link Destroyed}. - * - * @author Jozef Hartinger - * - */ -@SuppressWarnings("all") -public class DestroyedLiteral extends AnnotationLiteral implements Destroyed { - - private static final long serialVersionUID = 217403232984847384L; - - public static final DestroyedLiteral REQUEST = new DestroyedLiteral(RequestScoped.class); - public static final DestroyedLiteral CONVERSATION = new DestroyedLiteral(ConversationScoped.class); - public static final DestroyedLiteral SESSION = new DestroyedLiteral(SessionScoped.class); - public static final DestroyedLiteral APPLICATION = new DestroyedLiteral(ApplicationScoped.class); - - private Class value; - - private DestroyedLiteral(Class value) { - this.value = value; - } - - @Override - public Class value() { - return value; - } -} diff --git a/impl/src/main/java/org/jboss/weld/literal/InitializedLiteral.java b/impl/src/main/java/org/jboss/weld/literal/InitializedLiteral.java deleted file mode 100644 index dfd14f9fb60..00000000000 --- a/impl/src/main/java/org/jboss/weld/literal/InitializedLiteral.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * 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. - */ -package org.jboss.weld.literal; - -import java.lang.annotation.Annotation; - -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.context.ConversationScoped; -import javax.enterprise.context.Initialized; -import javax.enterprise.context.RequestScoped; -import javax.enterprise.context.SessionScoped; -import javax.enterprise.util.AnnotationLiteral; - -/** - * Annotation literal for {@link Initialized}. - * - * @author Jozef Hartinger - * - */ -@SuppressWarnings("all") -public class InitializedLiteral extends AnnotationLiteral implements Initialized { - - private static final long serialVersionUID = 217403232984847384L; - - public static final InitializedLiteral REQUEST = new InitializedLiteral(RequestScoped.class); - public static final InitializedLiteral CONVERSATION = new InitializedLiteral(ConversationScoped.class); - public static final InitializedLiteral SESSION = new InitializedLiteral(SessionScoped.class); - public static final InitializedLiteral APPLICATION = new InitializedLiteral(ApplicationScoped.class); - - private Class value; - - private InitializedLiteral(Class value) { - this.value = value; - } - - @Override - public Class value() { - return value; - } -} diff --git a/jboss-tck-runner/src/test/tck20/tck-tests.xml b/jboss-tck-runner/src/test/tck20/tck-tests.xml index 21005dc1ba7..4304e8f3802 100644 --- a/jboss-tck-runner/src/test/tck20/tck-tests.xml +++ b/jboss-tck-runner/src/test/tck20/tck-tests.xml @@ -73,6 +73,13 @@ + + +- +- +- +- + @@ -134,22 +141,8 @@ - - - - - - - - - - - - - - diff --git a/modules/ejb/src/main/java/org/jboss/weld/ejb/AbstractEJBRequestScopeActivationInterceptor.java b/modules/ejb/src/main/java/org/jboss/weld/ejb/AbstractEJBRequestScopeActivationInterceptor.java index 0866fccd529..db5d3a59865 100644 --- a/modules/ejb/src/main/java/org/jboss/weld/ejb/AbstractEJBRequestScopeActivationInterceptor.java +++ b/modules/ejb/src/main/java/org/jboss/weld/ejb/AbstractEJBRequestScopeActivationInterceptor.java @@ -18,14 +18,15 @@ import java.io.Serializable; +import javax.enterprise.context.BeforeDestroyed; +import javax.enterprise.context.Destroyed; +import javax.enterprise.context.Initialized; import javax.enterprise.context.RequestScoped; import javax.interceptor.InvocationContext; import org.jboss.weld.context.ejb.EjbRequestContext; import org.jboss.weld.event.ContextEvent; import org.jboss.weld.event.FastEvent; -import org.jboss.weld.literal.DestroyedLiteral; -import org.jboss.weld.literal.InitializedLiteral; import org.jboss.weld.manager.BeanManagerImpl; import org.jboss.weld.util.LazyValueHolder; @@ -47,14 +48,21 @@ public abstract class AbstractEJBRequestScopeActivationInterceptor implements Se private static final long serialVersionUID = 1L; @Override protected FastEvent computeValue() { - return FastEvent.of(Object.class, getBeanManager(), getBeanManager().getGlobalLenientObserverNotifier(), InitializedLiteral.REQUEST); + return FastEvent.of(Object.class, getBeanManager(), getBeanManager().getGlobalLenientObserverNotifier(), Initialized.Literal.REQUEST); + } + }; + private final LazyValueHolder> requestBeforeDestroyedEvent = new LazyValueHolder.Serializable>() { + private static final long serialVersionUID = 1L; + @Override + protected FastEvent computeValue() { + return FastEvent.of(Object.class, getBeanManager(), getBeanManager().getGlobalLenientObserverNotifier(), BeforeDestroyed.Literal.REQUEST); } }; private final LazyValueHolder> requestDestroyedEvent = new LazyValueHolder.Serializable>() { private static final long serialVersionUID = 1L; @Override protected FastEvent computeValue() { - return FastEvent.of(Object.class, getBeanManager(), getBeanManager().getGlobalLenientObserverNotifier(), DestroyedLiteral.REQUEST); + return FastEvent.of(Object.class, getBeanManager(), getBeanManager().getGlobalLenientObserverNotifier(), Destroyed.Literal.REQUEST); } }; @@ -72,6 +80,7 @@ public Object aroundInvoke(InvocationContext invocation) throws Exception { requestInitializedEvent.get().fire(ContextEvent.REQUEST_INITIALIZED_EJB); return invocation.proceed(); } finally { + requestBeforeDestroyedEvent.get().fire(ContextEvent.REQUEST_BEFORE_DESTROYED_EJB); requestContext.invalidate(); requestContext.deactivate(); } diff --git a/modules/web/src/main/java/org/jboss/weld/servlet/ConversationContextActivator.java b/modules/web/src/main/java/org/jboss/weld/servlet/ConversationContextActivator.java index 20a6a37d9db..4ba172b0e7e 100644 --- a/modules/web/src/main/java/org/jboss/weld/servlet/ConversationContextActivator.java +++ b/modules/web/src/main/java/org/jboss/weld/servlet/ConversationContextActivator.java @@ -25,6 +25,9 @@ import java.util.Map.Entry; import java.util.function.Consumer; +import javax.enterprise.context.BeforeDestroyed; +import javax.enterprise.context.Destroyed; +import javax.enterprise.context.Initialized; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; @@ -34,8 +37,6 @@ import org.jboss.weld.context.http.HttpConversationContext; import org.jboss.weld.context.http.LazyHttpConversationContextImpl; import org.jboss.weld.event.FastEvent; -import org.jboss.weld.literal.DestroyedLiteral; -import org.jboss.weld.literal.InitializedLiteral; import org.jboss.weld.logging.ContextLogger; import org.jboss.weld.logging.ConversationLogger; import org.jboss.weld.logging.ServletLogger; @@ -63,6 +64,7 @@ public class ConversationContextActivator { private HttpConversationContext httpConversationContextCache; private final FastEvent conversationInitializedEvent; + private final FastEvent conversationBeforeDestroyedEvent; private final FastEvent conversationDestroyedEvent; private final Consumer lazyInitializationCallback; @@ -71,8 +73,9 @@ public class ConversationContextActivator { protected ConversationContextActivator(BeanManagerImpl beanManager, boolean lazy) { this.beanManager = beanManager; - conversationInitializedEvent = FastEvent.of(HttpServletRequest.class, beanManager, InitializedLiteral.CONVERSATION); - conversationDestroyedEvent = FastEvent.of(HttpServletRequest.class, beanManager, DestroyedLiteral.CONVERSATION); + conversationInitializedEvent = FastEvent.of(HttpServletRequest.class, beanManager, Initialized.Literal.CONVERSATION); + conversationBeforeDestroyedEvent = FastEvent.of(HttpServletRequest.class, beanManager, BeforeDestroyed.Literal.CONVERSATION); + conversationDestroyedEvent = FastEvent.of(HttpServletRequest.class, beanManager, Destroyed.Literal.CONVERSATION); lazyInitializationCallback = lazy ? conversationInitializedEvent::fire : null; this.lazy = lazy; } @@ -166,6 +169,9 @@ protected void deactivateConversationContext(HttpServletRequest request) { ConversationLogger.LOG.cleaningUpConversation(conversationContext.getCurrentConversation().getId()); } } + if (isTransient) { + conversationBeforeDestroyedEvent.fire(request); + } conversationContext.invalidate(); conversationContext.deactivate(); if (isTransient) { @@ -189,9 +195,11 @@ private void processDestructionQueue(HttpServletRequest request) { if (contextsAttribute instanceof Map) { Map>> contexts = cast(contextsAttribute); synchronized (contexts) { - FastEvent destroyedEvent = FastEvent.of(String.class, beanManager, DestroyedLiteral.CONVERSATION); + FastEvent beforeDestroyedEvent = FastEvent.of(String.class, beanManager, BeforeDestroyed.Literal.CONVERSATION); + FastEvent destroyedEvent = FastEvent.of(String.class, beanManager, Destroyed.Literal.CONVERSATION); for (Iterator>>> iterator = contexts.entrySet().iterator(); iterator.hasNext();) { Entry>> entry = iterator.next(); + beforeDestroyedEvent.fire(entry.getKey()); for (ContextualInstance contextualInstance : entry.getValue()) { destroyContextualInstance(contextualInstance); } diff --git a/modules/web/src/main/java/org/jboss/weld/servlet/HttpContextLifecycle.java b/modules/web/src/main/java/org/jboss/weld/servlet/HttpContextLifecycle.java index 06549eee7e5..96fbcffdc05 100644 --- a/modules/web/src/main/java/org/jboss/weld/servlet/HttpContextLifecycle.java +++ b/modules/web/src/main/java/org/jboss/weld/servlet/HttpContextLifecycle.java @@ -19,6 +19,9 @@ import java.lang.annotation.Annotation; import java.util.Collections; +import javax.enterprise.context.BeforeDestroyed; +import javax.enterprise.context.Destroyed; +import javax.enterprise.context.Initialized; import javax.enterprise.inject.spi.EventMetadata; import javax.servlet.ServletContext; import javax.servlet.ServletRequestListener; @@ -38,8 +41,6 @@ import org.jboss.weld.context.http.HttpSessionDestructionContext; import org.jboss.weld.event.EventMetadataImpl; import org.jboss.weld.event.FastEvent; -import org.jboss.weld.literal.DestroyedLiteral; -import org.jboss.weld.literal.InitializedLiteral; import org.jboss.weld.logging.ServletLogger; import org.jboss.weld.manager.BeanManagerImpl; import org.jboss.weld.servlet.spi.HttpContextActivationFilter; @@ -78,8 +79,10 @@ public class HttpContextLifecycle implements Service { private final HttpContextActivationFilter contextActivationFilter; private final FastEvent requestInitializedEvent; + private final FastEvent requestBeforeDestroyedEvent; private final FastEvent requestDestroyedEvent; private final FastEvent sessionInitializedEvent; + private final FastEvent sessionBeforeDestroyedEvent; private final FastEvent sessionDestroyedEvent; private final ServletApiAbstraction servletApi; @@ -104,10 +107,12 @@ public HttpContextLifecycle(BeanManagerImpl beanManager, HttpContextActivationFi this.ignoreForwards = ignoreForwards; this.ignoreIncludes = ignoreIncludes; this.contextActivationFilter = contextActivationFilter; - this.requestInitializedEvent = FastEvent.of(HttpServletRequest.class, beanManager, InitializedLiteral.REQUEST); - this.requestDestroyedEvent = FastEvent.of(HttpServletRequest.class, beanManager, DestroyedLiteral.REQUEST); - this.sessionInitializedEvent = FastEvent.of(HttpSession.class, beanManager, InitializedLiteral.SESSION); - this.sessionDestroyedEvent = FastEvent.of(HttpSession.class, beanManager, DestroyedLiteral.SESSION); + this.requestInitializedEvent = FastEvent.of(HttpServletRequest.class, beanManager, Initialized.Literal.REQUEST); + this.requestBeforeDestroyedEvent = FastEvent.of(HttpServletRequest.class, beanManager, BeforeDestroyed.Literal.REQUEST); + this.requestDestroyedEvent = FastEvent.of(HttpServletRequest.class, beanManager, Destroyed.Literal.REQUEST); + this.sessionInitializedEvent = FastEvent.of(HttpSession.class, beanManager, Initialized.Literal.SESSION); + this.sessionBeforeDestroyedEvent = FastEvent.of(HttpSession.class, beanManager, BeforeDestroyed.Literal.SESSION); + this.sessionDestroyedEvent = FastEvent.of(HttpSession.class, beanManager, Destroyed.Literal.SESSION); this.servletApi = beanManager.getServices().get(ServletApiAbstraction.class); this.servletContextService = beanManager.getServices().get(ServletContextService.class); this.nestedInvocationGuardEnabled = nestedInvocationGuardEnabled; @@ -140,13 +145,15 @@ public HttpRequestContext getRequestContext() { public void contextInitialized(ServletContext ctx) { servletContextService.contextInitialized(ctx); synchronized (container) { - fireEventForApplicationScope(ctx, InitializedLiteral.APPLICATION); + fireEventForApplicationScope(ctx, Initialized.Literal.APPLICATION); } } public void contextDestroyed(ServletContext ctx) { synchronized (container) { - fireEventForApplicationScope(ctx, DestroyedLiteral.APPLICATION); + // TODO firing these two right after each other does not really make sense + fireEventForApplicationScope(ctx, BeforeDestroyed.Literal.APPLICATION); + fireEventForApplicationScope(ctx, Destroyed.Literal.APPLICATION); } } @@ -304,13 +311,19 @@ public void requestDestroyed(HttpServletRequest request) { getRequestContext().invalidate(); } + // fire @BeforeDestroyed(RequestScoped.class) + requestBeforeDestroyedEvent.fire(request); safelyDeactivate(getRequestContext(), request); // fire @Destroyed(RequestScoped.class) requestDestroyedEvent.fire(request); + Object destroyedHttpSession = request.getAttribute(HTTP_SESSION); + // fire @BeforeDestroyed(SessionScoped.class) + if (destroyedHttpSession != null) { + sessionBeforeDestroyedEvent.fire((HttpSession) destroyedHttpSession); + } safelyDeactivate(getSessionContext(), request); // fire @Destroyed(SessionScoped.class) - Object destroyedHttpSession = request.getAttribute(HTTP_SESSION); if (destroyedHttpSession != null) { sessionDestroyedEvent.fire((HttpSession) destroyedHttpSession); } diff --git a/pom.xml b/pom.xml index eacd2a4a4b7..e6d25cfe6cf 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ 1.1.11.Final 2.0.0.Final 2.1.0.CR1 - 2.0.0.Beta3 + 2.0.0.Beta4 1.0.1.Final 1.0.0.CR6 1.0.0.CR3