[jboss-cvs] JBossAS SVN: r84054 - in projects/ejb3/trunk: core/src/main/java/org/jboss/ejb3/mdb/inflow and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Feb 10 07:57:34 EST 2009
Author: wolfc
Date: 2009-02-10 07:57:34 -0500 (Tue, 10 Feb 2009)
New Revision: 84054
Added:
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree987/
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree987/DormantMDB.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree987/unit/
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree987/unit/DeliveryActiveUnitTestCase.java
projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree987/
projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree987/META-INF/
projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree987/META-INF/jboss.xml
Modified:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingDelegateWrapper.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingDelegateWrapperMBean.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/inflow/JBossMessageEndpointFactory.java
projects/ejb3/trunk/testsuite/build-test.xml
Log:
EJBTHREE-987: DeliveryActive activation config property (r74088)
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingContainer.java 2009-02-10 12:26:10 UTC (rev 84053)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingContainer.java 2009-02-10 12:57:34 UTC (rev 84054)
@@ -178,11 +178,28 @@
timerServiceFactory.restoreTimerService(timerService);
}
+ protected void startDelivery()
+ {
+ try
+ {
+ messageEndpointFactory.activate();
+ }
+ catch(DeploymentException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
protected void innerStart() throws Exception
{
log.debug("Initializing");
}
+ protected boolean isDeliveryActive()
+ {
+ return messageEndpointFactory.isDeliveryActive();
+ }
+
public ObjectName getJmxName()
{
ObjectName jmxName = null;
@@ -311,6 +328,11 @@
super.lockedStop();
}
+ protected void stopDelivery()
+ {
+ messageEndpointFactory.deactivate();
+ }
+
protected void stopProxies() throws Exception
{
messageEndpointFactory.stop();
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingDelegateWrapper.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingDelegateWrapper.java 2009-02-10 12:26:10 UTC (rev 84053)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingDelegateWrapper.java 2009-02-10 12:57:34 UTC (rev 84054)
@@ -56,4 +56,19 @@
{
return ((MessagingContainer)delegate).getKeepAliveMillis();
}
+
+ public boolean isDeliveryActive()
+ {
+ return delegate.isDeliveryActive();
+ }
+
+ public void startDelivery()
+ {
+ delegate.startDelivery();
+ }
+
+ public void stopDelivery()
+ {
+ delegate.stopDelivery();
+ }
}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingDelegateWrapperMBean.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingDelegateWrapperMBean.java 2009-02-10 12:26:10 UTC (rev 84053)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/MessagingDelegateWrapperMBean.java 2009-02-10 12:57:34 UTC (rev 84054)
@@ -35,4 +35,10 @@
int getMaxMessages();
int getKeepAliveMillis();
+
+ boolean isDeliveryActive();
+
+ void startDelivery();
+
+ void stopDelivery();
}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/inflow/JBossMessageEndpointFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/inflow/JBossMessageEndpointFactory.java 2009-02-10 12:26:10 UTC (rev 84053)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/mdb/inflow/JBossMessageEndpointFactory.java 2009-02-10 12:57:34 UTC (rev 84054)
@@ -57,6 +57,15 @@
{
private static final Logger log = Logger.getLogger(JBossMessageEndpointFactory.class);
+ /*
+ * For backwards compatibility it's called DeliveryActive.
+ * See http://wiki.jboss.org/wiki/ConfigJBossMDB
+ */
+ /**
+ * The activation config property name to specify activation.
+ */
+ private static final String ACTIVATE_ON_STARTUP = "DeliveryActive";
+
/** Whether trace is enabled */
protected boolean trace = log.isTraceEnabled();
@@ -80,6 +89,12 @@
/** The interfaces */
protected Class[] interfaces;
+
+ /** Whether the MDB should make the subscription at initial deployment or wait for start/stopDelivery on the MBean */
+ private boolean activateOnStartup = true;
+
+ /** Is the delivery currently active? */
+ private boolean deliveryActive = false;
// Static --------------------------------------------------------
@@ -156,6 +171,11 @@
}
}
+ public boolean isDeliveryActive()
+ {
+ return deliveryActive;
+ }
+
public boolean isDeliveryTransacted(Method method) throws NoSuchMethodException
{
TransactionManagementType mtype = TxUtil.getTransactionManagementType(container.getAdvisor());
@@ -186,14 +206,20 @@
// Set up proxy parameters
// Set the interfaces
interfaces = new Class[] { MessageEndpoint.class, messagingTypeClass};
- // Activate
- activate();
+ if(activateOnStartup)
+ {
+ // Activate
+ activate();
+ }
}
public void stop() throws Exception
{
- // Deactivate
- deactivate();
+ if(deliveryActive)
+ {
+ // Deactivate
+ deactivate();
+ }
}
// ContainerService implementation -------------------------------
@@ -276,6 +302,13 @@
properties.put(property.getName(), new org.jboss.metadata.ActivationConfigPropertyMetaData(property));
}
+ // Filter out the MDB features
+ if(properties.containsKey(ACTIVATE_ON_STARTUP))
+ {
+ this.activateOnStartup = Boolean.parseBoolean(properties.get(ACTIVATE_ON_STARTUP).getValue());
+ properties.remove(ACTIVATE_ON_STARTUP);
+ }
+
Object[] params = new Object[]
{
messagingTypeClass,
@@ -298,8 +331,11 @@
*
* @throws DeploymentException for any error
*/
- protected void activate() throws DeploymentException
- {
+ public synchronized void activate() throws DeploymentException
+ {
+ if(deliveryActive)
+ throw new IllegalStateException("Delivery is already active");
+
Object[] params = new Object[] { this, activationSpec };
try
{
@@ -310,13 +346,17 @@
DeploymentException.rethrowAsDeploymentException("Endpoint activation failed ra=" + resourceAdapterObjectName +
" activationSpec=" + activationSpec, t);
}
+ deliveryActive = true;
}
/**
* Deactivate
*/
- protected void deactivate()
+ public synchronized void deactivate()
{
+ if(!deliveryActive)
+ throw new IllegalStateException("Delivery is already deactivated");
+
Object[] params = new Object[] { this, activationSpec };
try
{
@@ -327,5 +367,6 @@
log.warn("Endpoint activation failed ra=" + resourceAdapterObjectName +
" activationSpec=" + activationSpec, t);
}
+ deliveryActive = false;
}
}
Modified: projects/ejb3/trunk/testsuite/build-test.xml
===================================================================
--- projects/ejb3/trunk/testsuite/build-test.xml 2009-02-10 12:26:10 UTC (rev 84053)
+++ projects/ejb3/trunk/testsuite/build-test.xml 2009-02-10 12:57:34 UTC (rev 84054)
@@ -2237,6 +2237,13 @@
<build-simple-jar name="ejbthree986"/>
</target>
+ <target name="ejbthree987"
+ description="Builds a simple jar files."
+ >
+
+ <build-simple-jar name="ejbthree987"/>
+ </target>
+
<target name="ejbthree994"
description="Builds a simple jar files."
>
@@ -4229,6 +4236,7 @@
ejbthree832, ejbthree921, ejbthree936,
ejbthree939,
ejbthree953, ejbthree957, ejbthree959, ejbthree963, ejbthree967, ejbthree971, ejbthree973, ejbthree985, ejbthree986,
+ ejbthree987,
ejbthree989, ejbthree994, ejbthree1020, ejbthree1023, ejbthree1025,
ejbthree1028,
ejbthree1040,
@@ -4960,6 +4968,9 @@
<param name="test" value="ejbthree986"/>
</antcall>
<antcall target="test" inheritRefs="true">
+ <param name="test" value="ejbthree987"/>
+ </antcall>
+ <antcall target="test" inheritRefs="true">
<param name="test" value="ejbthree994"/>
</antcall>
<antcall target="test" inheritRefs="true">
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree987/DormantMDB.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree987/DormantMDB.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree987/DormantMDB.java 2009-02-10 12:57:34 UTC (rev 84054)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, 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.ejb3.test.ejbthree987;
+
+import java.util.Date;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+
+/**
+ * This MDB starts up dormant.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at MessageDriven(activationConfig =
+{
+ @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName="destination", propertyValue="queue/ejbthree987"),
+ @ActivationConfigProperty(propertyName="DeliveryActive", propertyValue="false")
+})
+public class DormantMDB implements MessageListener
+{
+ @Resource(mappedName="ConnectionFactory")
+ private QueueConnectionFactory factory;
+
+ private QueueConnection connection;
+ private QueueSession session;
+ private QueueSender sender;
+
+ public void onMessage(Message message)
+ {
+ try
+ {
+ Message reply = session.createObjectMessage(new Date());
+ sender.send(message.getJMSReplyTo(), reply);
+ }
+ catch (JMSException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @PostConstruct
+ public void postConstruct()
+ {
+ try
+ {
+ connection = factory.createQueueConnection();
+ session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+ sender = session.createSender(null);
+ }
+ catch(JMSException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @PreDestroy
+ public void preDestroy()
+ {
+ try
+ {
+ if(sender != null)
+ sender.close();
+ if(session != null)
+ session.close();
+ if(connection != null)
+ connection.close();
+ }
+ catch(JMSException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree987/unit/DeliveryActiveUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree987/unit/DeliveryActiveUnitTestCase.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree987/unit/DeliveryActiveUnitTestCase.java 2009-02-10 12:57:34 UTC (rev 84054)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, 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.ejb3.test.ejbthree987.unit;
+
+import java.util.Date;
+
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.TemporaryQueue;
+import javax.jms.TextMessage;
+import javax.management.Attribute;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossTestCase;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DeliveryActiveUnitTestCase extends JBossTestCase
+{
+ public DeliveryActiveUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ serverFound();
+ }
+
+ public void test1() throws Exception
+ {
+ InitialContext ctx = new InitialContext();
+ Queue queue = (Queue) ctx.lookup("queue/ejbthree987");
+ QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
+ QueueConnection connection = factory.createQueueConnection();
+ try
+ {
+ connection.start();
+
+ QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+
+ TemporaryQueue replyQueue = session.createTemporaryQueue();
+ QueueReceiver receiver = session.createReceiver(replyQueue);
+
+ QueueSender sender = session.createSender(queue);
+ TextMessage message = session.createTextMessage("Hello world");
+ message.setJMSReplyTo(replyQueue);
+ sender.send(message);
+ sender.close();
+
+ long whenSent = System.currentTimeMillis();
+
+ MBeanServerConnection server = getServer();
+ ObjectName name = new ObjectName("jboss.j2ee:jar=ejbthree987.jar,name=DormantMDB,service=EJB3");
+ assertFalse((Boolean) server.getAttribute(name, "DeliveryActive"));
+
+ Message msg = receiver.receive(5000);
+ assertNull(msg);
+
+ server.invoke(name, "startDelivery", null, null);
+ assertTrue((Boolean) server.getAttribute(name, "DeliveryActive"));
+
+ msg = receiver.receive(5000);
+ assertNotNull(msg);
+
+ Date date = (Date) ((ObjectMessage) msg).getObject();
+ long whenProcessed = date.getTime();
+
+ // The message should have been processed after we started delivery
+ assertTrue((whenProcessed - whenSent) > 4000);
+
+ receiver.close();
+ session.close();
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(DeliveryActiveUnitTestCase.class, "ejbthree987.jar");
+ }
+}
Added: projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree987/META-INF/jboss.xml
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree987/META-INF/jboss.xml (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree987/META-INF/jboss.xml 2009-02-10 12:57:34 UTC (rev 84054)
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+<jboss
+ xmlns="http://www.jboss.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee
+ http://www.jboss.org/j2ee/schema/jboss_5_0.xsd"
+ version="3.0">
+ <enterprise-beans>
+ <message-driven>
+ <ejb-name>DormantMDB</ejb-name>
+ <create-destination>true</create-destination>
+ </message-driven>
+ </enterprise-beans>
+</jboss>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list