[jboss-svn-commits] JBL Code SVN: r12922 - in labs/jbossesb/trunk/product: rosetta/src/org/jboss/internal/soa/esb/services/registry and 9 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jun 28 09:41:44 EDT 2007
Author: kurt.stam at jboss.com
Date: 2007-06-28 09:41:44 -0400 (Thu, 28 Jun 2007)
New Revision: 12922
Added:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/FirstAvailable.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/LoadBalancePolicy.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/RandomRobin.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/RoundRobin.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/ServiceClusterInfo.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/ServiceClusterInfoImpl.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/MockMessageComposer.java
Modified:
labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml
labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/MockRegistryImpl.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Environment.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerUtil.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/RegistryUtil.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageDeliveryAdapter.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/UncomposedMessageDeliveryAdapter.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/services/registry/Registry.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/MockCourierFactory.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/MockRegistry.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/GroovyGatewayUnitTest.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListenerUnitTest.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/MessageDeliveryAdapterUnitTest.java
Log:
JBESB-581 and JBESB-429, Adding stateless failover and roundrobin loadbalancing.
Modified: labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml
===================================================================
--- labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml 2007-06-28 13:35:12 UTC (rev 12921)
+++ labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml 2007-06-28 13:41:44 UTC (rev 12922)
@@ -34,6 +34,7 @@
<property name="org.jboss.soa.esb.jndi.server.context.factory" value="org.jnp.interfaces.NamingContextFactory"/>
<property name="org.jboss.soa.esb.jndi.server.url" value="localhost"/>
<property name="org.jboss.soa.esb.persistence.connection.factory" value="org.jboss.internal.soa.esb.persistence.format.MessageStoreFactoryImpl"/>
+ <property name="org.jboss.soa.esb.loadbalancer.policy" value="org.jboss.soa.esb.listeners.ha.RoundRobin"/>
</properties>
<properties name="registry">
<property name="org.jboss.soa.esb.registry.queryManagerURI" value="org.apache.juddi.registry.local.InquiryService#inquire"/>
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java 2007-06-28 13:35:12 UTC (rev 12921)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -28,6 +28,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Properties;
import java.util.Set;
@@ -293,9 +294,9 @@
* {@inheritDoc}
* @return collection services
*/
- public Collection<String> findAllServices() throws RegistryException
+ public List<String> findAllServices() throws RegistryException
{
- Collection<String> serviceNames = new ArrayList<String>();
+ List<String> serviceNames = new ArrayList<String>();
try {
Collection services = getJBossESBOrganization().getServices();
for (Iterator i=services.iterator();i.hasNext();) {
@@ -313,9 +314,9 @@
* @param serviceType
* @return collection services
*/
- public Collection<String> findServices(String category) throws RegistryException
+ public List<String> findServices(String category) throws RegistryException
{
- Collection<String>serviceNames = new ArrayList<String>();
+ List<String>serviceNames = new ArrayList<String>();
try {
Collection<Service>services = findServicesForCategory(category);
for (Iterator<Service> i=services.iterator();i.hasNext();) {
@@ -332,9 +333,9 @@
* @param service
* @return
*/
- public Collection<EPR> findEPRs(String category, String serviceName) throws RegistryException
+ public List<EPR> findEPRs(String category, String serviceName) throws RegistryException
{
- Collection<EPR> eprs = new ArrayList<EPR>();
+ List<EPR> eprs = new ArrayList<EPR>();
Connection connection = JAXRRegistryImpl.getConnection();
try {
Service service = findService(category, serviceName);
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/MockRegistryImpl.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/MockRegistryImpl.java 2007-06-28 13:35:12 UTC (rev 12921)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/MockRegistryImpl.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -105,9 +105,9 @@
* {@inheritDoc}
* @return collection services
*/
- public Collection<String> findAllServices() throws RegistryException
+ public List<String> findAllServices() throws RegistryException
{
- Collection<String> serviceNames = new ArrayList<String>();
+ List<String> serviceNames = new ArrayList<String>();
for (Category category : categories.values()) {
for (Service service : category.getServices()) {
serviceNames.add(service.name);
@@ -119,11 +119,11 @@
* Find Services based on a category ("transformation").
*
* @param serviceType
- * @return collection services
+ * @return List services
*/
- public Collection<String> findServices(String categoryName) throws RegistryException
+ public List<String> findServices(String categoryName) throws RegistryException
{
- Collection<String> serviceNames = new ArrayList<String>();
+ List<String> serviceNames = new ArrayList<String>();
Category category = categories.get(categoryName);
if (category==null) {
throw new RegistryException("No category called " + categoryName + " exist");
@@ -138,9 +138,9 @@
* @param service
* @return
*/
- public Collection<EPR> findEPRs(String categoryName, String serviceName) throws RegistryException
+ public List<EPR> findEPRs(String categoryName, String serviceName) throws RegistryException
{
- Collection<EPR> eprs = new ArrayList<EPR>();
+ List<EPR> eprs = new ArrayList<EPR>();
Service service = findService(categoryName, serviceName);
for (ServiceBinding serviceBinding : service.serviceBindings) {
eprs.add(serviceBinding.getEpr());
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java 2007-06-28 13:35:12 UTC (rev 12921)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -131,6 +131,12 @@
return ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).getProperty(Environment.JNDI_SERVER_PKG_PREFIX,
Environment.DEFAULT_JNDI_PKG_PREFIX);
}
+
+ public static String getLoadBalancerPolicy()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).getProperty(Environment.LOAD_BALANCER_POLICY,
+ Environment.DEFAULT_LOAD_BALANCER_POLICY);
+ }
/**
* The Registry Query Manager URI can be used to obtain information about services and their endPoints.
* @return Registry Query Manager URI String
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Environment.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Environment.java 2007-06-28 13:35:12 UTC (rev 12921)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Environment.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -54,6 +54,7 @@
public static final String PARAMS_REPOS_IMPL_CLASS = "org.jboss.soa.esb.paramsRepository.class";
public static final String OBJECT_STORE_CONFIG_FILE = "org.jboss.soa.esb.objStore.configFile";
public static final String ENCRYPT_FACTORY_CLASS = "org.jboss.soa.esb.encryption.factory.class";
+ public static final String LOAD_BALANCER_POLICY = "org.jboss.soa.esb.loadbalancer.policy";
/**
* The Registry Query Manager URI defines the endPoint where registry queries can be made.
*/
@@ -98,6 +99,7 @@
public static final String DEFAULT_PORT = "25";
public static final String DEFAULT_JNDI_CONTEXT_FACTORY = "org.jnp.interfaces.NamingContextFactory";
public static final String DEFAULT_JNDI_PKG_PREFIX = "org.jnp.interfaces";
+ public static final String DEFAULT_LOAD_BALANCER_POLICY = "org.jboss.soa.esb.listeners.ha.FirstAvailable";
/*
* DatabaseMessageStore Persistence Store properties.
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerUtil.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerUtil.java 2007-06-28 13:35:12 UTC (rev 12921)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerUtil.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -66,7 +66,7 @@
* @throws JMSException
*/
public static void tryToDeliver(Message message, String category, String name)
- throws MessageDeliverException, RegistryException, JMSException
+ throws MessageDeliverException, JMSException, RegistryException
{
MessageDeliveryAdapter adapter = new MessageDeliveryAdapter(category, name);
adapter.deliverAsync(message);
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/RegistryUtil.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/RegistryUtil.java 2007-06-28 13:35:12 UTC (rev 12921)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/RegistryUtil.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -24,7 +24,7 @@
import java.io.IOException;
import java.util.Arrays;
-import java.util.Collection;
+import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -185,7 +185,7 @@
*
* @throws RegistryException for registration errors.
*/
- public static Collection<EPR> getEprs(final String category, final String name)
+ public static List<EPR> getEprs(final String category, final String name)
throws RegistryException
{
if ("eprManager".equalsIgnoreCase(category))
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/FirstAvailable.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/FirstAvailable.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/FirstAvailable.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss 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.soa.esb.listeners.ha;
+
+import java.util.List;
+
+import org.jboss.soa.esb.addressing.EPR;
+
+/**
+ * LoadBalancingPolicy implementation that always favor the first available target i.e.
+ * no load balancing occurs. Nevertheless, the first target is randomly selected.
+ * This does not mean that fail-over will not occur if the
+ * first epr in the list dies. In this case, fail-over will occur, and a new epr
+ * will become the first member and invocation will continously be invoked on the same
+ * new epr until its death.
+ *
+ * Code based on jbossas ha framework.
+ *
+ * @author <a href="mailto:kurt at osconsulting.org">Kurt Stam</a>.
+ *
+ * @see org.jboss.soa.esb.listeners.ha.LoadBalancePolicy
+ *
+ */
+
+public class FirstAvailable implements LoadBalancePolicy
+{
+ private static final long serialVersionUID = 1L;
+
+ protected transient EPR electedEPR = null;
+
+ public EPR chooseEPR (ServiceClusterInfo serviceCluster)
+ {
+ List<EPR> eprs = serviceCluster.getEPRs ();
+ if (eprs.size () == 0)
+ return null;
+
+ if ( (this.electedEPR != null) && eprs.contains (this.electedEPR) ){
+ return this.electedEPR;
+ } else {
+ int cursor = RandomRobin.localRandomizer.nextInt(eprs.size());
+ this.electedEPR = eprs.get(cursor);
+ return this.electedEPR;
+ }
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/FirstAvailable.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/LoadBalancePolicy.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/LoadBalancePolicy.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/LoadBalancePolicy.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss 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.soa.esb.listeners.ha;
+
+import org.jboss.soa.esb.addressing.EPR;
+
+/**
+ * Base interface for load-balancing policies. It is possible to implement many
+ * different load-balancing policies by implementing this simple interface and
+ * using it in the different service clusters.
+ *
+ * Code based on jbossas ha framework.
+ *
+ * @author <a href="mailto:kurt at osconsulting.org">Kurt Stam</a>.
+ */
+public interface LoadBalancePolicy
+{
+ /**
+ * Called when the ServiceInvoker wishes to know on which node the next invocation must
+ * be performed.
+ * @param serviceCluster A list of potential eprs
+ * @return The selected epr for the next invocation
+ */
+ public EPR chooseEPR (ServiceClusterInfo serviceCluster);
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/LoadBalancePolicy.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/RandomRobin.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/RandomRobin.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/RandomRobin.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss 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.soa.esb.listeners.ha;
+
+import java.util.List;
+import java.util.Random;
+
+import org.jboss.soa.esb.addressing.EPR;
+
+/**
+ * LoadBalancingPolicy implementation that always fully randomly select its epr
+ * (without basing its decision on any historic).
+ *
+ * Code based on jbossas ha framework.
+ *
+ * @author <a href="mailto:kurt at osconsulting.org">Kurt Stam</a>.
+ */
+public class RandomRobin implements LoadBalancePolicy
+{
+ private static final long serialVersionUID = 1L;
+ /** This needs to be a class variable or else you end up with multiple
+ * Random numbers with the same seed when many clients lookup a proxy.
+ */
+ public static final Random localRandomizer = new Random (System.currentTimeMillis ());
+
+
+ public EPR chooseEPR (ServiceClusterInfo serviceCluster)
+ {
+ List<EPR> eprs = serviceCluster.getEPRs ();
+ int max = eprs.size();
+
+ if (max == 0)
+ return null;
+
+ int cursor = localRandomizer.nextInt (max);
+ return eprs.get(cursor);
+ }
+
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/RandomRobin.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/RoundRobin.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/RoundRobin.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/RoundRobin.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss 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.soa.esb.listeners.ha;
+
+import java.util.List;
+
+import org.jboss.soa.esb.addressing.EPR;
+
+/**
+ * LoadBalancingPolicy implementation that always favors the next available
+ * epr load balancing always occurs.
+ *
+ * Code based on jbossas ha framework.
+ *
+ * @author <a href="mailto:kurt at osconsulting.org">Kurt Stam</a>.
+ *
+ */
+public class RoundRobin implements LoadBalancePolicy
+{
+ private static final long serialVersionUID = 1L;
+
+ public EPR chooseEPR (ServiceClusterInfo serviceCluster)
+ {
+ int cursor = serviceCluster.getCursor ();
+ List<EPR> eprs = serviceCluster.getEPRs ();
+
+ if (eprs.size () == 0) {
+ return null;
+ }
+ if (cursor == ServiceClusterInfo.UNINITIALIZED_CURSOR) {
+ // Obtain a random index into eprs
+ cursor = RandomRobin.localRandomizer.nextInt(eprs.size());
+ } else {
+ // Choose the next epr
+ cursor = ( (cursor + 1) % eprs.size() );
+ }
+ serviceCluster.setCursor (cursor);
+
+ return eprs.get(cursor);
+ }
+
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/RoundRobin.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/ServiceClusterInfo.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/ServiceClusterInfo.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/ServiceClusterInfo.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, JBoss 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.soa.esb.listeners.ha;
+
+import java.util.List;
+
+import org.jboss.soa.esb.addressing.EPR;
+/**
+ * Holder for a list of eprs all belonging to the same service.
+ *
+ * Code based on jbossas ha framework.
+ *
+ * @author <a href="mailto:kurt at osconsulting.org">Kurt Stam</a>.
+ *
+ */
+
+
+public interface ServiceClusterInfo
+{
+ public String getServiceName ();
+ /**
+ * Gets the list of eprs.
+ */
+ public List<EPR> getEPRs ();
+
+ /**
+ * Remove the given epr from the list of eprs.
+ *
+ * @param target the epr
+ * @return the updated list of EPRs
+ */
+ public List<EPR> removeDeadEPR(EPR epr);
+
+ /**
+ * Updates the eprs.
+ */
+ public List<EPR> updateClusterInfo (List<EPR> eprs);
+
+ // arbitrary usage by the LoadBalancePolicy implementation
+ // We could have used an HashMap but the lookup would have taken
+ // much more time and we probably don't need as much flexibility
+ // (+ it is slow for a simple int)
+ //
+ public int getCursor();
+ public int setCursor (int cursor);
+
+ public final static int UNINITIALIZED_CURSOR = 999999999;
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/ServiceClusterInfo.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/ServiceClusterInfoImpl.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/ServiceClusterInfoImpl.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/ServiceClusterInfoImpl.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, JBoss 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.soa.esb.listeners.ha;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.soa.esb.addressing.EPR;
+
+/**
+ * Default implementation of ServiceClusterInfo.
+ *
+ * Holder for a list of eprs all belonging to the same service.
+ *
+ * Code based on jbossas ha framework.
+ *
+ * @author <a href="mailto:kurt at osconsulting.org">Kurt Stam</a>.
+ *
+ */
+public class ServiceClusterInfoImpl implements ServiceClusterInfo
+{
+ public String serviceName = null;
+ ArrayList<EPR> eprs = null;
+
+ int cursor = ServiceClusterInfo.UNINITIALIZED_CURSOR;
+ Object arbitraryObject = null;
+
+ private ServiceClusterInfoImpl (){ }
+
+ public ServiceClusterInfoImpl (String serviceName, List<EPR> eprs)
+ {
+ this.serviceName = serviceName;
+ this.eprs = cloneList(eprs);
+ }
+ /**
+ * Returns the ServiceName.
+ */
+ public String getServiceName () { return this.serviceName; }
+ /**
+ * Returns an unmodifiable view of the target list.
+ */
+ public synchronized List<EPR> getEPRs ()
+ {
+ return Collections.unmodifiableList(this.eprs);
+ }
+
+ public int getCursor () { return this.cursor; }
+ public int setCursor (int cursor) { return (this.cursor = cursor);}
+
+ @SuppressWarnings("unchecked")
+ public List<EPR> removeDeadEPR(EPR epr)
+ {
+ synchronized (this)
+ {
+ ArrayList<EPR> tmp = (ArrayList<EPR>) eprs.clone();
+ tmp.remove (epr);
+ this.eprs = tmp;
+
+ return Collections.unmodifiableList(this.eprs);
+ }
+ }
+
+ public List<EPR> updateClusterInfo (List<EPR> eprs)
+ {
+ synchronized (this)
+ {
+ this.eprs = cloneList(eprs);
+ return Collections.unmodifiableList(this.eprs);
+ }
+ }
+
+ public String toString()
+ {
+ StringBuffer tmp = new StringBuffer(super.toString());
+ tmp.append("serviceName=");
+ tmp.append(serviceName);
+ tmp.append("eprs=");
+ tmp.append(eprs);
+ tmp.append(",cursor=");
+ tmp.append(cursor);
+ tmp.append("}");
+ return tmp.toString();
+ }
+
+ @SuppressWarnings("unchecked")
+ private static ArrayList<EPR> cloneList(List<EPR> toClone)
+ {
+ if (toClone instanceof ArrayList)
+ {
+ synchronized (toClone)
+ {
+ return (ArrayList<EPR>) ((ArrayList<EPR>) toClone).clone();
+ }
+ }
+
+ ArrayList<EPR> clone = new ArrayList<EPR>(toClone.size());
+ synchronized (toClone)
+ {
+ clone.addAll(toClone);
+ }
+ return clone;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ha/ServiceClusterInfoImpl.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageDeliveryAdapter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageDeliveryAdapter.java 2007-06-28 13:35:12 UTC (rev 12921)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageDeliveryAdapter.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -19,21 +19,27 @@
*/
package org.jboss.soa.esb.listeners.message;
-import java.util.Collection;
+import java.util.Date;
+import java.util.List;
import org.apache.log4j.Logger;
import org.jboss.internal.soa.esb.assertion.AssertArgument;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.MalformedEPRException;
+import org.jboss.soa.esb.common.Configuration;
import org.jboss.soa.esb.couriers.Courier;
import org.jboss.soa.esb.couriers.CourierException;
import org.jboss.soa.esb.couriers.CourierFactory;
import org.jboss.soa.esb.couriers.CourierUtil;
import org.jboss.soa.esb.couriers.TwoWayCourier;
import org.jboss.soa.esb.listeners.RegistryUtil;
+import org.jboss.soa.esb.listeners.ha.LoadBalancePolicy;
+import org.jboss.soa.esb.listeners.ha.ServiceClusterInfo;
+import org.jboss.soa.esb.listeners.ha.ServiceClusterInfoImpl;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.util.ClassUtil;
/**
* Adapter class for managing {@link Message} delivery to a specified Service.
@@ -62,22 +68,22 @@
*/
private String serviceName;
/**
- * The list of installed EPRs for the target Service.
+ *
*/
- private Collection<EPR> serviceEprs;
-
+ private LoadBalancePolicy loadBalancer;
/**
- * A cached instance of the last EPR that "worked" on this instance. Just saves iterating over
- * all the EPRs again. If it fails, we iterate as normal.
+ *
*/
- private EPR lastSuccessfulEPR;
-
+ private ServiceClusterInfo serviceClusterInfo;
/**
* Synchronous courier "pickup" deliver timeout.
*/
private ThreadLocal<Long> syncPickupDeliveryTimeout = new ThreadLocal<Long>();
-
/**
+ *
+ */
+ private Date expirationDate;
+ /**
* Public constructor.
*
* @param serviceCategory The <b>category name</b> of the Service to which this instance will
@@ -86,13 +92,26 @@
* deliver messages.
* @throws RegistryException Failed to lookup EPRs for the specified Service.
*/
- public MessageDeliveryAdapter(String serviceCategory, String serviceName) throws RegistryException {
+ public MessageDeliveryAdapter(String serviceCategory, String serviceName) throws RegistryException, MessageDeliverException {
AssertArgument.isNotNullAndNotEmpty(serviceCategory, "serviceCategory");
AssertArgument.isNotNullAndNotEmpty(serviceName, "serviceName");
-
this.serviceCategory = serviceCategory;
this.serviceName = serviceName;
- serviceEprs = RegistryUtil.getEprs(serviceCategory, serviceName);
+ String lbClass = Configuration.getLoadBalancerPolicy();
+ try {
+ Class c = ClassUtil.forName(lbClass, this.getClass());
+ loadBalancer = (LoadBalancePolicy) c.newInstance();
+ loadServiceClusterInfo();
+ } catch (ClassNotFoundException clf) {
+ logger.error("No such LoadBalancePolicy class = " + lbClass);
+ throw new MessageDeliverException( clf.getMessage(), clf);
+ } catch (InstantiationException ie) {
+ logger.error("Could not instatiate LoadBalancePolicy class = " + lbClass);
+ throw new MessageDeliverException( ie.getMessage(), ie.getCause());
+ } catch (IllegalAccessException iae) {
+ logger.error("Illegal access while instantiating LoadBalancePolicy class = " + lbClass);
+ throw new MessageDeliverException( iae.getMessage(), iae);
+ }
}
/**
@@ -104,7 +123,7 @@
* without error, otherwise an exception is thrown.
* @throws MessageDeliverException Failed to deliver message, after trying all available EPRs.
*/
- public Message deliverSync(Message message, long timeoutMillis) throws MessageDeliverException {
+ public Message deliverSync(Message message, long timeoutMillis) throws MessageDeliverException, RegistryException {
syncPickupDeliveryTimeout.set(timeoutMillis);
return deliver(message, true);
}
@@ -129,29 +148,28 @@
* without error, otherwise an exception is thrown.
* @throws MessageDeliverException Failed to deliver message, after trying all available EPRs.
*/
- private Message deliver(Message message, boolean synchronous) throws MessageDeliverException {
- Message replyMessage = null;
-
- // If we have a cached version of an EPR that previously worked, try it first...
- if (lastSuccessfulEPR != null) {
- replyMessage = attemptDelivery(message, lastSuccessfulEPR, synchronous);
- if (replyMessage != null) {
- // We've successully delivered the message using the same EPR as worked the
- // the last time. We're done!...
- return replyMessage;
+ private Message deliver(Message message, boolean synchronous) throws MessageDeliverException
+ {
+ int numberOfAttemps=0;
+ while (numberOfAttemps++ < 2) {
+ if ((serviceClusterInfo.getEPRs().size()==0) || (new Date().after(expirationDate)) ) {
+ loadServiceClusterInfo();
}
- }
-
- // Iterate over all the EPRs in the list...
- for (EPR epr : serviceEprs) {
- replyMessage = attemptDelivery(message, epr, synchronous);
- if (replyMessage != null) {
- // We've delivered it, we're done!
- lastSuccessfulEPR = epr;
- return replyMessage;
+ Message replyMessage = null;
+ EPR epr = null;
+ // Iterate over all the EPRs in the list until delivered
+ while ((epr = loadBalancer.chooseEPR(serviceClusterInfo))!=null) {
+ replyMessage = attemptDelivery(message, epr, synchronous);
+ if (replyMessage != null) {
+ // We've delivered it, we're done!
+ return replyMessage;
+ } else {
+ logger.info("Dead EPR: " + epr);
+ serviceClusterInfo.removeDeadEPR(epr);
+ }
}
}
-
+
// Throw exception if delivery failed...
throw new MessageDeliverException("Failed to deliver message to Service [" + serviceCategory + ":" + serviceName + "]. Check for errors.");
}
@@ -235,15 +253,6 @@
}
/**
- * Get the last EPR that "worked" on this instance.
- *
- * @return Last successfully used EPR, or null if there was none.
- */
- protected EPR getLastSuccessfulEPR() {
- return lastSuccessfulEPR;
- }
-
- /**
* Get the reply to address for synchronous delivery.
*
* @param toEpr The to address.
@@ -274,4 +283,19 @@
// This method just allows us to override Courier lookup during unit testing.
return CourierFactory.getInstance().getMessageCourier(epr);
}
+ /**
+ * Loads the EPRs fresh from the Registry. Right now we will do this every minute
+ * until we can expect to get updates from the registry. For now this should work
+ * just fine.
+ */
+ public void loadServiceClusterInfo() throws MessageDeliverException
+ {
+ try {
+ List<EPR> serviceEprs = RegistryUtil.getEprs(serviceCategory, serviceName);
+ serviceClusterInfo = new ServiceClusterInfoImpl(serviceName, serviceEprs);
+ expirationDate = new Date(java.lang.System.currentTimeMillis() + 60000);
+ } catch (RegistryException e) {
+ throw new MessageDeliverException(e.getMessage(), e);
+ }
+ }
}
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/UncomposedMessageDeliveryAdapter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/UncomposedMessageDeliveryAdapter.java 2007-06-28 13:35:12 UTC (rev 12921)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/UncomposedMessageDeliveryAdapter.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -58,7 +58,7 @@
* @throws org.jboss.soa.esb.services.registry.RegistryException
* Failed to lookup EPRs for the specified Service.
*/
- public UncomposedMessageDeliveryAdapter(String serviceCategory, String serviceName, MessageComposer composer) throws RegistryException {
+ public UncomposedMessageDeliveryAdapter(String serviceCategory, String serviceName, MessageComposer composer) throws RegistryException, MessageDeliverException {
AssertArgument.isNotNull(serviceCategory, "serviceCategory");
AssertArgument.isNotNull(serviceName, "serviceName");
AssertArgument.isNotNull(composer, "composer");
@@ -80,7 +80,7 @@
* ({@link MessageComposer#decompose(org.jboss.soa.esb.message.Message) decomposed}).
* @throws MessageDeliverException Failed to deliverAsync message, after trying all available EPRs.
*/
- public Object deliverSync(Object messagePayload, long timeoutMillis) throws MessageDeliverException {
+ public Object deliverSync(Object messagePayload, long timeoutMillis) throws MessageDeliverException, RegistryException {
// Deliver the message...
Message message = deliverSyncWithoutDecomposing(messagePayload, timeoutMillis);
@@ -98,7 +98,7 @@
* @return The reply {@link Message}. The caller must decompose the message.
* @throws MessageDeliverException Failed to deliverAsync message, after trying all available EPRs.
*/
- public Message deliverSyncWithoutDecomposing(Object messagePayload, long timeoutMillis) throws MessageDeliverException {
+ public Message deliverSyncWithoutDecomposing(Object messagePayload, long timeoutMillis) throws MessageDeliverException, RegistryException {
AssertArgument.isNotNull(messagePayload, "messagePayload");
Message message = composer.compose(messagePayload);
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/services/registry/Registry.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/services/registry/Registry.java 2007-06-28 13:35:12 UTC (rev 12921)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/services/registry/Registry.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -21,7 +21,7 @@
*/
package org.jboss.soa.esb.services.registry;
-import java.util.Collection;
+import java.util.List;
import org.jboss.soa.esb.addressing.EPR;
/**
@@ -66,7 +66,7 @@
* @return Collection of Strings containing the service names.
* @throws RegistryException
*/
- public Collection<String> findAllServices() throws RegistryException;
+ public List<String> findAllServices() throws RegistryException;
/**
* Find all services that belong to the supplied category.
*
@@ -74,7 +74,7 @@
* @return Collection of Strings containing the service names
* @throws RegistryException
*/
- public Collection<String> findServices(String serviceCategoryName) throws RegistryException;
+ public List<String> findServices(String serviceCategoryName) throws RegistryException;
/**
* Finds all the EPRs that belong to a specific category and service combination.
*
@@ -83,7 +83,7 @@
* @return Collection of EPRs.
* @throws RegistryException
*/
- public Collection<EPR> findEPRs(String serviceCategoryName, String serviceName) throws RegistryException;
+ public List<EPR> findEPRs(String serviceCategoryName, String serviceName) throws RegistryException;
/**
* Returns the first EPR in the list that belong to a specific category and service combination.
*
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/MockCourierFactory.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/MockCourierFactory.java 2007-06-28 13:35:12 UTC (rev 12921)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/MockCourierFactory.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -55,7 +55,7 @@
}
public static void uninstall() {
- CourierFactory.setInstance(originalInstance);
+ CourierFactory.setInstance(null);
reset();
}
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/MockRegistry.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/MockRegistry.java 2007-06-28 13:35:12 UTC (rev 12921)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/MockRegistry.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -22,7 +22,6 @@
package org.jboss.internal.soa.esb.services.registry;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import junit.framework.TestCase;
@@ -91,6 +90,7 @@
// It wasn't set in the first place, so just unset the impl
regPropManager.removeProperty(Environment.REGISTRY_IMPEMENTATION_CLASS);
}
+ repository = new ArrayList<RepositoryEntry>();
}
/**
@@ -151,8 +151,8 @@
/* (non-Javadoc)
* @see org.jboss.soa.esb.services.registry.Registry#findAllServices()
*/
- public Collection<String> findAllServices() throws RegistryException {
- Collection<String> services = new ArrayList<String>();
+ public List<String> findAllServices() throws RegistryException {
+ List<String> services = new ArrayList<String>();
for (RepositoryEntry entry : repository) {
services.add(entry.serviceName);
}
@@ -162,9 +162,9 @@
/* (non-Javadoc)
* @see org.jboss.soa.esb.services.registry.Registry#findServices(java.lang.String)
*/
- public Collection<String> findServices(String serviceCategoryName)
+ public List<String> findServices(String serviceCategoryName)
throws RegistryException {
- Collection<String> services = new ArrayList<String>();
+ List<String> services = new ArrayList<String>();
for (RepositoryEntry entry : repository) {
if (serviceCategoryName.equals(entry.serviceCategoryName)) {
services.add(entry.serviceName);
@@ -176,9 +176,9 @@
/* (non-Javadoc)
* @see org.jboss.soa.esb.services.registry.Registry#findEPRs(java.lang.String, java.lang.String)
*/
- public Collection<EPR> findEPRs(String serviceCategoryName,
+ public List<EPR> findEPRs(String serviceCategoryName,
String serviceName) throws RegistryException {
- Collection<EPR> services = new ArrayList<EPR>();
+ List<EPR> services = new ArrayList<EPR>();
for (RepositoryEntry entry : repository) {
if (serviceCategoryName.equals(entry.serviceCategoryName) && serviceName.equals(entry.serviceName)) {
services.add(entry.epr);
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/GroovyGatewayUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/GroovyGatewayUnitTest.java 2007-06-28 13:35:12 UTC (rev 12921)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/GroovyGatewayUnitTest.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -30,6 +30,7 @@
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
import org.jboss.soa.esb.listeners.message.BasicMessageComposer;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
import org.jboss.soa.esb.listeners.message.UncomposedMessageDeliveryAdapter;
import org.jboss.soa.esb.services.registry.RegistryException;
@@ -106,6 +107,8 @@
return new UncomposedMessageDeliveryAdapter("x", "y", new BasicMessageComposer());
} catch (RegistryException e) {
fail(e.getMessage());
+ } catch (MessageDeliverException e) {
+ fail(e.getMessage());
}
return null;
}
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListenerUnitTest.java 2007-06-28 13:35:12 UTC (rev 12921)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListenerUnitTest.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -20,8 +20,12 @@
package org.jboss.soa.esb.listeners.gateway;
import java.net.InetAddress;
+import java.net.URI;
-import junit.framework.TestCase;
+import junit.framework.JUnit4TestAdapter;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import org.apache.log4j.Logger;
import org.jboss.internal.soa.esb.couriers.MockCourier;
@@ -35,15 +39,19 @@
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.ListenerTagNames;
import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
import org.jboss.soa.esb.listeners.message.UncomposedMessageDeliveryAdapter;
import org.jboss.soa.esb.services.registry.RegistryException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.xml.sax.SAXException;
/**
* JBossRemotingGatewayListenerUnit unit tests.
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
*/
-public class JBossRemotingGatewayListenerUnitTest extends TestCase {
+public class JBossRemotingGatewayListenerUnitTest {
private Logger log = Logger
.getLogger( JBossRemotingGatewayListenerUnitTest.class );
@@ -52,26 +60,24 @@
private MockCourier courier1;
private MockCourier courier2;
private EPR epr3 = new EPR();
- private MockCourier courier3;
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
MockCourierFactory.install();
MockRegistry.install();
-
+
+ EPR epr2 = new EPR(new URI("2"));
courier1 = new MockCourier(false); // Will fail
courier2 = new MockCourier(true); // Will work
- courier3 = new MockCourier(true); // Will work
MockRegistry.register("cat", "servicex", courier1);
- MockRegistry.register("cat", "servicex", courier2);
- MockRegistry.register("cat", "servicex", epr3, courier3);
+ MockRegistry.register("cat", "servicex", epr2, courier2);
}
-
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
MockRegistry.uninstall();
MockCourierFactory.uninstall();
- stopServer();
}
-
+ @Test
public void test_config() throws SAXException {
test_config(null, "servicex", "http", "8888", "");
test_config("", "servicex", "http", "8888", "");
@@ -82,7 +88,7 @@
test_config("cat", "servicex", "http", null, "");
test_config("cat", "servicex", "http", "", "");
}
-
+ @Test
public void test_lifecycle() throws SAXException, ConfigurationException, ManagedLifecycleException {
ConfigTree config = getConfig("cat", "servicex", "http", "8888");
@@ -133,20 +139,20 @@
listener.doStop();
assertTrue(!listener.isStarted());
}
-
+ @Test
public void test_http_async() throws Throwable {
test_delivery("http", false);
}
- public void x_test_http_sync() throws Throwable {
- test_delivery("http", true);
- System.out.println("Ho " + courier3);
- }
-
+// public void x_test_http_sync() throws Throwable {
+// test_delivery("http", true);
+// System.out.println("Ho " + courier3);
+// }
+ @Test
public void test_socket_() throws Throwable {
test_delivery("socket", false);
}
-
+
public void test_delivery(String protocol, boolean synchronous) throws Throwable {
startServer(protocol, synchronous);
sendMessageToServer(protocol, protocol + "_payload");
@@ -181,6 +187,10 @@
e.printStackTrace();
fail(e.getMessage());
return null;
+ } catch (MessageDeliverException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ return null;
}
}
};
@@ -194,6 +204,7 @@
}
private void sendMessageToServer(String protocol, Object messagePayload) throws Throwable {
+
String locatorURI = protocol + "://" + InetAddress.getLocalHost().getHostName() + ":8888";
InvokerLocator locator = new InvokerLocator(locatorURI);
System.out.println("Calling remoting server with locator uri of: " + locatorURI);
@@ -205,7 +216,7 @@
// Make sure the courier doesn't have a payload beforehand...
assertEquals(null, courier2.message);
-
+
// Deliver the message to the listener...
Object response = remotingClient.invoke(messagePayload);
assertEquals("<ack/>", response);
@@ -258,4 +269,8 @@
assertTrue(cause.getMessage().startsWith(exception));
}
}
+
+ public static junit.framework.Test suite() {
+ return new JUnit4TestAdapter(JBossRemotingGatewayListenerUnitTest.class);
+ }
}
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/MessageDeliveryAdapterUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/MessageDeliveryAdapterUnitTest.java 2007-06-28 13:35:12 UTC (rev 12921)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/MessageDeliveryAdapterUnitTest.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -19,8 +19,13 @@
*/
package org.jboss.soa.esb.listeners.message;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import java.net.URI;
+
+import junit.framework.JUnit4TestAdapter;
+
import org.apache.log4j.Logger;
import org.jboss.internal.soa.esb.couriers.MockCourier;
import org.jboss.internal.soa.esb.couriers.MockCourierFactory;
@@ -29,9 +34,10 @@
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.MalformedEPRException;
import org.jboss.soa.esb.couriers.CourierException;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.services.registry.RegistryException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests for the MessageDeliveryAdapter and UncomposedMessageDeliveryAdapter
@@ -39,52 +45,48 @@
*
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
*/
-public class MessageDeliveryAdapterUnitTest extends TestCase {
+public class MessageDeliveryAdapterUnitTest {
private Logger log = Logger
.getLogger( MessageDeliveryAdapterUnitTest.class );
- private EPR epr1;
- private EPR epr2;
- private EPR epr3;
- private EPR epr4;
- private EPR epr5;
- private MockCourier courier1;
- private MockCourier courier2;
- private MockCourier courier3;
- private MockCourier courier4;
- private MockCourier courier5;
- private UncomposedMessageDeliveryAdapter deliveryAdapter;
+ private static EPR epr1;
+ private static EPR epr2;
+ private static EPR epr3;
+ private static EPR epr4;
+ private static MockCourier courier1;
+ private static MockCourier courier2;
+ private static MockCourier courier3;
+ private static MockCourier courier4;
+ private static UncomposedMessageDeliveryAdapter deliveryAdapter;
private String payload = "*XX*";
-
- protected void setUp() throws Exception {
+
+ @Before
+ public void setUp() throws Exception {
MockCourierFactory.install();
MockRegistry.install();
- epr1 = new EPR();
- epr2 = new EPR();
- epr3 = new EPR();
- epr4 = new EPR();
- epr5 = new EPR();
+ epr1 = new EPR(new URI("1"));
+ epr2 = new EPR(new URI("2"));
+ epr3 = new EPR(new URI("3"));
+ epr4 = new EPR(new URI("4"));
courier1 = new MockCourier(false);
courier2 = new MockCourier(new CourierException(""));
courier3 = new MockCourier(new MalformedEPRException(""));
courier4 = new MockCourier(true);
- courier5 = new MockCourier(true);
MockRegistry.register("cat", "service", epr1, courier1);
MockRegistry.register("cat", "service", epr2, courier2);
MockRegistry.register("cat", "service", epr3, courier3);
MockRegistry.register("cat", "service", epr4, courier4);
- MockRegistry.register("cat", "service", epr5, courier5);
-
+
deliveryAdapter = new UncomposedMessageDeliveryAdapter("cat", "service", new MockMessageComposer());
}
-
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
MockRegistry.uninstall();
MockCourierFactory.uninstall();
}
-
+ @Test
public void test_getCourier_CourierException() throws MessageDeliverException {
// Get the courier factory to throw a CourierException
MockCourierFactory.courierException = new CourierException("");
@@ -97,7 +99,7 @@
}
assertNoDeliveryAttempted();
}
-
+ @Test
public void test_getCourier_MalformedEPRException() throws MessageDeliverException {
// Get the courier factory to throw a MalformedEPRException
MockCourierFactory.malformedEPRException = new MalformedEPRException("");
@@ -110,7 +112,7 @@
}
assertNoDeliveryAttempted();
}
-
+ @Test
public void test_No_EPRs() throws RegistryException, MessageDeliverException {
// Make sure there's no attempt to make a delivery when there's no
// EPRs for the service.
@@ -123,7 +125,7 @@
}
assertNoDeliveryAttempted();
}
-
+ @Test
public void test_deliver() throws MessageDeliverException {
// Make sure the delivery happens as expected...
@@ -132,30 +134,23 @@
assertEquals(null, courier2.message);
assertEquals(null, courier3.message);
assertEquals(payload, ActionUtils.getTaskObject(courier4.message));
- assertEquals(null, courier5.message);
- assertEquals(epr4, deliveryAdapter.getDeliveryAdapter().getLastSuccessfulEPR());
String payload2 = "*YYY*";
deliveryAdapter.deliverAsync(payload2);
assertEquals(payload2, ActionUtils.getTaskObject(courier4.message));
- assertEquals(epr4, deliveryAdapter.getDeliveryAdapter().getLastSuccessfulEPR());
}
+
private void assertNoDeliveryAttempted() {
if(courier1.deliveryAttempted ||
courier2.deliveryAttempted ||
courier3.deliveryAttempted ||
- courier4.deliveryAttempted ||
- courier5.deliveryAttempted) {
+ courier4.deliveryAttempted) {
fail("A deliverAsync attempt was made on one of the couriers.");
}
}
-
- public class MockMessageComposer extends AbstractMessageComposer {
- public void setConfiguration(ConfigTree config) {
- }
- protected void populateMessage(Message message, Object messagePayload) throws MessageDeliverException {
- ActionUtils.setTaskObject(message, messagePayload);
- }
+
+ public static junit.framework.Test suite() {
+ return new JUnit4TestAdapter(MessageDeliveryAdapterUnitTest.class);
}
}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/MockMessageComposer.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/MockMessageComposer.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/MockMessageComposer.java 2007-06-28 13:41:44 UTC (rev 12922)
@@ -0,0 +1,20 @@
+/**
+ *
+ */
+package org.jboss.soa.esb.listeners.message;
+
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * @author kstam
+ *
+ */
+public class MockMessageComposer extends AbstractMessageComposer {
+ public void setConfiguration(ConfigTree config) {
+ }
+ public void populateMessage(Message message, Object messagePayload) throws MessageDeliverException {
+ ActionUtils.setTaskObject(message, messagePayload);
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/MockMessageComposer.java
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list