| @@ -0,0 +1,167 @@ | ||
| /* | ||
| * JBoss, Home of Professional Open Source | ||
| * Copyright 2019, Red Hat Inc., and individual contributors as indicated | ||
| * by the @authors tag. See the copyright.txt in the distribution for a | ||
| * full listing of individual contributors. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
|
|
||
| package org.jboss.as.test.integration.weld.context.application.lifecycle; | ||
|
|
||
| import org.jboss.arquillian.container.test.api.Deployer; | ||
| import org.jboss.arquillian.container.test.api.Deployment; | ||
| import org.jboss.arquillian.junit.Arquillian; | ||
| import org.jboss.arquillian.test.api.ArquillianResource; | ||
| import org.jboss.shrinkwrap.api.Archive; | ||
| import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
| import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; | ||
| import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
| import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| import javax.naming.InitialContext; | ||
| import javax.naming.NamingException; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| /** | ||
| * Tests possible deployment scenarios for CDI ApplicationScoped events, and usage of other EE technologies in such event handlers. | ||
| * @author emmartins | ||
| */ | ||
| @RunWith(Arquillian.class) | ||
| public class ApplicationContextLifecycleTestCase { | ||
|
|
||
| private static final String TEST_BEANS_LIB_JAR = "TEST_BEANS_LIB_JAR"; | ||
| private static final String TEST_BEANS_EJB_JAR = "TEST_BEANS_EJB_JAR"; | ||
| private static final String TEST_BEANS_EAR = "TEST_BEANS_EAR"; | ||
| private static final String TEST_BEANS_WAR = "TEST_BEANS_WAR"; | ||
| private static final String TEST_RESULTS = "TEST_RESULTS"; | ||
|
|
||
| @ArquillianResource | ||
| public Deployer deployer; | ||
|
|
||
| @Deployment(name = TEST_BEANS_EJB_JAR, managed = false) | ||
| public static Archive<JavaArchive> deployJar() { | ||
| final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, TEST_BEANS_EJB_JAR +".jar") | ||
| .addClasses(Ejb.class, Bean.class, Mdb.class, TestResults.class, Utils.class); | ||
| return ejbJar; | ||
| } | ||
|
|
||
| @Deployment(name = TEST_BEANS_EAR, managed = false) | ||
| public static Archive<EnterpriseArchive> deployEar() { | ||
| final JavaArchive libJar = ShrinkWrap.create(JavaArchive.class, TEST_BEANS_LIB_JAR +".jar") | ||
| .addClasses(TestResults.class, Utils.class); | ||
| final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, TEST_BEANS_EJB_JAR +".jar") | ||
| .addClasses(Ejb.class, Bean.class, Mdb.class); | ||
| final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, TEST_BEANS_EAR +".ear") | ||
| .addAsLibrary(libJar) | ||
| .addAsModule(ejbJar); | ||
| return ear; | ||
| } | ||
|
|
||
| @Deployment(name = TEST_BEANS_WAR, managed = false) | ||
| public static Archive<WebArchive> deployWar() { | ||
| final JavaArchive libJar = ShrinkWrap.create(JavaArchive.class, TEST_BEANS_LIB_JAR +".jar") | ||
| .addClasses(TestResults.class, Utils.class); | ||
| final WebArchive war = ShrinkWrap.create(WebArchive.class, TEST_BEANS_WAR +".war") | ||
| .addAsLibrary(libJar) | ||
| .addClasses(Servlet.class, Bean.class, Mdb.class); | ||
| return war; | ||
| } | ||
|
|
||
| @Deployment | ||
| public static Archive<?> deployTestResults() { | ||
| final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, TEST_RESULTS +".jar"); | ||
| jar.addClasses(TestResultsBean.class, TestResults.class); | ||
| return jar; | ||
| } | ||
|
|
||
| @ArquillianResource | ||
| private InitialContext initialContext; | ||
|
|
||
| @Test | ||
| public void testJar() throws NamingException, InterruptedException { | ||
| final TestResults testResults = (TestResults) initialContext.lookup("java:global/"+ TEST_RESULTS +"/"+ TestResultsBean.class.getSimpleName()+"!"+ TestResults.class.getName()); | ||
| // setup initialized test | ||
| testResults.setup(2); | ||
| // deploy app | ||
| deployer.deploy(TEST_BEANS_EJB_JAR); | ||
| // await and assert initialized results | ||
| testResults.await(5, TimeUnit.SECONDS); | ||
| Assert.assertTrue(testResults.isCdiBeanInitialized()); | ||
| Assert.assertTrue(testResults.isEjbBeanInitialized()); | ||
| // NOTE: before destroyed and destroyed atm only guaranteed for web deployments, uncomment all once that's solved | ||
| // setup before destroyed and destroyed test | ||
| //testResults.setup(4); | ||
| // undeploy app | ||
| deployer.undeploy(TEST_BEANS_EJB_JAR); | ||
| // await and assert before destroyed and destroyed results | ||
| //testResults.await(5, TimeUnit.SECONDS); | ||
| //Assert.assertTrue(testResults.isCdiBeanBeforeDestroyed()); | ||
| //Assert.assertTrue(testResults.isCdiBeanDestroyed()); | ||
| //Assert.assertTrue(testResults.isEjbBeanBeforeDestroyed()); | ||
| //Assert.assertTrue(testResults.isEjbBeanDestroyed()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEar() throws NamingException, InterruptedException { | ||
| final TestResults testResults = (TestResults) initialContext.lookup("java:global/"+ TEST_RESULTS +"/"+ TestResultsBean.class.getSimpleName()+"!"+ TestResults.class.getName()); | ||
| // setup initialized test | ||
| testResults.setup(2); | ||
| // deploy app | ||
| deployer.deploy(TEST_BEANS_EAR); | ||
| // await and assert initialized results | ||
| testResults.await(5, TimeUnit.SECONDS); | ||
| Assert.assertTrue(testResults.isCdiBeanInitialized()); | ||
| Assert.assertTrue(testResults.isEjbBeanInitialized()); | ||
| // NOTE: before destroyed and destroyed atm only guaranteed for web deployments, uncomment all once that's solved | ||
| // setup before destroyed and destroyed test | ||
| //testResults.setup(4); | ||
| // undeploy app | ||
| deployer.undeploy(TEST_BEANS_EAR); | ||
| // await and assert before destroyed and destroyed results | ||
| //testResults.await(5, TimeUnit.SECONDS); | ||
| //Assert.assertTrue(testResults.isCdiBeanBeforeDestroyed()); | ||
| //Assert.assertTrue(testResults.isCdiBeanDestroyed()); | ||
| //Assert.assertTrue(testResults.isEjbBeanBeforeDestroyed()); | ||
| //Assert.assertTrue(testResults.isEjbBeanDestroyed()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testWar() throws NamingException, InterruptedException { | ||
| final TestResults testResults = (TestResults) initialContext.lookup("java:global/"+ TEST_RESULTS +"/"+ TestResultsBean.class.getSimpleName()+"!"+ TestResults.class.getName()); | ||
| // setup initialized test | ||
| testResults.setup(2); | ||
| // deploy app | ||
| deployer.deploy(TEST_BEANS_WAR); | ||
| // await and assert initialized results | ||
| testResults.await(5, TimeUnit.SECONDS); | ||
| Assert.assertTrue(testResults.isCdiBeanInitialized()); | ||
| Assert.assertTrue(testResults.isServletInitialized()); | ||
| // setup before destroyed and destroyed test | ||
| testResults.setup(4); | ||
| // undeploy app | ||
| deployer.undeploy(TEST_BEANS_WAR); | ||
| // await and assert before destroyed and destroyed results | ||
| testResults.await(5, TimeUnit.SECONDS); | ||
| Assert.assertTrue(testResults.isCdiBeanBeforeDestroyed()); | ||
| Assert.assertTrue(testResults.isCdiBeanDestroyed()); | ||
| Assert.assertTrue(testResults.isServletBeforeDestroyed()); | ||
| Assert.assertTrue(testResults.isServletDestroyed()); | ||
| } | ||
| } |
| @@ -0,0 +1,126 @@ | ||
| /* | ||
| * JBoss, Home of Professional Open Source | ||
| * Copyright 2019, Red Hat Inc., and individual contributors as indicated | ||
| * by the @authors tag. See the copyright.txt in the distribution for a | ||
| * full listing of individual contributors. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
|
|
||
| package org.jboss.as.test.integration.weld.context.application.lifecycle; | ||
|
|
||
| import org.jboss.logging.Logger; | ||
|
|
||
| import javax.annotation.Resource; | ||
| import javax.ejb.EJB; | ||
| import javax.enterprise.concurrent.ManagedExecutorService; | ||
| import javax.enterprise.context.ApplicationScoped; | ||
| import javax.enterprise.context.BeforeDestroyed; | ||
| import javax.enterprise.context.Destroyed; | ||
| import javax.enterprise.context.Initialized; | ||
| import javax.enterprise.context.control.RequestContextController; | ||
| import javax.enterprise.event.Observes; | ||
| import javax.inject.Inject; | ||
| import javax.jms.JMSContext; | ||
| import javax.jms.Queue; | ||
| import javax.naming.NamingException; | ||
|
|
||
| /** | ||
| * @author emmartins | ||
| */ | ||
| @ApplicationScoped | ||
| public class Bean { | ||
|
|
||
| private static final Logger LOGGER = Logger.getLogger(Bean.class.getName()); | ||
|
|
||
| @Resource | ||
| private ManagedExecutorService executorService; | ||
|
|
||
| @Inject | ||
| private JMSContext jmsContext; | ||
|
|
||
| @Resource(lookup = Mdb.JNDI_NAME) | ||
| private Queue jmsQueue; | ||
|
|
||
| @Inject | ||
| private RequestContextController requestContextController; | ||
|
|
||
| @EJB(lookup = "java:global/TEST_RESULTS/TestResultsBean!org.jboss.as.test.integration.weld.context.application.lifecycle.TestResults") | ||
| private TestResults testResults; | ||
|
|
||
| public void onInitialized(@Observes @Initialized(ApplicationScoped.class) Object object) { | ||
| LOGGER.info("onInitialized!"); | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, false); | ||
| executorService.submit(() -> { | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, false); | ||
| testResults.setCdiBeanInitialized(true); | ||
| } catch (NamingException e) { | ||
| LOGGER.error("Failed to set initialized test result", e); | ||
| testResults.setCdiBeanInitialized(false); | ||
| } | ||
| }).get(); | ||
| } catch (Throwable e) { | ||
| LOGGER.error("Failed to set initialized test result", e); | ||
| testResults.setCdiBeanInitialized(false); | ||
| } | ||
| } | ||
|
|
||
| public void onBeforeDestroyed(@Observes @BeforeDestroyed(ApplicationScoped.class) Object object) { | ||
| LOGGER.info("onBeforeDestroyed!"); | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, false); | ||
| executorService.submit(() -> { | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, false); | ||
| testResults.setCdiBeanBeforeDestroyed(true); | ||
| } catch (NamingException e) { | ||
| LOGGER.error("Failed to set initialized test result", e); | ||
| testResults.setCdiBeanBeforeDestroyed(false); | ||
| } | ||
| }).get(); | ||
| } catch (Throwable e) { | ||
| LOGGER.error("Failed to set initialized test result", e); | ||
| testResults.setCdiBeanBeforeDestroyed(false); | ||
| } | ||
| } | ||
|
|
||
| public void onDestroyed(@Observes @Destroyed(ApplicationScoped.class) Object object) { | ||
| LOGGER.info("onDestroyed!"); | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, false); | ||
| executorService.submit(() -> { | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, false); | ||
| testResults.setCdiBeanDestroyed(true); | ||
| } catch (NamingException e) { | ||
| LOGGER.error("Failed to set initialized test result", e); | ||
| testResults.setCdiBeanDestroyed(false); | ||
| } | ||
| }).get(); | ||
| } catch (Throwable e) { | ||
| LOGGER.error("Failed to set initialized test result", e); | ||
| testResults.setCdiBeanDestroyed(false); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,127 @@ | ||
| /* | ||
| * JBoss, Home of Professional Open Source | ||
| * Copyright 2019, Red Hat Inc., and individual contributors as indicated | ||
| * by the @authors tag. See the copyright.txt in the distribution for a | ||
| * full listing of individual contributors. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
|
|
||
| package org.jboss.as.test.integration.weld.context.application.lifecycle; | ||
|
|
||
| import org.jboss.logging.Logger; | ||
|
|
||
| import javax.annotation.Resource; | ||
| import javax.ejb.EJB; | ||
| import javax.ejb.Stateless; | ||
| import javax.enterprise.concurrent.ManagedExecutorService; | ||
| import javax.enterprise.context.ApplicationScoped; | ||
| import javax.enterprise.context.BeforeDestroyed; | ||
| import javax.enterprise.context.Destroyed; | ||
| import javax.enterprise.context.Initialized; | ||
| import javax.enterprise.context.control.RequestContextController; | ||
| import javax.enterprise.event.Observes; | ||
| import javax.inject.Inject; | ||
| import javax.jms.JMSContext; | ||
| import javax.jms.Queue; | ||
| import javax.naming.NamingException; | ||
|
|
||
| /** | ||
| * @author emmartins | ||
| */ | ||
| @Stateless | ||
| public class Ejb { | ||
|
|
||
| private static final Logger LOGGER = Logger.getLogger(Ejb.class.getName()); | ||
|
|
||
| @Resource | ||
| private ManagedExecutorService executorService; | ||
|
|
||
| @Inject | ||
| private JMSContext jmsContext; | ||
|
|
||
| @Resource(lookup = Mdb.JNDI_NAME) | ||
| private Queue jmsQueue; | ||
|
|
||
| @Inject | ||
| private RequestContextController requestContextController; | ||
|
|
||
| @EJB(lookup = "java:global/TEST_RESULTS/TestResultsBean!org.jboss.as.test.integration.weld.context.application.lifecycle.TestResults") | ||
| private TestResults testResults; | ||
|
|
||
| public void onInitialized(@Observes @Initialized(ApplicationScoped.class) Object event) { | ||
| LOGGER.info("onInitialized!"); | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, true); | ||
| executorService.submit(() -> { | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, true); | ||
| testResults.setEjbBeanInitialized(true); | ||
| } catch (NamingException e) { | ||
| LOGGER.error("Failed to set initialized test result", e); | ||
| testResults.setEjbBeanInitialized(false); | ||
| } | ||
| }).get(); | ||
| } catch (Throwable e) { | ||
| LOGGER.error("Failed to set initialized test result", e); | ||
| testResults.setEjbBeanInitialized(false); | ||
| } | ||
| } | ||
|
|
||
| public void onBeforeDestroyed(@Observes @BeforeDestroyed(ApplicationScoped.class) Object object) { | ||
| LOGGER.info("onBeforeDestroyed!"); | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, false); | ||
| executorService.submit(() -> { | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, false); | ||
| testResults.setEjbBeanBeforeDestroyed(true); | ||
| } catch (NamingException e) { | ||
| LOGGER.error("Failed to set before destroyed test result", e); | ||
| testResults.setEjbBeanBeforeDestroyed(false); | ||
| } | ||
| }).get(); | ||
| } catch (Throwable e) { | ||
| LOGGER.error("Failed to set before destroyed test result", e); | ||
| testResults.setEjbBeanBeforeDestroyed(false); | ||
| } | ||
| } | ||
|
|
||
| public void onDestroyed(@Observes @Destroyed(ApplicationScoped.class) Object object) { | ||
| LOGGER.info("onDestroyed!"); | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, false); | ||
| executorService.submit(() -> { | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, false); | ||
| testResults.setEjbBeanDestroyed(true); | ||
| } catch (NamingException e) { | ||
| LOGGER.error("Failed to set destroyed test result", e); | ||
| testResults.setEjbBeanDestroyed(false); | ||
| } | ||
| }).get(); | ||
| } catch (Throwable e) { | ||
| LOGGER.error("Failed to set destroyed test result", e); | ||
| testResults.setEjbBeanDestroyed(false); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * JBoss, Home of Professional Open Source | ||
| * Copyright 2019, Red Hat Inc., and individual contributors as indicated | ||
| * by the @authors tag. See the copyright.txt in the distribution for a | ||
| * full listing of individual contributors. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
|
|
||
| package org.jboss.as.test.integration.weld.context.application.lifecycle; | ||
|
|
||
| import org.jboss.logging.Logger; | ||
|
|
||
| import javax.ejb.ActivationConfigProperty; | ||
| import javax.ejb.MessageDriven; | ||
| import javax.jms.JMSDestinationDefinition; | ||
| import javax.jms.Message; | ||
| import javax.jms.MessageListener; | ||
| import javax.jms.TextMessage; | ||
|
|
||
|
|
||
| /** | ||
| * @author emmartins | ||
| */ | ||
| @JMSDestinationDefinition( | ||
| name = Mdb.JNDI_NAME, | ||
| interfaceName = "javax.jms.Queue", | ||
| destinationName = "jmsQueue" | ||
| ) | ||
| @MessageDriven(activationConfig = { | ||
| @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = Mdb.JNDI_NAME), | ||
| @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), | ||
| @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "auto-acknowledge") | ||
| }) | ||
| public class Mdb implements MessageListener { | ||
|
|
||
| private static final Logger LOGGER = Logger.getLogger(Mdb.class); | ||
|
|
||
| public static final String JNDI_NAME = "java:app/mdb"; | ||
|
|
||
| public void onMessage(Message message) { | ||
| try { | ||
| String text = ((TextMessage) message).getText(); | ||
| LOGGER.info("Received " + text); | ||
| } catch (Throwable e) { | ||
| LOGGER.error("Failed to receive or send message", e); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,125 @@ | ||
| /* | ||
| * JBoss, Home of Professional Open Source. | ||
| * Copyright (c) 2011, Red Hat, Inc., and individual contributors | ||
| * as indicated by the @author tags. See the copyright.txt file in the | ||
| * distribution for a full listing of individual contributors. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
| package org.jboss.as.test.integration.weld.context.application.lifecycle; | ||
|
|
||
| import org.jboss.logging.Logger; | ||
|
|
||
| import javax.annotation.Resource; | ||
| import javax.ejb.EJB; | ||
| import javax.enterprise.concurrent.ManagedExecutorService; | ||
| import javax.enterprise.context.ApplicationScoped; | ||
| import javax.enterprise.context.BeforeDestroyed; | ||
| import javax.enterprise.context.Destroyed; | ||
| import javax.enterprise.context.Initialized; | ||
| import javax.enterprise.context.control.RequestContextController; | ||
| import javax.enterprise.event.Observes; | ||
| import javax.inject.Inject; | ||
| import javax.jms.JMSContext; | ||
| import javax.jms.Queue; | ||
| import javax.naming.NamingException; | ||
| import javax.servlet.ServletException; | ||
| import javax.servlet.annotation.WebServlet; | ||
| import javax.servlet.http.HttpServlet; | ||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpServletResponse; | ||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * @author emmartins | ||
| */ | ||
| @WebServlet(name="Servlet", urlPatterns={"/FiveHundred"}) | ||
| public class Servlet extends HttpServlet { | ||
|
|
||
| private static final Logger LOGGER = Logger.getLogger(Servlet.class.getName()); | ||
|
|
||
| @Resource | ||
| private ManagedExecutorService executorService; | ||
|
|
||
| @Inject | ||
| private JMSContext jmsContext; | ||
|
|
||
| @Resource(lookup = Mdb.JNDI_NAME) | ||
| private Queue jmsQueue; | ||
|
|
||
| @Inject | ||
| private RequestContextController requestContextController; | ||
|
|
||
| @EJB(lookup = "java:global/TEST_RESULTS/TestResultsBean!org.jboss.as.test.integration.weld.context.application.lifecycle.TestResults") | ||
| private TestResults testResults; | ||
|
|
||
| public void onInitialized(@Observes @Initialized(ApplicationScoped.class) Object event) { | ||
| LOGGER.info("onInitialized!"); | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, false); | ||
| executorService.submit(() -> { | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, false); | ||
| testResults.setServletInitialized(true); | ||
| } catch (NamingException e) { | ||
| LOGGER.error("Failed to set initialized test result", e); | ||
| testResults.setServletInitialized(false); | ||
| } | ||
| }).get(); | ||
| } catch (Throwable e) { | ||
| LOGGER.error("Failed to set initialized test result", e); | ||
| testResults.setServletInitialized(false); | ||
| } | ||
| } | ||
|
|
||
| public void onBeforeDestroyed(@Observes @BeforeDestroyed(ApplicationScoped.class) Object object) { | ||
| LOGGER.info("onBeforeDestroyed!"); | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, false); | ||
| executorService.submit(() -> { | ||
| try { | ||
| Utils.sendMessage(jmsContext, jmsQueue, requestContextController); | ||
| Utils.lookupCommonResources(LOGGER, false); | ||
| testResults.setServletBeforeDestroyed(true); | ||
| } catch (NamingException e) { | ||
| LOGGER.error("Failed to set before destroyed test result", e); | ||
| testResults.setServletBeforeDestroyed(false); | ||
| } | ||
| }).get(); | ||
| } catch (Throwable e) { | ||
| LOGGER.error("Failed to set before destroyed test result", e); | ||
| testResults.setServletBeforeDestroyed(false); | ||
| } | ||
| } | ||
|
|
||
| public void onDestroyed(@Observes @Destroyed(ApplicationScoped.class) Object object) { | ||
| LOGGER.info("onDestroyed!"); | ||
| try { | ||
| executorService.submit(() -> testResults.setServletDestroyed(true)).get(); | ||
| } catch (Throwable e) { | ||
| LOGGER.error("Failed to set destroyed test result", e); | ||
| testResults.setServletDestroyed(false); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
| resp.sendError(500); | ||
| } | ||
| } |
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * JBoss, Home of Professional Open Source | ||
| * Copyright 2019, Red Hat Inc., and individual contributors as indicated | ||
| * by the @authors tag. See the copyright.txt in the distribution for a | ||
| * full listing of individual contributors. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
|
|
||
| package org.jboss.as.test.integration.weld.context.application.lifecycle; | ||
|
|
||
| import javax.ejb.Remote; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| /** | ||
| * @author emmartins | ||
| */ | ||
| @Remote | ||
| public interface TestResults { | ||
|
|
||
| boolean isCdiBeanInitialized(); | ||
|
|
||
| void setCdiBeanInitialized(boolean cdiBeanInitialized); | ||
|
|
||
| boolean isEjbBeanInitialized(); | ||
|
|
||
| void setEjbBeanInitialized(boolean ejbBeanInitialized); | ||
|
|
||
| boolean isServletInitialized(); | ||
|
|
||
| void setServletInitialized(boolean servletInitialized); | ||
|
|
||
|
|
||
| boolean isCdiBeanBeforeDestroyed(); | ||
|
|
||
| void setCdiBeanBeforeDestroyed(boolean cdiBeanBeforeDestroyed); | ||
|
|
||
| boolean isEjbBeanBeforeDestroyed(); | ||
|
|
||
| void setEjbBeanBeforeDestroyed(boolean ejbBeanBeforeDestroyed); | ||
|
|
||
| boolean isServletBeforeDestroyed(); | ||
|
|
||
| void setServletBeforeDestroyed(boolean servletBeforeDestroyed); | ||
|
|
||
|
|
||
| boolean isCdiBeanDestroyed(); | ||
|
|
||
| void setCdiBeanDestroyed(boolean cdiBeanDestroyed); | ||
|
|
||
| boolean isEjbBeanDestroyed(); | ||
|
|
||
| void setEjbBeanDestroyed(boolean ejbBeanDestroyed); | ||
|
|
||
| boolean isServletDestroyed(); | ||
|
|
||
| void setServletDestroyed(boolean servletDestroyed); | ||
|
|
||
| void setup(int latchCount); | ||
|
|
||
| void await(long timeout, TimeUnit timeUnit) throws InterruptedException; | ||
| } |
| @@ -0,0 +1,155 @@ | ||
| /* | ||
| * JBoss, Home of Professional Open Source | ||
| * Copyright 2019, Red Hat Inc., and individual contributors as indicated | ||
| * by the @authors tag. See the copyright.txt in the distribution for a | ||
| * full listing of individual contributors. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
|
|
||
| package org.jboss.as.test.integration.weld.context.application.lifecycle; | ||
|
|
||
| import javax.ejb.Singleton; | ||
| import javax.ejb.Startup; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| /** | ||
| * @author emmartins | ||
| */ | ||
| @Startup | ||
| @Singleton | ||
| public class TestResultsBean implements TestResults { | ||
|
|
||
| private CountDownLatch latch; | ||
|
|
||
| private boolean cdiBeanInitialized; | ||
| private boolean cdiBeanBeforeDestroyed; | ||
| private boolean cdiBeanDestroyed; | ||
|
|
||
| private boolean ejbBeanInitialized; | ||
| private boolean ejbBeanBeforeDestroyed; | ||
| private boolean ejbBeanDestroyed; | ||
|
|
||
| private boolean servletInitialized; | ||
| private boolean servletBeforeDestroyed; | ||
| private boolean servletDestroyed; | ||
|
|
||
| public boolean isCdiBeanInitialized() { | ||
| return cdiBeanInitialized; | ||
| } | ||
|
|
||
| public void setCdiBeanInitialized(boolean cdiBeanInitialized) { | ||
| this.cdiBeanInitialized = cdiBeanInitialized; | ||
| latch.countDown(); | ||
| } | ||
|
|
||
| public boolean isEjbBeanInitialized() { | ||
| return ejbBeanInitialized; | ||
| } | ||
|
|
||
| public void setEjbBeanInitialized(boolean ejbBeanInitialized) { | ||
| this.ejbBeanInitialized = ejbBeanInitialized; | ||
| latch.countDown(); | ||
| } | ||
|
|
||
| public boolean isServletInitialized() { | ||
| return servletInitialized; | ||
| } | ||
|
|
||
| public void setServletInitialized(boolean servletInitialized) { | ||
| this.servletInitialized = servletInitialized; | ||
| latch.countDown(); | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| public boolean isCdiBeanBeforeDestroyed() { | ||
| return cdiBeanBeforeDestroyed; | ||
| } | ||
|
|
||
| public void setCdiBeanBeforeDestroyed(boolean cdiBeanBeforeDestroyed) { | ||
| this.cdiBeanBeforeDestroyed = cdiBeanBeforeDestroyed; | ||
| latch.countDown(); | ||
| } | ||
|
|
||
| public boolean isEjbBeanBeforeDestroyed() { | ||
| return ejbBeanBeforeDestroyed; | ||
| } | ||
|
|
||
| public void setEjbBeanBeforeDestroyed(boolean ejbBeanBeforeDestroyed) { | ||
| this.ejbBeanBeforeDestroyed = ejbBeanBeforeDestroyed; | ||
| latch.countDown(); | ||
| } | ||
|
|
||
| public boolean isServletBeforeDestroyed() { | ||
| return servletBeforeDestroyed; | ||
| } | ||
|
|
||
| public void setServletBeforeDestroyed(boolean servletBeforeDestroyed) { | ||
| this.servletBeforeDestroyed = servletBeforeDestroyed; | ||
| latch.countDown(); | ||
| } | ||
|
|
||
| // --- | ||
|
|
||
| public boolean isCdiBeanDestroyed() { | ||
| return cdiBeanDestroyed; | ||
| } | ||
|
|
||
| public void setCdiBeanDestroyed(boolean cdiBeanDestroyed) { | ||
| this.cdiBeanDestroyed = cdiBeanDestroyed; | ||
| latch.countDown(); | ||
| } | ||
|
|
||
| public boolean isEjbBeanDestroyed() { | ||
| return ejbBeanDestroyed; | ||
| } | ||
|
|
||
| public void setEjbBeanDestroyed(boolean ejbBeanDestroyed) { | ||
| this.ejbBeanDestroyed = ejbBeanDestroyed; | ||
| latch.countDown(); | ||
| } | ||
|
|
||
| public boolean isServletDestroyed() { | ||
| return servletDestroyed; | ||
| } | ||
|
|
||
| public void setServletDestroyed(boolean servletDestroyed) { | ||
| this.servletDestroyed = servletDestroyed; | ||
| latch.countDown(); | ||
| } | ||
|
|
||
| // -- | ||
|
|
||
| public void setup(int latchCount) { | ||
| if (latch != null) { | ||
| throw new IllegalStateException(); | ||
| } | ||
| latch = new CountDownLatch(latchCount); | ||
| } | ||
|
|
||
| public void await(long timeout, TimeUnit timeUnit) throws InterruptedException { | ||
| if (latch == null) { | ||
| throw new IllegalStateException(); | ||
| } | ||
| try { | ||
| latch.await(timeout, timeUnit); | ||
| } finally { | ||
| latch = null; | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * JBoss, Home of Professional Open Source | ||
| * Copyright 2019, Red Hat Inc., and individual contributors as indicated | ||
| * by the @authors tag. See the copyright.txt in the distribution for a | ||
| * full listing of individual contributors. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
|
|
||
| package org.jboss.as.test.integration.weld.context.application.lifecycle; | ||
|
|
||
| import org.jboss.logging.Logger; | ||
|
|
||
| import javax.enterprise.context.control.RequestContextController; | ||
| import javax.jms.JMSContext; | ||
| import javax.jms.JMSProducer; | ||
| import javax.jms.Queue; | ||
| import javax.naming.InitialContext; | ||
| import javax.naming.NamingException; | ||
|
|
||
| /** | ||
| * @author emmartins | ||
| */ | ||
| public interface Utils { | ||
|
|
||
| static void sendMessage(JMSContext jmsContext, Queue jmsQueue, RequestContextController requestContextController) { | ||
| requestContextController.activate(); | ||
| final JMSProducer producer = jmsContext.createProducer(); | ||
| producer.send(jmsQueue, "a message"); | ||
| requestContextController.deactivate(); | ||
| } | ||
|
|
||
| static void lookupCommonResources(Logger logger, boolean statelessEjb) throws NamingException { | ||
| final InitialContext initialContext = new InitialContext(); | ||
| // lookup app name | ||
| logger.info("java:app/AppName: "+initialContext.lookup("java:app/AppName")); | ||
| // lookup module name | ||
| logger.info("java:module/ModuleName: "+initialContext.lookup("java:module/ModuleName")); | ||
| // lookup default EE concurrency resources | ||
| logger.info("java:comp/DefaultContextService: "+initialContext.lookup("java:comp/DefaultContextService")); | ||
| logger.info("java:comp/DefaultManagedExecutorService: "+initialContext.lookup("java:comp/DefaultManagedExecutorService")); | ||
| logger.info("java:comp/DefaultManagedScheduledExecutorService: "+initialContext.lookup("java:comp/DefaultManagedScheduledExecutorService")); | ||
| logger.info("java:comp/DefaultManagedThreadFactory: "+initialContext.lookup("java:comp/DefaultManagedThreadFactory")); | ||
| // lookup default datasource | ||
| logger.info("java:comp/DefaultDataSource: "+initialContext.lookup("java:comp/DefaultDataSource")); | ||
| // lookup default jms connection factory | ||
| logger.info("java:comp/DefaultJMSConnectionFactory: "+initialContext.lookup("java:comp/DefaultJMSConnectionFactory")); | ||
| // lookup tx resources | ||
| logger.info("java:comp/TransactionSynchronizationRegistry: "+initialContext.lookup("java:comp/TransactionSynchronizationRegistry")); | ||
| if (!statelessEjb) { | ||
| logger.info("java:comp/UserTransaction: "+initialContext.lookup("java:comp/UserTransaction")); | ||
| } else { | ||
| logger.info("java:comp/EJBContext: "+initialContext.lookup("java:comp/EJBContext")); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,167 @@ | ||
| /* | ||
| * JBoss, Home of Professional Open Source. | ||
| * Copyright 2019, Red Hat, Inc., and individual contributors | ||
| * as indicated by the @author tags. See the copyright.txt file in the | ||
| * distribution for a full listing of individual contributors. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
|
|
||
| package org.jboss.as.weld.deployment.processors; | ||
|
|
||
| import org.jboss.as.controller.capability.CapabilityServiceSupport; | ||
| import org.jboss.as.ee.structure.DeploymentType; | ||
| import org.jboss.as.ee.structure.DeploymentTypeMarker; | ||
|
|
||
| import org.jboss.as.server.deployment.Attachments; | ||
| import org.jboss.as.server.deployment.DeploymentPhaseContext; | ||
| import org.jboss.as.server.deployment.DeploymentUnit; | ||
| import org.jboss.as.server.deployment.DeploymentUnitProcessingException; | ||
| import org.jboss.as.server.deployment.DeploymentUnitProcessor; | ||
| import org.jboss.as.server.deployment.SetupAction; | ||
| import org.jboss.as.weld.WeldCapability; | ||
| import org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl; | ||
| import org.jboss.as.weld.deployment.BeanDeploymentModule; | ||
| import org.jboss.as.weld.deployment.WeldAttachments; | ||
| import org.jboss.as.weld.logging.WeldLogger; | ||
|
|
||
| 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 javax.enterprise.event.Reception; | ||
| import javax.enterprise.event.TransactionPhase; | ||
| import javax.enterprise.inject.spi.Extension; | ||
| import javax.enterprise.inject.spi.ObserverMethod; | ||
| import javax.enterprise.inject.spi.ProcessObserverMethod; | ||
| import java.lang.annotation.Annotation; | ||
| import java.lang.reflect.Type; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import static org.jboss.as.weld.Capabilities.WELD_CAPABILITY_NAME; | ||
|
|
||
| /** | ||
| * Processor that registers a CDI portable extension for EAR deployments, which adds support for EE facilities, to CDI app context lifecycle event handlers. | ||
| * | ||
| * @author emmartins | ||
| */ | ||
| public class EarApplicationScopedObserverMethodProcessor implements DeploymentUnitProcessor { | ||
|
|
||
| @Override | ||
| public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { | ||
| final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); | ||
| if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) { | ||
| // ear deployment only processor | ||
| return; | ||
| } | ||
| final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT); | ||
| if (support.hasCapability(WELD_CAPABILITY_NAME)) { | ||
| final WeldCapability api = support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class).get(); | ||
| if (api.isPartOfWeldDeployment(deploymentUnit)) { | ||
| api.registerExtensionInstance(new PortableExtension(deploymentUnit), deploymentUnit); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void undeploy(DeploymentUnit context) { | ||
| } | ||
|
|
||
| private static class PortableExtension implements Extension { | ||
|
|
||
| private final DeploymentUnit deploymentUnit; | ||
|
|
||
| private PortableExtension(DeploymentUnit deploymentUnit) { | ||
| this.deploymentUnit = deploymentUnit; | ||
| } | ||
|
|
||
| public <Object, X> void processObserverMethod(@Observes ProcessObserverMethod<Object, X> event) { | ||
| final ObserverMethod<Object> method = event.getObserverMethod(); | ||
| for (Annotation a : method.getObservedQualifiers()) { | ||
| // only process @Initialized(ApplicationScoped.class), @BeforeDestroyed(ApplicationScoped.class) and @Destroyed(ApplicationScoped.class) | ||
| if ((a instanceof Initialized && ((Initialized) a).value().equals(ApplicationScoped.class)) || (a instanceof BeforeDestroyed && ((BeforeDestroyed) a).value().equals(ApplicationScoped.class)) || (a instanceof Destroyed && ((Destroyed) a).value().equals(ApplicationScoped.class))) { | ||
| // if there are setup actions for the bean's class deployable unit wrap the observer method | ||
| final DeploymentUnit beanDeploymentUnit = getBeanDeploymentUnit(method.getBeanClass().getName()); | ||
| if (beanDeploymentUnit != null) { | ||
| final List<SetupAction> setupActions = WeldDeploymentProcessor.getSetupActions(beanDeploymentUnit); | ||
| if (!setupActions.isEmpty()) { | ||
| event.setObserverMethod(new ObserverMethod<Object>() { | ||
| @Override | ||
| public Class<?> getBeanClass() { | ||
| return method.getBeanClass(); | ||
| } | ||
|
|
||
| @Override | ||
| public Type getObservedType() { | ||
| return method.getObservedType(); | ||
| } | ||
|
|
||
| @Override | ||
| public Set<Annotation> getObservedQualifiers() { | ||
| return method.getObservedQualifiers(); | ||
| } | ||
|
|
||
| @Override | ||
| public Reception getReception() { | ||
| return method.getReception(); | ||
| } | ||
|
|
||
| @Override | ||
| public TransactionPhase getTransactionPhase() { | ||
| return method.getTransactionPhase(); | ||
| } | ||
|
|
||
| @Override | ||
| public void notify(Object event) { | ||
| try { | ||
| for (SetupAction action : setupActions) { | ||
| action.setup(null); | ||
| } | ||
| method.notify(event); | ||
| } finally { | ||
| for (SetupAction action : setupActions) { | ||
| try { | ||
| action.teardown(null); | ||
| } catch (Exception e) { | ||
| WeldLogger.DEPLOYMENT_LOGGER.exceptionClearingThreadState(e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private DeploymentUnit getBeanDeploymentUnit(String beanClass) { | ||
| for (DeploymentUnit subDeploymentUnit : deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS)) { | ||
| final BeanDeploymentModule beanDeploymentModule = subDeploymentUnit.getAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE); | ||
| if (beanDeploymentModule != null) { | ||
| for (BeanDeploymentArchiveImpl beanDeploymentArchive : beanDeploymentModule.getBeanDeploymentArchives()) { | ||
| if (beanDeploymentArchive.getBeanClasses().contains(beanClass)) { | ||
| return subDeploymentUnit; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
| } |