[jboss-cvs] JBossAS SVN: r74088 - in branches/JBPAPP_4_2_0_GA_CP/ejb3: src/main/org/jboss/ejb3/mdb and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 4 08:08:19 EDT 2008
Author: wolfc
Date: 2008-06-04 08:08:19 -0400 (Wed, 04 Jun 2008)
New Revision: 74088
Added:
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree987/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree987/DormantMDB.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree987/unit/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree987/unit/DeliveryActiveUnitTestCase.java
Modified:
branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MdbDelegateWrapper.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MdbDelegateWrapperMBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/inflow/JBossMessageEndpointFactory.java
Log:
EJBTHREE-987 JBPAPP-856: DeliveryActive activation config property
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml 2008-06-04 11:24:48 UTC (rev 74087)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml 2008-06-04 12:08:19 UTC (rev 74088)
@@ -1990,6 +1990,13 @@
<build-simple-jar name="ejbthree986"/>
</target>
+ <target name="ejbthree987"
+ description="Builds a simple jar files."
+ depends="compile-classes">
+
+ <build-simple-jar name="ejbthree987"/>
+ </target>
+
<target name="ejbthree994"
description="Builds a simple jar files."
depends="compile-classes">
@@ -3725,7 +3732,9 @@
<target name="jars" depends="ejbthree1090, mdbsessionpoolclear, ejbthree1092, removedislocal, statelesscreation, defaultremotebindings, localfromremote, clusteredjms, entityoptimisticlocking, concurrentnaming, propertyreplacement, persistenceunits, invalidtxmdb, descriptortypo, libdeployment, homeinterface, servicexmbean, arjuna, mdbtransactions, unauthenticatedprincipal, clusteredservice, invoker, classloader,
circulardependency, jsp, timerdependency, servicedependency, servlet, stateless14, webservices, ear, ejbthree440,
- ejbthree454, ejbthree653, ejbthree670, ejbthree712, ejbthree724, ejbthree751, ejbthree785, ejbthree832, ejbthree921,
+ ejbthree454, ejbthree653, ejbthree670, ejbthree712, ejbthree724, ejbthree751, ejbthree785, ejbthree832,
+ ejbthree987,
+ ejbthree921,
ejbthree959, ejbthree963, ejbthree994, ejbthree1023, ejbthree1025, ejbthree1062,
jbas4489, epcpropagation, jaccpropagation,
aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency, jaxws,
@@ -4327,6 +4336,9 @@
<param name="test" value="ejbthree963"/>
</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">
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MdbDelegateWrapper.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MdbDelegateWrapper.java 2008-06-04 11:24:48 UTC (rev 74087)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MdbDelegateWrapper.java 2008-06-04 12:08:19 UTC (rev 74088)
@@ -48,8 +48,28 @@
return ((MDB)delegate).getMaxMessages();
}
+ private MDB getMDB()
+ {
+ return (MDB) delegate;
+ }
+
public int getKeepAliveMillis()
{
return ((MDB)delegate).getKeepAliveMillis();
}
+
+ public boolean isDeliveryActive()
+ {
+ return getMDB().isDeliveryActive();
+ }
+
+ public void startDelivery()
+ {
+ getMDB().startDelivery();
+ }
+
+ public void stopDelivery()
+ {
+ getMDB().stopDelivery();
+ }
}
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MdbDelegateWrapperMBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MdbDelegateWrapperMBean.java 2008-06-04 11:24:48 UTC (rev 74087)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MdbDelegateWrapperMBean.java 2008-06-04 12:08:19 UTC (rev 74088)
@@ -35,4 +35,10 @@
int getMaxMessages();
int getKeepAliveMillis();
+
+ boolean isDeliveryActive();
+
+ void startDelivery();
+
+ void stopDelivery();
}
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java 2008-06-04 11:24:48 UTC (rev 74087)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java 2008-06-04 12:08:19 UTC (rev 74088)
@@ -154,6 +154,18 @@
TimerServiceFactory.getInstance().restoreTimerService(timerService);
}
+ protected void startDelivery()
+ {
+ try
+ {
+ messageEndpointFactory.activate();
+ }
+ catch(DeploymentException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
protected void innerStart() throws Exception
{
log.debug("Initializing");
@@ -162,6 +174,11 @@
jmsCreate();
}
+ protected boolean isDeliveryActive()
+ {
+ return messageEndpointFactory.isDeliveryActive();
+ }
+
public ObjectName getJmxName()
{
ObjectName jmxName = null;
@@ -292,6 +309,11 @@
super.stop();
}
+ protected void stopDelivery()
+ {
+ messageEndpointFactory.deactivate();
+ }
+
protected void stopProxies() throws Exception
{
messageEndpointFactory.stop();
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/inflow/JBossMessageEndpointFactory.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/inflow/JBossMessageEndpointFactory.java 2008-06-04 11:24:48 UTC (rev 74087)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/inflow/JBossMessageEndpointFactory.java 2008-06-04 12:08:19 UTC (rev 74088)
@@ -43,6 +43,7 @@
import org.jboss.ejb3.KernelAbstractionFactory;
import org.jboss.ejb3.tx.TxUtil;
import org.jboss.ejb3.mdb.MessagingContainer;
+import org.jboss.metadata.ActivationConfigPropertyMetaData;
import org.jboss.mx.util.JMXExceptionDecoder;
import org.jboss.logging.Logger;
@@ -59,6 +60,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();
@@ -84,6 +94,12 @@
/** The next proxy id */
protected SynchronizedInt nextProxyId = new SynchronizedInt(0);
+
+ /** 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 --------------------------------------------------------
@@ -160,6 +176,11 @@
}
}
+ public boolean isDeliveryActive()
+ {
+ return deliveryActive;
+ }
+
public boolean isDeliveryTransacted(Method method) throws NoSuchMethodException
{
TransactionManagementType mtype = TxUtil.getTransactionManagementType(container);
@@ -190,14 +211,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 -------------------------------
@@ -273,7 +300,14 @@
protected void createActivationSpec() throws DeploymentException
{
properties = new HashMap(container.getActivationConfigProperties());
-
+
+ // Filter out the MDB features
+ if(properties.containsKey(ACTIVATE_ON_STARTUP))
+ {
+ this.activateOnStartup = Boolean.parseBoolean(((ActivationConfigPropertyMetaData) properties.get(ACTIVATE_ON_STARTUP)).getValue());
+ properties.remove(ACTIVATE_ON_STARTUP);
+ }
+
Object[] params = new Object[]
{
messagingTypeClass,
@@ -297,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 +347,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
{
@@ -328,5 +369,6 @@
log.warn("Endpoint activation failed ra=" + resourceAdapterObjectName +
" activationSpec=" + activationSpec, t);
}
+ deliveryActive = false;
}
}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree987/DormantMDB.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree987/DormantMDB.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree987/DormantMDB.java 2008-06-04 12:08:19 UTC (rev 74088)
@@ -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);
+ }
+ }
+}
Property changes on: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree987/DormantMDB.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree987/unit/DeliveryActiveUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree987/unit/DeliveryActiveUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree987/unit/DeliveryActiveUnitTestCase.java 2008-06-04 12:08:19 UTC (rev 74088)
@@ -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");
+ }
+}
Property changes on: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree987/unit/DeliveryActiveUnitTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the jboss-cvs-commits
mailing list