From 3b76ccc92b5f0e00de54a4fd6c3705d1b8509771 Mon Sep 17 00:00:00 2001 From: Andy Taylor Date: Thu, 29 Jan 2015 09:18:36 +0000 Subject: [PATCH] ACTIVEMQ6-7 - Improve Serialization on Connection Factory https://issues.apache.org/jira/browse/ACTIVEMQ6-7 Connection Factory is now externalizable and is now serialized as a string that represents a URI. There are schemas for every possible type for connection factory and server locator. The client JNDI representation of factories has also been changed to be consistent with this. --- .../activemq/utils/uri/SchemaConstants.java | 15 +- .../apache/activemq/utils/uri/URIFactory.java | 85 +++- .../apache/activemq/utils/uri/URISchema.java | 86 +++- .../apache/activemq/utils/URIParserTest.java | 12 + .../api/core/BroadcastEndpointFactory.java | 2 +- .../api/core/BroadcastGroupConfiguration.java | 18 +- .../core/ChannelBroadcastEndpointFactory.java | 41 ++ .../api/core/DiscoveryGroupConfiguration.java | 67 +-- .../api/core/JGroupsBroadcastEndpoint.java | 281 ++++++++++++ .../JGroupsBroadcastGroupConfiguration.java | 404 ------------------ ...a => JGroupsChannelBroadcastEndpoint.java} | 34 +- .../core/JGroupsFileBroadcastEndpoint.java | 49 +++ .../JGroupsFileBroadcastEndpointFactory.java | 55 +++ .../JGroupsPropertiesBroadcastEndpoint.java | 43 ++ ...upsPropertiesBroadcastEndpointFactory.java | 55 +++ ....java => UDPBroadcastEndpointFactory.java} | 35 +- .../api/core/client/ActiveMQClient.java | 14 + .../api/core/client/TopologyMember.java | 4 +- .../core/client/impl/ServerLocatorImpl.java | 9 +- .../ClientProtocolManagerFactory.java | 4 +- .../uri/AbstractServerLocatorSchema.java | 34 ++ .../activemq/uri/ConnectionOptions.java | 75 ++++ .../activemq/uri/InVMServerLocatorSchema.java | 73 ++++ .../uri/JGroupsServerLocatorSchema.java | 102 +++++ .../activemq/uri/ServerLocatorParser.java | 33 ++ .../activemq/uri/TCPServerLocatorSchema.java | 160 +++++++ .../activemq/uri/UDPServerLocatorSchema.java | 89 ++++ activemq-jms-client/pom.xml | 7 + .../activemq/api/jms/ActiveMQJMSClient.java | 13 + .../jms/client/ActiveMQConnectionFactory.java | 70 ++- .../client/ActiveMQJMSConnectionFactory.java | 1 - .../jndi/ActiveMQInitialContextFactory.java | 359 +--------------- .../apache/activemq/uri/AbstractCFSchema.java | 6 +- .../activemq/uri/ConnectionFactoryParser.java | 2 + .../org/apache/activemq/uri/InVMSchema.java | 51 +++ .../apache/activemq/uri/JGroupsSchema.java | 53 ++- ...Options.java => JMSConnectionOptions.java} | 47 +- .../org/apache/activemq/uri/TCPSchema.java | 67 +++ .../org/apache/activemq/uri/UDPSchema.java | 33 +- .../uri/ConnectionFactoryURITest.java | 368 +++++++++++++++- .../activemq/ra/ActiveMQResourceAdapter.java | 33 +- .../activemq/core/config/Configuration.java | 3 +- .../core/config/impl/ConfigurationImpl.java | 3 +- .../impl/FileConfigurationParser.java | 26 +- .../impl/BroadcastGroupControlImpl.java | 14 +- .../impl/invm/InVMAcceptorFactory.java | 1 - .../impl/invm/InVMConnectorFactory.java | 1 - .../impl/invm/TransportConstants.java | 5 - .../impl/netty/NettyAcceptorFactory.java | 1 - .../server/impl/RemotingServiceImpl.java | 15 - .../core/server/cluster/ClusterManager.java | 2 +- .../spi/core/remoting/AcceptorFactory.java | 1 - .../config/impl/FileConfigurationTest.java | 16 +- docs/user-manual/en/using-jms.md | 105 ++--- .../src/main/resources/jndi.properties | 2 +- .../ApplicationLayerFailoverExample.java | 2 +- .../activemq/jms/example/BridgeExample.java | 4 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 6 +- .../src/main/resources/jndi.properties | 2 +- .../ClusteredDurableSubscriptionExample.java | 4 +- .../jms/example/ClusteredGroupingExample.java | 6 +- .../jms/example/ClusteredJgroupsExample.java | 4 +- .../activemq/server0/client-jndi.properties | 2 +- .../jms/example/ClusteredQueueExample.java | 4 +- .../example/ClusteredStandaloneExample.java | 6 +- .../example/StaticClusteredQueueExample.java | 2 +- .../example/ClusterStaticOnewayExample.java | 2 +- .../jms/example/ClusteredTopicExample.java | 4 +- .../ColocatedFailoverScaleDownExample.java | 8 +- .../jms/example/ColocatedFailoverExample.java | 8 +- .../src/main/resources/jndi.properties | 3 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../activemq/jms/example/DivertExample.java | 4 +- .../src/main/resources/jndi.properties | 2 +- .../expiry/src/main/resources/jndi.properties | 2 +- .../example/HAPolicyAutoBackupExample.java | 12 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../jms/example/JMSBridgeExample.java | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../jmx/src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 3 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 6 +- .../src/main/resources/jndi.properties | 6 +- .../src/main/resources/jndi.properties | 3 +- .../src/main/resources/jndi.properties | 6 +- .../paging/src/main/resources/jndi.properties | 2 +- .../perf/src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 3 +- .../QueueMessageRedistributionExample.java | 4 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../queue/src/main/resources/jndi.properties | 2 +- .../activemq/jms/example/ReattachExample.java | 2 +- .../src/main/resources/jndi.properties | 7 +- .../src/main/resources/jndi.properties | 6 +- .../src/main/resources/jndi.properties | 6 +- .../src/main/resources/jndi.properties | 6 +- .../src/main/resources/jndi.properties | 6 +- .../src/main/resources/jndi.properties | 6 +- .../jms/example/ScaleDownExample.java | 12 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 3 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../stomp/src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 6 +- .../jms/example/SymmetricClusterExample.java | 7 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../topic/src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 6 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../src/main/resources/jndi.properties | 2 +- .../jms/soak/example/SoakReceiver.java | 2 +- .../activemq/jms/soak/example/SoakSender.java | 2 +- .../ServerLocatorSerializationTest.java | 131 ------ .../client/SessionFactoryTest.java | 48 +-- .../BridgeWithDiscoveryGroupStartTest.java | 8 +- .../cluster/distribution/ClusterTestBase.java | 14 +- .../HAClientTopologyWithDiscoveryTest.java | 8 +- .../discovery/DiscoveryBaseTest.java | 12 +- .../discovery/DiscoveryStayAliveTest.java | 10 +- .../integration/discovery/DiscoveryTest.java | 67 +-- .../jms/ActiveMQConnectionFactoryTest.java | 16 +- .../integration/jms/SimpleJNDIClientTest.java | 399 +++++------------ .../ConnectionFactorySerializationTest.java | 329 ++++++++++++-- ...onFactoryWithJGroupsSerializationTest.java | 19 +- .../jms/server/JMSServerDeployerTest.java | 10 +- .../management/ActiveMQServerControlTest.java | 3 +- .../management/BroadcastGroupControlTest.java | 12 +- .../ClusterConnectionControl2Test.java | 14 +- .../ClusterConnectionControlTest.java | 8 +- .../ra/ActiveMQRAClusteredTestBase.java | 5 +- .../integration/ra/ResourceAdapterTest.java | 8 +- .../src/test/resources/jndi.properties | 3 +- .../jtests/jms/framework/PTPTestCase.java | 3 +- .../jtests/jms/framework/PubSubTestCase.java | 3 +- .../jtests/jms/framework/UnifiedTestCase.java | 5 +- .../tests/unit/ra/ResourceAdapterTest.java | 4 +- 163 files changed, 2682 insertions(+), 1922 deletions(-) rename activemq-core-client/src/main/java/org/apache/activemq/api/core/BroadcastEndpointFactoryConfiguration.java => activemq-commons/src/main/java/org/apache/activemq/utils/uri/SchemaConstants.java (78%) create mode 100644 activemq-core-client/src/main/java/org/apache/activemq/api/core/ChannelBroadcastEndpointFactory.java create mode 100644 activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsBroadcastEndpoint.java delete mode 100644 activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsBroadcastGroupConfiguration.java rename activemq-core-client/src/main/java/org/apache/activemq/api/core/{DiscoveryGroupConfigurationCompatibilityHelper.java => JGroupsChannelBroadcastEndpoint.java} (54%) create mode 100644 activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsFileBroadcastEndpoint.java create mode 100644 activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsFileBroadcastEndpointFactory.java create mode 100644 activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsPropertiesBroadcastEndpoint.java create mode 100644 activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsPropertiesBroadcastEndpointFactory.java rename activemq-core-client/src/main/java/org/apache/activemq/api/core/{UDPBroadcastGroupConfiguration.java => UDPBroadcastEndpointFactory.java} (86%) create mode 100644 activemq-core-client/src/main/java/org/apache/activemq/uri/AbstractServerLocatorSchema.java create mode 100644 activemq-core-client/src/main/java/org/apache/activemq/uri/ConnectionOptions.java create mode 100644 activemq-core-client/src/main/java/org/apache/activemq/uri/InVMServerLocatorSchema.java create mode 100644 activemq-core-client/src/main/java/org/apache/activemq/uri/JGroupsServerLocatorSchema.java create mode 100644 activemq-core-client/src/main/java/org/apache/activemq/uri/ServerLocatorParser.java create mode 100644 activemq-core-client/src/main/java/org/apache/activemq/uri/TCPServerLocatorSchema.java create mode 100644 activemq-core-client/src/main/java/org/apache/activemq/uri/UDPServerLocatorSchema.java create mode 100644 activemq-jms-client/src/main/java/org/apache/activemq/uri/InVMSchema.java rename activemq-jms-client/src/main/java/org/apache/activemq/uri/{ConnectionOptions.java => JMSConnectionOptions.java} (75%) create mode 100644 activemq-jms-client/src/main/java/org/apache/activemq/uri/TCPSchema.java delete mode 100644 tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/client/ServerLocatorSerializationTest.java diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/BroadcastEndpointFactoryConfiguration.java b/activemq-commons/src/main/java/org/apache/activemq/utils/uri/SchemaConstants.java similarity index 78% rename from activemq-core-client/src/main/java/org/apache/activemq/api/core/BroadcastEndpointFactoryConfiguration.java rename to activemq-commons/src/main/java/org/apache/activemq/utils/uri/SchemaConstants.java index c600c8870c..6e7afe148f 100644 --- a/activemq-core-client/src/main/java/org/apache/activemq/api/core/BroadcastEndpointFactoryConfiguration.java +++ b/activemq-commons/src/main/java/org/apache/activemq/utils/uri/SchemaConstants.java @@ -14,15 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.api.core; - -import java.io.Serializable; +package org.apache.activemq.utils.uri; /** * @author Andy Taylor - * 9/25/12 */ -public interface BroadcastEndpointFactoryConfiguration extends Serializable +public class SchemaConstants { - BroadcastEndpointFactory createBroadcastEndpointFactory(); + public static final String TCP = "tcp"; + + public static final String UDP = "udp"; + + public static final String JGROUPS = "jgroups"; + + public static final String VM = "vm"; } diff --git a/activemq-commons/src/main/java/org/apache/activemq/utils/uri/URIFactory.java b/activemq-commons/src/main/java/org/apache/activemq/utils/uri/URIFactory.java index 4bc5fa457c..452bedd6a6 100644 --- a/activemq-commons/src/main/java/org/apache/activemq/utils/uri/URIFactory.java +++ b/activemq-commons/src/main/java/org/apache/activemq/utils/uri/URIFactory.java @@ -18,13 +18,13 @@ package org.apache.activemq.utils.uri; import java.net.URI; +import java.net.URISyntaxException; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** * @author clebertsuconic */ - public class URIFactory { @@ -48,11 +48,25 @@ public class URIFactory schemaFactory.setFactory(this); } - public void removeSchema(final String schemaName) + public void removeSchema(final SchemaConstants schemaName) { schemas.remove(schemaName); } + public T newObject(String uriString) throws Exception + { + URI uri = normalise(uriString); + URISchema schemaFactory = schemas.get(uri.getScheme()); + + if (schemaFactory == null) + { + throw new NullPointerException("Schema " + uri.getScheme() + " not found"); + } + + + return schemaFactory.newObject(uri); + } + public T newObject(URI uri) throws Exception { URISchema schemaFactory = schemas.get(uri.getScheme()); @@ -66,5 +80,72 @@ public class URIFactory return schemaFactory.newObject(uri); } + public void populateObject(URI uri, T bean) throws Exception + { + URISchema schemaFactory = schemas.get(uri.getScheme()); + if (schemaFactory == null) + { + throw new NullPointerException("Schema " + uri.getScheme() + " not found"); + } + + schemaFactory.populateObject(uri, bean); + } + + public URI createSchema(String scheme, T bean) throws Exception + { + URISchema schemaFactory = schemas.get(scheme); + + if (schemaFactory == null) + { + throw new NullPointerException("Schema " + scheme + " not found"); + } + return schemaFactory.newURI(bean); + } + + /* + * this method is used to change a string with multiple URI's in it into a valid URI. + * for instance it is possible to have the following String + * (tcp://localhost:5445,tcp://localhost:5545,tcp://localhost:5555)?somequery + * This is an invalid URI so will be changed so that the first URI is used and the + * extra ones added as part of the URI fragment, like so + * tcp://localhost:5445?someQuery#tcp://localhost:5545,tcp://localhost:5555. + * + * It is the job of the URISchema implementation to handle these fragments as needed. + * */ + private URI normalise(String uri) throws URISyntaxException + { + if (uri.startsWith("(")) + { + String[] split = uri.split("\\)"); + String[] connectorURIS = split[0].substring(split[0].indexOf('(') + 1).split(","); + String factoryQuery = split.length > 1 ? split[1] : ""; + StringBuilder builder = new StringBuilder(connectorURIS[0]); + if (factoryQuery != null && factoryQuery.length() > 0) + { + if (connectorURIS[0].contains("?")) + { + builder.append("&").append(factoryQuery.substring(1)); + } + else + { + builder.append(factoryQuery); + } + } + if (connectorURIS.length > 1) + { + builder.append("#"); + for (int i = 1; i < connectorURIS.length; i++) + { + if (i > 1) + { + builder.append(","); + } + builder.append(connectorURIS[i]); + } + } + return new URI(builder.toString()); + } + return new URI(uri); + } } diff --git a/activemq-commons/src/main/java/org/apache/activemq/utils/uri/URISchema.java b/activemq-commons/src/main/java/org/apache/activemq/utils/uri/URISchema.java index 4226d710f1..26ec4cd9e5 100644 --- a/activemq-commons/src/main/java/org/apache/activemq/utils/uri/URISchema.java +++ b/activemq-commons/src/main/java/org/apache/activemq/utils/uri/URISchema.java @@ -14,15 +14,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.activemq.utils.uri; +import java.beans.PropertyDescriptor; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; import java.net.URLDecoder; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.commons.beanutils.BeanUtilsBean; import org.apache.commons.beanutils.FluentPropertyBeanIntrospector; @@ -40,6 +42,16 @@ public abstract class URISchema return newObject(uri, null); } + public void populateObject(URI uri, T bean) throws Exception + { + setData(uri, bean, parseQuery(uri.getQuery(), null)); + } + + public URI newURI(T bean) throws Exception + { + return internalNewURI(bean); + } + private URIFactory parentFactory; @@ -102,6 +114,8 @@ public abstract class URISchema protected abstract T internalNewObject(URI uri, Map query) throws Exception; + protected abstract URI internalNewURI(T bean) throws Exception; + private static final BeanUtilsBean beanUtils = new BeanUtilsBean(); @@ -185,4 +199,74 @@ public abstract class URISchema } return obj; } + + public static void setData(URI uri, HashMap properties, Set allowableProperties, Map query) + { + if (allowableProperties.contains("host")) + { + properties.put("host", uri.getHost()); + } + if (allowableProperties.contains("port")) + { + properties.put("port", uri.getPort()); + } + if (allowableProperties.contains("userInfo")) + { + properties.put("userInfo", uri.getUserInfo()); + } + for (Map.Entry entry : query.entrySet()) + { + if (allowableProperties.contains(entry.getKey())) + { + properties.put(entry.getKey(), entry.getValue()); + } + } + } + + public static String getData(List ignored, Object... beans) throws Exception + { + StringBuilder sb = new StringBuilder(); + synchronized (beanUtils) + { + for (Object bean : beans) + { + if (bean != null) + { + PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); + for (PropertyDescriptor descriptor : descriptors) + { + if (descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null && isWriteable(descriptor, ignored)) + { + String value = beanUtils.getProperty(bean, descriptor.getName()); + if (value != null) + { + sb.append("&").append(descriptor.getName()).append("=").append(value); + } + } + } + } + } + } + return sb.toString(); + } + + private static boolean isWriteable(PropertyDescriptor descriptor, List ignored) + { + if (ignored != null && ignored.contains(descriptor.getName())) + { + return false; + } + Class type = descriptor.getPropertyType(); + return (type == Double.class) || + (type == double.class) || + (type == Long.class) || + (type == long.class) || + (type == Integer.class) || + (type == int.class) || + (type == Float.class) || + (type == float.class) || + (type == Boolean.class) || + (type == boolean.class) || + (type == String.class); + } } diff --git a/activemq-commons/src/test/java/org/apache/activemq/utils/URIParserTest.java b/activemq-commons/src/test/java/org/apache/activemq/utils/URIParserTest.java index be389c6457..1654ec4fdf 100644 --- a/activemq-commons/src/test/java/org/apache/activemq/utils/URIParserTest.java +++ b/activemq-commons/src/test/java/org/apache/activemq/utils/URIParserTest.java @@ -109,6 +109,12 @@ public class URIParserTest { return setData(uri, new Fruit(getSchemaName()), query); } + + @Override + protected URI internalNewURI(FruitBase bean) + { + return null; + } } class FruitBaseSchema extends URISchema @@ -125,6 +131,12 @@ public class URIParserTest { return setData(uri, new FruitBase(getSchemaName()), query); } + + @Override + protected URI internalNewURI(FruitBase bean) + { + return null; + } } diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/BroadcastEndpointFactory.java b/activemq-core-client/src/main/java/org/apache/activemq/api/core/BroadcastEndpointFactory.java index 2091c84bad..8fbe217ee8 100644 --- a/activemq-core-client/src/main/java/org/apache/activemq/api/core/BroadcastEndpointFactory.java +++ b/activemq-core-client/src/main/java/org/apache/activemq/api/core/BroadcastEndpointFactory.java @@ -16,8 +16,8 @@ */ package org.apache.activemq.api.core; -import java.io.Serializable; +import java.io.Serializable; public interface BroadcastEndpointFactory extends Serializable { diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/BroadcastGroupConfiguration.java b/activemq-core-client/src/main/java/org/apache/activemq/api/core/BroadcastGroupConfiguration.java index 671483042d..a27b543e2c 100644 --- a/activemq-core-client/src/main/java/org/apache/activemq/api/core/BroadcastGroupConfiguration.java +++ b/activemq-core-client/src/main/java/org/apache/activemq/api/core/BroadcastGroupConfiguration.java @@ -38,7 +38,7 @@ public final class BroadcastGroupConfiguration implements Serializable private long broadcastPeriod = ActiveMQDefaultConfiguration.getDefaultBroadcastPeriod(); - private BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration = null; + private BroadcastEndpointFactory endpointFactory = null; private List connectorInfos = null; @@ -79,14 +79,14 @@ public final class BroadcastGroupConfiguration implements Serializable return this; } - public BroadcastEndpointFactoryConfiguration getEndpointFactoryConfiguration() + public BroadcastEndpointFactory getEndpointFactory() { - return endpointFactoryConfiguration; + return endpointFactory; } - public BroadcastGroupConfiguration setEndpointFactoryConfiguration(BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration) + public BroadcastGroupConfiguration setEndpointFactory(BroadcastEndpointFactory endpointFactory) { - this.endpointFactoryConfiguration = endpointFactoryConfiguration; + this.endpointFactory = endpointFactory; return this; } @@ -97,7 +97,7 @@ public final class BroadcastGroupConfiguration implements Serializable int result = 1; result = prime * result + (int)(broadcastPeriod ^ (broadcastPeriod >>> 32)); result = prime * result + ((connectorInfos == null) ? 0 : connectorInfos.hashCode()); - result = prime * result + ((endpointFactoryConfiguration == null) ? 0 : endpointFactoryConfiguration.hashCode()); + result = prime * result + ((endpointFactory == null) ? 0 : endpointFactory.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @@ -121,12 +121,12 @@ public final class BroadcastGroupConfiguration implements Serializable } else if (!connectorInfos.equals(other.connectorInfos)) return false; - if (endpointFactoryConfiguration == null) + if (endpointFactory == null) { - if (other.endpointFactoryConfiguration != null) + if (other.endpointFactory != null) return false; } - else if (!endpointFactoryConfiguration.equals(other.endpointFactoryConfiguration)) + else if (!endpointFactory.equals(other.endpointFactory)) return false; if (name == null) { diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/ChannelBroadcastEndpointFactory.java b/activemq-core-client/src/main/java/org/apache/activemq/api/core/ChannelBroadcastEndpointFactory.java new file mode 100644 index 0000000000..ce77d6fdfe --- /dev/null +++ b/activemq-core-client/src/main/java/org/apache/activemq/api/core/ChannelBroadcastEndpointFactory.java @@ -0,0 +1,41 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.api.core; + +import org.jgroups.JChannel; + +/** +* @author Andy Taylor +*/ +public class ChannelBroadcastEndpointFactory implements BroadcastEndpointFactory +{ + private final JChannel channel; + + private final String channelName; + + public ChannelBroadcastEndpointFactory(JChannel channel, String channelName) + { + this.channel = channel; + this.channelName = channelName; + } + + @Override + public BroadcastEndpoint createBroadcastEndpoint() throws Exception + { + return new JGroupsChannelBroadcastEndpoint(channel, channelName).initChannel(); + } +} diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/DiscoveryGroupConfiguration.java b/activemq-core-client/src/main/java/org/apache/activemq/api/core/DiscoveryGroupConfiguration.java index 5789cc63f7..cbe0d7a754 100644 --- a/activemq-core-client/src/main/java/org/apache/activemq/api/core/DiscoveryGroupConfiguration.java +++ b/activemq-core-client/src/main/java/org/apache/activemq/api/core/DiscoveryGroupConfiguration.java @@ -16,9 +16,6 @@ */ package org.apache.activemq.api.core; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.io.Serializable; import org.apache.activemq.api.core.client.ActiveMQClient; @@ -47,30 +44,10 @@ public final class DiscoveryGroupConfiguration implements Serializable private long discoveryInitialWaitTimeout = ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT; - /* - * The localBindAddress is needed so we can be backward compatible with 2.2 clients - * */ - private transient String localBindAddress = null; - - /* - * The localBindPort is needed so we can be backward compatible with 2.2 clients - * */ - private transient int localBindPort = -1; - - /* - * The groupAddress is needed so we can be backward compatible with 2.2 clients - * */ - private String groupAddress = null; - - /* - * The groupPort is needed so we can be backward compatible with 2.2 clients - * */ - private int groupPort = -1; - /* * This is the actual object used by the class, it has to be transient so we can handle deserialization with a 2.2 client * */ - private transient BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration; + private BroadcastEndpointFactory endpointFactory; public DiscoveryGroupConfiguration() { @@ -121,51 +98,17 @@ public final class DiscoveryGroupConfiguration implements Serializable return this; } - public BroadcastEndpointFactoryConfiguration getBroadcastEndpointFactoryConfiguration() + public BroadcastEndpointFactory getBroadcastEndpointFactory() { - return endpointFactoryConfiguration; + return endpointFactory; } - public DiscoveryGroupConfiguration setBroadcastEndpointFactoryConfiguration(BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration) + public DiscoveryGroupConfiguration setBroadcastEndpointFactory(BroadcastEndpointFactory endpointFactory) { - this.endpointFactoryConfiguration = endpointFactoryConfiguration; - if (endpointFactoryConfiguration instanceof DiscoveryGroupConfigurationCompatibilityHelper) - { - DiscoveryGroupConfigurationCompatibilityHelper dgcch = (DiscoveryGroupConfigurationCompatibilityHelper) endpointFactoryConfiguration; - localBindAddress = dgcch.getLocalBindAddress(); - localBindPort = dgcch.getLocalBindPort(); - groupAddress = dgcch.getGroupAddress(); - groupPort = dgcch.getGroupPort(); - } + this.endpointFactory = endpointFactory; return this; } - private void writeObject(ObjectOutputStream out) throws IOException - { - out.defaultWriteObject(); - if (groupPort < 0) - { - out.writeObject(endpointFactoryConfiguration); - } - } - - private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException - { - in.defaultReadObject(); - if (groupPort < 0) - { - endpointFactoryConfiguration = (BroadcastEndpointFactoryConfiguration) in.readObject(); - } - else - { - endpointFactoryConfiguration = new UDPBroadcastGroupConfiguration() - .setGroupAddress(groupAddress) - .setGroupPort(groupPort) - .setLocalBindAddress(localBindAddress) - .setLocalBindPort(localBindPort); - } - } - @Override public boolean equals(Object o) { diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsBroadcastEndpoint.java b/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsBroadcastEndpoint.java new file mode 100644 index 0000000000..07381ed812 --- /dev/null +++ b/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsBroadcastEndpoint.java @@ -0,0 +1,281 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.api.core; + +import org.jgroups.JChannel; +import org.jgroups.ReceiverAdapter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.TimeUnit; + +/** + * This class is the implementation of ActiveMQ members discovery that will use JGroups. + * + * @author Howard Gao + */ +public abstract class JGroupsBroadcastEndpoint implements BroadcastEndpoint +{ + private final String channelName; + + private boolean clientOpened; + + private boolean broadcastOpened; + + private JChannelWrapper channel; + + private JGroupsReceiver receiver; + + public JGroupsBroadcastEndpoint(String channelName) + { + this.channelName = channelName; + } + + public void broadcast(final byte[] data) throws Exception + { + if (broadcastOpened) + { + org.jgroups.Message msg = new org.jgroups.Message(); + + msg.setBuffer(data); + + channel.send(msg); + } + } + + public byte[] receiveBroadcast() throws Exception + { + if (clientOpened) + { + return receiver.receiveBroadcast(); + } + else + { + return null; + } + } + + public byte[] receiveBroadcast(long time, TimeUnit unit) throws Exception + { + if (clientOpened) + { + return receiver.receiveBroadcast(time, unit); + } + else + { + return null; + } + } + + public synchronized void openClient() throws Exception + { + if (clientOpened) + { + return; + } + internalOpen(); + receiver = new JGroupsReceiver(); + channel.setReceiver(receiver); + clientOpened = true; + } + + public synchronized void openBroadcaster() throws Exception + { + if (broadcastOpened) return; + internalOpen(); + broadcastOpened = true; + } + + public abstract JChannel createChannel() throws Exception; + + public JGroupsBroadcastEndpoint initChannel() throws Exception + { + this.channel = JChannelManager.getJChannel(channelName, this); + return this; + } + + protected void internalOpen() throws Exception + { + channel.connect(); + } + + public synchronized void close(boolean isBroadcast) throws Exception + { + if (isBroadcast) + { + broadcastOpened = false; + } + else + { + channel.removeReceiver(receiver); + clientOpened = false; + } + channel.close(); + } + + /** + * This class is used to receive messages from a JGroups channel. + * Incoming messages are put into a queue. + */ + private static final class JGroupsReceiver extends ReceiverAdapter + { + private final BlockingQueue dequeue = new LinkedBlockingDeque(); + + @Override + public void receive(org.jgroups.Message msg) + { + dequeue.add(msg.getBuffer()); + } + + public byte[] receiveBroadcast() throws Exception + { + return dequeue.take(); + } + + public byte[] receiveBroadcast(long time, TimeUnit unit) throws Exception + { + return dequeue.poll(time, unit); + } + } + + /** + * This class wraps a JChannel with a reference counter. The reference counter + * controls the life of the JChannel. When reference count is zero, the channel + * will be disconnected. + */ + protected static class JChannelWrapper + { + int refCount = 1; + JChannel channel; + String channelName; + List receivers = new ArrayList(); + + public JChannelWrapper(String channelName, JChannel channel) throws Exception + { + this.refCount = 1; + this.channelName = channelName; + this.channel = channel; + } + + public synchronized void close() + { + refCount--; + if (refCount == 0) + { + JChannelManager.closeChannel(this.channelName, channel); + } + } + + public void removeReceiver(JGroupsReceiver receiver) + { + synchronized (receivers) + { + receivers.remove(receiver); + } + } + + public synchronized void connect() throws Exception + { + if (channel.isConnected()) return; + channel.setReceiver(new ReceiverAdapter() + { + + @Override + public void receive(org.jgroups.Message msg) + { + synchronized (receivers) + { + for (JGroupsReceiver r : receivers) + { + r.receive(msg); + } + } + } + }); + channel.connect(channelName); + } + + public void setReceiver(JGroupsReceiver jGroupsReceiver) + { + synchronized (receivers) + { + receivers.add(jGroupsReceiver); + } + } + + public void send(org.jgroups.Message msg) throws Exception + { + channel.send(msg); + } + + public JChannelWrapper addRef() + { + this.refCount++; + return this; + } + + @Override + public String toString() + { + return "JChannelWrapper of [" + channel + "] " + refCount + " " + channelName; + } + } + + /** + * This class maintain a global Map of JChannels wrapped in JChannelWrapper for + * the purpose of reference counting. + *

+ * Wherever a JChannel is needed it should only get it by calling the getChannel() + * method of this class. The real disconnect of channels are also done here only. + */ + protected static class JChannelManager + { + private static Map channels; + + public static synchronized JChannelWrapper getJChannel(String channelName, JGroupsBroadcastEndpoint endpoint) throws Exception + { + if (channels == null) + { + channels = new HashMap<>(); + } + JChannelWrapper wrapper = channels.get(channelName); + if (wrapper == null) + { + wrapper = new JChannelWrapper(channelName, endpoint.createChannel()); + channels.put(channelName, wrapper); + return wrapper; + } + return wrapper.addRef(); + } + + public static synchronized void closeChannel(String channelName, JChannel channel) + { + channel.setReceiver(null); + channel.disconnect(); + channel.close(); + JChannelWrapper wrapper = channels.remove(channelName); + if (wrapper == null) + { + throw new IllegalStateException("Did not find channel " + channelName); + } + } + } +} diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsBroadcastGroupConfiguration.java b/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsBroadcastGroupConfiguration.java deleted file mode 100644 index 9d2a0acfde..0000000000 --- a/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsBroadcastGroupConfiguration.java +++ /dev/null @@ -1,404 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.api.core; - -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingDeque; -import java.util.concurrent.TimeUnit; - -import org.jgroups.JChannel; -import org.jgroups.Message; -import org.jgroups.ReceiverAdapter; -import org.jgroups.conf.PlainConfigurator; - -/** - * The configuration for creating broadcasting/discovery groups using JGroups channels - * There are two ways to constructing a JGroups channel (JChannel): - *

    - *
  1. by passing in a JGroups configuration file
    - * The file must exists in the activemq classpath. ActiveMQ creates a JChannel with the - * configuration file and use it for broadcasting and discovery. In standalone server - * mode ActiveMQ uses this way for constructing JChannels.
  2. - *
  3. by passing in a JChannel instance
    - * This is useful when ActiveMQ needs to get a JChannel from a running JGroups service as in the - * case of AS7 integration.
  4. - *
- *

- * Note only one JChannel is needed in a VM. To avoid the channel being prematurely disconnected - * by any party, a wrapper class is used. - * - * @author Andy Taylor - * @author Howard Gao - * @see JChannelWrapper, JChannelManager - */ -public final class JGroupsBroadcastGroupConfiguration implements BroadcastEndpointFactoryConfiguration, DiscoveryGroupConfigurationCompatibilityHelper -{ - private static final long serialVersionUID = 8952238567248461285L; - - private final BroadcastEndpointFactory factory; - - public JGroupsBroadcastGroupConfiguration(final String jgroupsFile, final String channelName) - { - factory = new BroadcastEndpointFactory() - { - private static final long serialVersionUID = 1047956472941098435L; - - @Override - public BroadcastEndpoint createBroadcastEndpoint() throws Exception - { - JGroupsBroadcastEndpoint endpoint = new JGroupsBroadcastEndpoint(); - endpoint.initChannel(jgroupsFile, channelName); - return endpoint; - } - }; - } - - public JGroupsBroadcastGroupConfiguration(final JChannel channel, final String channelName) - { - factory = new BroadcastEndpointFactory() - { - private static final long serialVersionUID = 5110372849181145377L; - - @Override - public BroadcastEndpoint createBroadcastEndpoint() throws Exception - { - JGroupsBroadcastEndpoint endpoint = new JGroupsBroadcastEndpoint(); - endpoint.initChannel(channel, channelName); - return endpoint; - } - }; - } - - @Override - public BroadcastEndpointFactory createBroadcastEndpointFactory() - { - return factory; - } - - @Override - public String getLocalBindAddress() - { - return null; - } - - @Override - /* - * return -1 to force deserialization of object - * */ - public int getLocalBindPort() - { - return -1; - } - - @Override - public String getGroupAddress() - { - return null; - } - - @Override - public int getGroupPort() - { - return -1; - } - - /** - * This class is the implementation of ActiveMQ members discovery that will use JGroups. - * - * @author Howard Gao - */ - private static final class JGroupsBroadcastEndpoint implements BroadcastEndpoint - { - private boolean clientOpened; - - private boolean broadcastOpened; - - private JChannelWrapper channel; - - private JGroupsReceiver receiver; - - public void broadcast(final byte[] data) throws Exception - { - if (broadcastOpened) - { - Message msg = new Message(); - - msg.setBuffer(data); - - channel.send(msg); - } - } - - public byte[] receiveBroadcast() throws Exception - { - if (clientOpened) - { - return receiver.receiveBroadcast(); - } - else - { - return null; - } - } - - public byte[] receiveBroadcast(long time, TimeUnit unit) throws Exception - { - if (clientOpened) - { - return receiver.receiveBroadcast(time, unit); - } - else - { - return null; - } - } - - public synchronized void openClient() throws Exception - { - if (clientOpened) - { - return; - } - internalOpen(); - receiver = new JGroupsReceiver(); - channel.setReceiver(receiver); - clientOpened = true; - } - - public synchronized void openBroadcaster() throws Exception - { - if (broadcastOpened) return; - internalOpen(); - broadcastOpened = true; - } - - private void initChannel(final String jgroupsConfig, final String channelName) throws Exception - { - PlainConfigurator configurator = new PlainConfigurator(jgroupsConfig); - try - { - this.channel = JChannelManager.getJChannel(channelName, configurator); - return; - } - catch (Exception e) - { - this.channel = null; - } - URL configURL = Thread.currentThread().getContextClassLoader().getResource(jgroupsConfig); - - if (configURL == null) - { - throw new RuntimeException("couldn't find JGroups configuration " + jgroupsConfig); - } - this.channel = JChannelManager.getJChannel(channelName, configURL); - } - - private void initChannel(final JChannel channel1, final String channelName) throws Exception - { - this.channel = JChannelManager.getJChannel(channelName, channel1); - } - - protected void internalOpen() throws Exception - { - channel.connect(); - } - - public synchronized void close(boolean isBroadcast) throws Exception - { - if (isBroadcast) - { - broadcastOpened = false; - } - else - { - channel.removeReceiver(receiver); - clientOpened = false; - } - channel.close(); - } - - /** - * This class is used to receive messages from a JGroups channel. - * Incoming messages are put into a queue. - */ - private static final class JGroupsReceiver extends ReceiverAdapter - { - private final BlockingQueue dequeue = new LinkedBlockingDeque(); - - @Override - public void receive(org.jgroups.Message msg) - { - dequeue.add(msg.getBuffer()); - } - - public byte[] receiveBroadcast() throws Exception - { - return dequeue.take(); - } - - public byte[] receiveBroadcast(long time, TimeUnit unit) throws Exception - { - return dequeue.poll(time, unit); - } - } - - /** - * This class wraps a JChannel with a reference counter. The reference counter - * controls the life of the JChannel. When reference count is zero, the channel - * will be disconnected. - * - * @param - */ - private static class JChannelWrapper - { - int refCount = 1; - JChannel channel; - String channelName; - List receivers = new ArrayList(); - - public JChannelWrapper(String channelName, T t) throws Exception - { - this.refCount = 1; - this.channelName = channelName; - if (t instanceof URL) - { - this.channel = new JChannel((URL) t); - } - else if (t instanceof JChannel) - { - this.channel = (JChannel) t; - } - else if (t instanceof PlainConfigurator) - { - this.channel = new JChannel((PlainConfigurator)t); - } - else - { - throw new IllegalArgumentException("Unsupported type " + t); - } - } - - public synchronized void close() - { - refCount--; - if (refCount == 0) - { - JChannelManager.closeChannel(this.channelName, channel); - } - } - - public void removeReceiver(JGroupsReceiver receiver) - { - synchronized (receivers) - { - receivers.remove(receiver); - } - } - - public synchronized void connect() throws Exception - { - if (channel.isConnected()) return; - channel.setReceiver(new ReceiverAdapter() - { - - @Override - public void receive(Message msg) - { - synchronized (receivers) - { - for (JGroupsReceiver r : receivers) - { - r.receive(msg); - } - } - } - }); - channel.connect(channelName); - } - - public void setReceiver(JGroupsReceiver jGroupsReceiver) - { - synchronized (receivers) - { - receivers.add(jGroupsReceiver); - } - } - - public void send(Message msg) throws Exception - { - channel.send(msg); - } - - public JChannelWrapper addRef() - { - this.refCount++; - return this; - } - - @Override - public String toString() - { - return "JChannelWrapper of [" + channel + "] " + refCount + " " + channelName; - } - } - - /** - * This class maintain a global Map of JChannels wrapped in JChannelWrapper for - * the purpose of reference counting. - *

- * Wherever a JChannel is needed it should only get it by calling the getChannel() - * method of this class. The real disconnect of channels are also done here only. - */ - private static class JChannelManager - { - private static Map> channels; - - public static synchronized JChannelWrapper getJChannel(String channelName, T t) throws Exception - { - if (channels == null) - { - channels = new HashMap>(); - } - JChannelWrapper wrapper = channels.get(channelName); - if (wrapper == null) - { - wrapper = new JChannelWrapper(channelName, t); - channels.put(channelName, wrapper); - return wrapper; - } - return wrapper.addRef(); - } - - public static synchronized void closeChannel(String channelName, JChannel channel) - { - channel.setReceiver(null); - channel.disconnect(); - channel.close(); - JChannelWrapper wrapper = channels.remove(channelName); - if (wrapper == null) - { - throw new IllegalStateException("Did not find channel " + channelName); - } - } - } - } -} diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/DiscoveryGroupConfigurationCompatibilityHelper.java b/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsChannelBroadcastEndpoint.java similarity index 54% rename from activemq-core-client/src/main/java/org/apache/activemq/api/core/DiscoveryGroupConfigurationCompatibilityHelper.java rename to activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsChannelBroadcastEndpoint.java index 4fd1bca7ae..e14d0f09d7 100644 --- a/activemq-core-client/src/main/java/org/apache/activemq/api/core/DiscoveryGroupConfigurationCompatibilityHelper.java +++ b/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsChannelBroadcastEndpoint.java @@ -16,30 +16,24 @@ */ package org.apache.activemq.api.core; +import org.jgroups.JChannel; + /** - * This interface is needed for making a DiscoveryGroupConfiguration backward - * compatible with version 2.2 clients. It is used to extract from new - * {@link org.apache.activemq.api.core.BroadcastEndpointFactoryConfiguration} the four - * UDP attributes in order to form a version 2.2 DiscoveryGroupConfiguration - * in time of serialization. - * - * @see DiscoveryGroupConfiguration#readObject(java.io.ObjectInputStream) - * @see DiscoveryGroupConfiguration#writeObject(java.io.ObjectOutputStream) - * * @author Andy Taylor - * 12/13/12 */ -public interface DiscoveryGroupConfigurationCompatibilityHelper +public class JGroupsChannelBroadcastEndpoint extends JGroupsBroadcastEndpoint { -// XXX No javadocs - String getLocalBindAddress(); + private final JChannel jChannel; -// XXX No javadocs - int getLocalBindPort(); + public JGroupsChannelBroadcastEndpoint(JChannel jChannel, final String channelName) throws Exception + { + super(channelName); + this.jChannel = jChannel; + } -// XXX No javadocs - String getGroupAddress(); - -// XXX No javadocs - int getGroupPort(); + @Override + public JChannel createChannel() throws Exception + { + return jChannel; + } } diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsFileBroadcastEndpoint.java b/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsFileBroadcastEndpoint.java new file mode 100644 index 0000000000..6f0b8adb09 --- /dev/null +++ b/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsFileBroadcastEndpoint.java @@ -0,0 +1,49 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.api.core; + +import org.jgroups.JChannel; + +import java.net.URL; + +/** + * This class is the implementation of ActiveMQ members discovery that will use JGroups. + * + * @author Howard Gao + */ +public final class JGroupsFileBroadcastEndpoint extends JGroupsBroadcastEndpoint +{ + private String file; + + public JGroupsFileBroadcastEndpoint(final String file, final String channelName) throws Exception + { + super(channelName); + this.file = file; + } + + public JChannel createChannel() throws Exception + { + URL configURL = Thread.currentThread().getContextClassLoader().getResource(file); + + if (configURL == null) + { + throw new RuntimeException("couldn't find JGroups configuration " + file); + } + + return new JChannel(configURL); + } +} diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsFileBroadcastEndpointFactory.java b/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsFileBroadcastEndpointFactory.java new file mode 100644 index 0000000000..21bef7ac02 --- /dev/null +++ b/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsFileBroadcastEndpointFactory.java @@ -0,0 +1,55 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.api.core; + +/** +* @author Andy Taylor +*/ +public class JGroupsFileBroadcastEndpointFactory implements BroadcastEndpointFactory +{ + private String file; + + private String channelName; + + @Override + public BroadcastEndpoint createBroadcastEndpoint() throws Exception + { + return new JGroupsFileBroadcastEndpoint(file, channelName).initChannel(); + } + + public String getFile() + { + return file; + } + + public JGroupsFileBroadcastEndpointFactory setFile(String file) + { + this.file = file; + return this; + } + + public String getChannelName() + { + return channelName; + } + + public JGroupsFileBroadcastEndpointFactory setChannelName(String channelName) + { + this.channelName = channelName; + return this; + } +} diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsPropertiesBroadcastEndpoint.java b/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsPropertiesBroadcastEndpoint.java new file mode 100644 index 0000000000..ddc5c19a7d --- /dev/null +++ b/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsPropertiesBroadcastEndpoint.java @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.api.core; + +import org.jgroups.JChannel; +import org.jgroups.conf.PlainConfigurator; + +/** + * This class is the implementation of ActiveMQ members discovery that will use JGroups. + * + * @author Howard Gao + */ +public final class JGroupsPropertiesBroadcastEndpoint extends JGroupsBroadcastEndpoint +{ + private String properties; + + public JGroupsPropertiesBroadcastEndpoint(final String properties, final String channelName) throws Exception + { + super(channelName); + this.properties = properties; + } + + @Override + public JChannel createChannel() throws Exception + { + PlainConfigurator configurator = new PlainConfigurator(properties); + return new JChannel(configurator); + } +} diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsPropertiesBroadcastEndpointFactory.java b/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsPropertiesBroadcastEndpointFactory.java new file mode 100644 index 0000000000..b9d06b9a9f --- /dev/null +++ b/activemq-core-client/src/main/java/org/apache/activemq/api/core/JGroupsPropertiesBroadcastEndpointFactory.java @@ -0,0 +1,55 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.api.core; + +/** +* @author Andy Taylor +*/ +public class JGroupsPropertiesBroadcastEndpointFactory implements BroadcastEndpointFactory +{ + private String properties; + + private String channelName; + + @Override + public BroadcastEndpoint createBroadcastEndpoint() throws Exception + { + return new JGroupsPropertiesBroadcastEndpoint(properties, channelName).initChannel(); + } + + public String getProperties() + { + return properties; + } + + public JGroupsPropertiesBroadcastEndpointFactory setProperties(String properties) + { + this.properties = properties; + return this; + } + + public String getChannelName() + { + return channelName; + } + + public JGroupsPropertiesBroadcastEndpointFactory setChannelName(String channelName) + { + this.channelName = channelName; + return this; + } +} diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/UDPBroadcastGroupConfiguration.java b/activemq-core-client/src/main/java/org/apache/activemq/api/core/UDPBroadcastEndpointFactory.java similarity index 86% rename from activemq-core-client/src/main/java/org/apache/activemq/api/core/UDPBroadcastGroupConfiguration.java rename to activemq-core-client/src/main/java/org/apache/activemq/api/core/UDPBroadcastEndpointFactory.java index 5c84d79505..b2f6095505 100644 --- a/activemq-core-client/src/main/java/org/apache/activemq/api/core/UDPBroadcastGroupConfiguration.java +++ b/activemq-core-client/src/main/java/org/apache/activemq/api/core/UDPBroadcastEndpointFactory.java @@ -36,10 +36,8 @@ import org.apache.activemq.core.client.ActiveMQClientLogger; * * @author Tim Fox Created 18 Nov 2008 08:44:30 */ -public final class UDPBroadcastGroupConfiguration implements BroadcastEndpointFactoryConfiguration, DiscoveryGroupConfigurationCompatibilityHelper +public final class UDPBroadcastEndpointFactory implements BroadcastEndpointFactory { - private static final long serialVersionUID = 1052413739064253955L; - private transient String localBindAddress = null; private transient int localBindPort = -1; @@ -48,24 +46,17 @@ public final class UDPBroadcastGroupConfiguration implements BroadcastEndpointFa private int groupPort = -1; - public UDPBroadcastGroupConfiguration() + public UDPBroadcastEndpointFactory() { } - public BroadcastEndpointFactory createBroadcastEndpointFactory() + public BroadcastEndpoint createBroadcastEndpoint() throws Exception { - return new BroadcastEndpointFactory() - { - @Override - public BroadcastEndpoint createBroadcastEndpoint() throws Exception - { - return new UDPBroadcastEndpoint() - .setGroupAddress(groupAddress != null ? InetAddress.getByName(groupAddress) : null) - .setGroupPort(groupPort) - .setLocalBindAddress(localBindAddress != null ? InetAddress.getByName(localBindAddress) : null) - .setLocalBindPort(localBindPort); - } - }; + return new UDPBroadcastEndpoint() + .setGroupAddress(groupAddress != null ? InetAddress.getByName(groupAddress) : null) + .setGroupPort(groupPort) + .setLocalBindAddress(localBindAddress != null ? InetAddress.getByName(localBindAddress) : null) + .setLocalBindPort(localBindPort); } public String getGroupAddress() @@ -73,7 +64,7 @@ public final class UDPBroadcastGroupConfiguration implements BroadcastEndpointFa return groupAddress; } - public UDPBroadcastGroupConfiguration setGroupAddress(String groupAddress) + public UDPBroadcastEndpointFactory setGroupAddress(String groupAddress) { this.groupAddress = groupAddress; return this; @@ -84,7 +75,7 @@ public final class UDPBroadcastGroupConfiguration implements BroadcastEndpointFa return groupPort; } - public UDPBroadcastGroupConfiguration setGroupPort(int groupPort) + public UDPBroadcastEndpointFactory setGroupPort(int groupPort) { this.groupPort = groupPort; return this; @@ -95,7 +86,7 @@ public final class UDPBroadcastGroupConfiguration implements BroadcastEndpointFa return localBindPort; } - public UDPBroadcastGroupConfiguration setLocalBindPort(int localBindPort) + public UDPBroadcastEndpointFactory setLocalBindPort(int localBindPort) { this.localBindPort = localBindPort; return this; @@ -106,7 +97,7 @@ public final class UDPBroadcastGroupConfiguration implements BroadcastEndpointFa return localBindAddress; } - public UDPBroadcastGroupConfiguration setLocalBindAddress(String localBindAddress) + public UDPBroadcastEndpointFactory setLocalBindAddress(String localBindAddress) { this.localBindAddress = localBindAddress; return this; @@ -324,7 +315,7 @@ public final class UDPBroadcastGroupConfiguration implements BroadcastEndpointFa return false; if (getClass() != obj.getClass()) return false; - UDPBroadcastGroupConfiguration other = (UDPBroadcastGroupConfiguration) obj; + UDPBroadcastEndpointFactory other = (UDPBroadcastEndpointFactory) obj; if (groupAddress == null) { if (other.groupAddress != null) diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/client/ActiveMQClient.java b/activemq-core-client/src/main/java/org/apache/activemq/api/core/client/ActiveMQClient.java index 1dc004e330..90c0f6e4a9 100644 --- a/activemq-core-client/src/main/java/org/apache/activemq/api/core/client/ActiveMQClient.java +++ b/activemq-core-client/src/main/java/org/apache/activemq/api/core/client/ActiveMQClient.java @@ -21,6 +21,9 @@ import org.apache.activemq.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.api.core.TransportConfiguration; import org.apache.activemq.api.core.client.loadbalance.RoundRobinConnectionLoadBalancingPolicy; import org.apache.activemq.core.client.impl.ServerLocatorImpl; +import org.apache.activemq.uri.ServerLocatorParser; + +import java.net.URI; /** * Utility class for creating ActiveMQ {@link ClientSessionFactory} objects. @@ -112,6 +115,17 @@ public final class ActiveMQClient public static final String DEFAULT_CORE_PROTOCOL = "CORE"; + /** + * Creates a ActiveMQConnectionFactory; + * + * @return the ActiveMQConnectionFactory + */ + public static ServerLocator createServerLocator(final String url) throws Exception + { + ServerLocatorParser parser = new ServerLocatorParser(); + return parser.newObject(new URI(url)); + } + /** * Create a ServerLocator which creates session factories using a static list of transportConfigurations, the ServerLocator is not updated automatically * as the cluster topology changes, and no HA backup information is propagated to the client diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/client/TopologyMember.java b/activemq-core-client/src/main/java/org/apache/activemq/api/core/client/TopologyMember.java index dd9e95a93f..72b13742a2 100644 --- a/activemq-core-client/src/main/java/org/apache/activemq/api/core/client/TopologyMember.java +++ b/activemq-core-client/src/main/java/org/apache/activemq/api/core/client/TopologyMember.java @@ -16,8 +16,6 @@ */ package org.apache.activemq.api.core.client; -import java.io.Serializable; - import org.apache.activemq.api.core.TransportConfiguration; import org.apache.activemq.spi.core.protocol.RemotingConnection; @@ -27,7 +25,7 @@ import org.apache.activemq.spi.core.protocol.RemotingConnection; * Each TopologyMember represents a single server and possibly any backup server that may take over * its duties (using the nodeId of the original server). */ -public interface TopologyMember extends Serializable +public interface TopologyMember { /** * Returns the {@code backup-group-name} of the live server and backup servers associated with diff --git a/activemq-core-client/src/main/java/org/apache/activemq/core/client/impl/ServerLocatorImpl.java b/activemq-core-client/src/main/java/org/apache/activemq/core/client/impl/ServerLocatorImpl.java index 268f9c70da..db0b34c787 100644 --- a/activemq-core-client/src/main/java/org/apache/activemq/core/client/impl/ServerLocatorImpl.java +++ b/activemq-core-client/src/main/java/org/apache/activemq/core/client/impl/ServerLocatorImpl.java @@ -72,13 +72,8 @@ import org.apache.activemq.utils.UUIDGenerator; * * @author Tim Fox */ -public final class ServerLocatorImpl implements ServerLocatorInternal, DiscoveryListener, Serializable +public final class ServerLocatorImpl implements ServerLocatorInternal, DiscoveryListener { - /*needed for backward compatibility*/ - @SuppressWarnings("unused") - private final Set topologyListeners = new HashSet(); - - /*end of compatibility fixes*/ private enum STATE { INITIALIZED, CLOSED, CLOSING @@ -398,7 +393,7 @@ public final class ServerLocatorImpl implements ServerLocatorInternal, Discovery private static DiscoveryGroup createDiscoveryGroup(String nodeID, DiscoveryGroupConfiguration config) throws Exception { DiscoveryGroup group = new DiscoveryGroup(nodeID, config.getName(), - config.getRefreshTimeout(), config.getBroadcastEndpointFactoryConfiguration().createBroadcastEndpointFactory(), null); + config.getRefreshTimeout(), config.getBroadcastEndpointFactory(), null); return group; } diff --git a/activemq-core-client/src/main/java/org/apache/activemq/spi/core/remoting/ClientProtocolManagerFactory.java b/activemq-core-client/src/main/java/org/apache/activemq/spi/core/remoting/ClientProtocolManagerFactory.java index 9eeffd5283..e90488b849 100644 --- a/activemq-core-client/src/main/java/org/apache/activemq/spi/core/remoting/ClientProtocolManagerFactory.java +++ b/activemq-core-client/src/main/java/org/apache/activemq/spi/core/remoting/ClientProtocolManagerFactory.java @@ -16,12 +16,10 @@ */ package org.apache.activemq.spi.core.remoting; -import java.io.Serializable; - /** * @author Clebert Suconic */ -public interface ClientProtocolManagerFactory extends Serializable +public interface ClientProtocolManagerFactory { ClientProtocolManager newProtocolManager(); diff --git a/activemq-core-client/src/main/java/org/apache/activemq/uri/AbstractServerLocatorSchema.java b/activemq-core-client/src/main/java/org/apache/activemq/uri/AbstractServerLocatorSchema.java new file mode 100644 index 0000000000..01297f4c10 --- /dev/null +++ b/activemq-core-client/src/main/java/org/apache/activemq/uri/AbstractServerLocatorSchema.java @@ -0,0 +1,34 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.uri; + +import org.apache.activemq.api.core.client.ServerLocator; +import org.apache.activemq.utils.uri.URISchema; + +import java.net.URI; +import java.util.Map; + +/** + * @author Andy Taylor + */ +public abstract class AbstractServerLocatorSchema extends URISchema +{ + protected ConnectionOptions newConnectionOptions(URI uri, Map query) throws Exception + { + return setData(uri, new ConnectionOptions(), query); + } +} diff --git a/activemq-core-client/src/main/java/org/apache/activemq/uri/ConnectionOptions.java b/activemq-core-client/src/main/java/org/apache/activemq/uri/ConnectionOptions.java new file mode 100644 index 0000000000..9c69ad286e --- /dev/null +++ b/activemq-core-client/src/main/java/org/apache/activemq/uri/ConnectionOptions.java @@ -0,0 +1,75 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.uri; +/** + * This will represent all the possible options you could setup on URLs + * When parsing the URL this will serve as an intermediate object + * And it could also be a pl + * @author clebertsuconic + */ + +public class ConnectionOptions +{ + + private boolean ha; + + private String host; + + private int port; + + public ConnectionOptions setHost(String host) + { + this.host = host; + return this; + } + + public String getHost() + { + return host; + } + + + public ConnectionOptions setPort(int port) + { + this.port = port; + return this; + } + + public int getPort() + { + return port; + } + + public boolean isHa() + { + return ha; + } + + public void setHa(boolean ha) + { + this.ha = ha; + } + + @Override + public String toString() + { + return "ConnectionOptions{" + + "ha=" + ha + + '}'; + } +} diff --git a/activemq-core-client/src/main/java/org/apache/activemq/uri/InVMServerLocatorSchema.java b/activemq-core-client/src/main/java/org/apache/activemq/uri/InVMServerLocatorSchema.java new file mode 100644 index 0000000000..54c3254f42 --- /dev/null +++ b/activemq-core-client/src/main/java/org/apache/activemq/uri/InVMServerLocatorSchema.java @@ -0,0 +1,73 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.uri; + +import org.apache.activemq.api.core.TransportConfiguration; +import org.apache.activemq.api.core.client.ActiveMQClient; +import org.apache.activemq.api.core.client.ServerLocator; +import org.apache.activemq.utils.uri.SchemaConstants; +import org.apache.activemq.utils.uri.URISchema; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Map; + +/** + * @author Andy Taylor + */ +public class InVMServerLocatorSchema extends AbstractServerLocatorSchema +{ + @Override + public String getSchemaName() + { + return SchemaConstants.VM; + } + + @Override + protected ServerLocator internalNewObject(URI uri, Map query) throws Exception + { + TransportConfiguration tc = createTransportConfiguration(uri); + ServerLocator factory = ActiveMQClient.createServerLocatorWithoutHA(tc); + return URISchema.setData(uri, factory, query); + } + + public static TransportConfiguration createTransportConfiguration(URI uri) + { + Map inVmTransportConfig = new HashMap<>(); + inVmTransportConfig.put("serverId", uri.getHost()); + return new TransportConfiguration("org.apache.activemq.core.remoting.impl.invm.InVMConnectorFactory", inVmTransportConfig); + } + + @Override + protected URI internalNewURI(ServerLocator bean) throws Exception + { + return getUri(bean.getStaticTransportConfigurations()); + } + + public static URI getUri(TransportConfiguration[] configurations) throws URISyntaxException + { + String host = "0"; + if (configurations != null && configurations.length > 0) + { + TransportConfiguration configuration = configurations[0]; + Map params = configuration.getParams(); + host = params.get("serverId") == null ? host : params.get("serverId").toString(); + } + return new URI(SchemaConstants.VM, null, host, -1, null, null, null); + } +} diff --git a/activemq-core-client/src/main/java/org/apache/activemq/uri/JGroupsServerLocatorSchema.java b/activemq-core-client/src/main/java/org/apache/activemq/uri/JGroupsServerLocatorSchema.java new file mode 100644 index 0000000000..b840bcb64d --- /dev/null +++ b/activemq-core-client/src/main/java/org/apache/activemq/uri/JGroupsServerLocatorSchema.java @@ -0,0 +1,102 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.uri; + +import org.apache.activemq.api.core.BroadcastEndpointFactory; +import org.apache.activemq.api.core.DiscoveryGroupConfiguration; +import org.apache.activemq.api.core.JGroupsFileBroadcastEndpointFactory; +import org.apache.activemq.api.core.JGroupsPropertiesBroadcastEndpointFactory; +import org.apache.activemq.api.core.client.ActiveMQClient; +import org.apache.activemq.api.core.client.ServerLocator; +import org.apache.activemq.utils.uri.SchemaConstants; +import org.apache.activemq.utils.uri.URISchema; + +import java.io.NotSerializableException; +import java.net.URI; +import java.util.Map; + +/** + * @author Andy Taylor + */ +public class JGroupsServerLocatorSchema extends AbstractServerLocatorSchema +{ + @Override + public String getSchemaName() + { + return SchemaConstants.JGROUPS; + } + + @Override + protected ServerLocator internalNewObject(URI uri, Map query) throws Exception + { + ConnectionOptions options = newConnectionOptions(uri, query); + + DiscoveryGroupConfiguration dcConfig = getDiscoveryGroupConfiguration(uri, query); + + if (options.isHa()) + { + return ActiveMQClient.createServerLocatorWithHA(dcConfig); + } + else + { + return ActiveMQClient.createServerLocatorWithoutHA(dcConfig); + } + } + + @Override + protected URI internalNewURI(ServerLocator bean) throws Exception + { + DiscoveryGroupConfiguration dgc = bean.getDiscoveryGroupConfiguration(); + BroadcastEndpointFactory endpoint = dgc.getBroadcastEndpointFactory(); + String auth; + if (endpoint instanceof JGroupsFileBroadcastEndpointFactory) + { + auth = ((JGroupsFileBroadcastEndpointFactory) endpoint).getChannelName(); + } + else if (endpoint instanceof JGroupsPropertiesBroadcastEndpointFactory) + { + auth = ((JGroupsPropertiesBroadcastEndpointFactory) endpoint).getChannelName(); + } + else + { + throw new NotSerializableException(endpoint + "not serializable"); + } + String query = URISchema.getData(null, bean, dgc, endpoint); + dgc.setBroadcastEndpointFactory(endpoint); + return new URI(SchemaConstants.JGROUPS, null, auth, -1, null, query, null); + } + + public static DiscoveryGroupConfiguration getDiscoveryGroupConfiguration(URI uri, Map query) throws Exception + { + BroadcastEndpointFactory endpointFactory; + if (query.containsKey("file")) + { + endpointFactory = new JGroupsFileBroadcastEndpointFactory().setChannelName(uri.getAuthority()); + } + else + { + endpointFactory = new JGroupsPropertiesBroadcastEndpointFactory().setChannelName(uri.getAuthority()); + } + + URISchema.setData(uri, endpointFactory, query); + + DiscoveryGroupConfiguration dcConfig = new DiscoveryGroupConfiguration().setBroadcastEndpointFactory(endpointFactory); + + URISchema.setData(uri, dcConfig, query); + return dcConfig; + } +} diff --git a/activemq-core-client/src/main/java/org/apache/activemq/uri/ServerLocatorParser.java b/activemq-core-client/src/main/java/org/apache/activemq/uri/ServerLocatorParser.java new file mode 100644 index 0000000000..c77250ae20 --- /dev/null +++ b/activemq-core-client/src/main/java/org/apache/activemq/uri/ServerLocatorParser.java @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.uri; + +import org.apache.activemq.api.core.client.ServerLocator; +import org.apache.activemq.utils.uri.URIFactory; + +/** + * @author Andy Taylor + */ +public class ServerLocatorParser extends URIFactory +{ + public ServerLocatorParser() + { + registerSchema(new TCPServerLocatorSchema()); + registerSchema(new UDPServerLocatorSchema()); + registerSchema(new JGroupsServerLocatorSchema()); + } +} diff --git a/activemq-core-client/src/main/java/org/apache/activemq/uri/TCPServerLocatorSchema.java b/activemq-core-client/src/main/java/org/apache/activemq/uri/TCPServerLocatorSchema.java new file mode 100644 index 0000000000..ee92c84cf9 --- /dev/null +++ b/activemq-core-client/src/main/java/org/apache/activemq/uri/TCPServerLocatorSchema.java @@ -0,0 +1,160 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.uri; + +import org.apache.activemq.api.core.TransportConfiguration; +import org.apache.activemq.api.core.client.ActiveMQClient; +import org.apache.activemq.api.core.client.ServerLocator; +import org.apache.activemq.core.remoting.impl.netty.NettyConnectorFactory; +import org.apache.activemq.core.remoting.impl.netty.TransportConstants; +import org.apache.activemq.utils.uri.SchemaConstants; +import org.apache.activemq.utils.uri.URISchema; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Andy Taylor + */ +public class TCPServerLocatorSchema extends AbstractServerLocatorSchema +{ + @Override + public String getSchemaName() + { + return SchemaConstants.TCP; + } + + @Override + protected ServerLocator internalNewObject(URI uri, Map query) throws Exception + { + ConnectionOptions options = newConnectionOptions(uri, query); + + TransportConfiguration[] configurations = getTransportConfigurations(uri, query); + + if (options.isHa()) + { + return ActiveMQClient.createServerLocatorWithHA(configurations); + } + else + { + return ActiveMQClient.createServerLocatorWithoutHA(configurations); + } + } + + public static TransportConfiguration[] getTransportConfigurations(URI uri, Map query) throws URISyntaxException + { + HashMap props = new HashMap<>(); + + URISchema.setData(uri, props, TransportConstants.ALLOWABLE_CONNECTOR_KEYS, query); + List transportConfigurations = new ArrayList<>(); + + transportConfigurations.add(new TransportConfiguration(NettyConnectorFactory.class.getName(), + props, + uri.toString())); + String connectors = uri.getFragment(); + + if (connectors != null) + { + String[] split = connectors.split(","); + for (String s : split) + { + URI extraUri = new URI(s); + HashMap newProps = new HashMap<>(); + URISchema.setData(extraUri, newProps, TransportConstants.ALLOWABLE_CONNECTOR_KEYS, query); + URISchema.setData(extraUri, newProps, TransportConstants.ALLOWABLE_CONNECTOR_KEYS, URISchema.parseQuery(extraUri.getQuery(), null)); + transportConfigurations.add(new TransportConfiguration(NettyConnectorFactory.class.getName(), + newProps, + extraUri.toString())); + } + } + TransportConfiguration[] configurations = new TransportConfiguration[transportConfigurations.size()]; + transportConfigurations.toArray(configurations); + return configurations; + } + + @Override + protected URI internalNewURI(ServerLocator bean) throws Exception + { + String query = URISchema.getData(null, bean); + TransportConfiguration[] staticConnectors = bean.getStaticTransportConfigurations(); + return getURI(query, staticConnectors); + } + + public static URI getURI(String query, TransportConfiguration[] staticConnectors) throws Exception + { + if (staticConnectors == null || staticConnectors.length < 1) + { + throw new Exception(); + } + StringBuilder fragment = new StringBuilder(); + for (int i = 1; i < staticConnectors.length; i++) + { + TransportConfiguration connector = staticConnectors[i]; + Map params = connector.getParams(); + URI extraUri = new URI(SchemaConstants.TCP, null, getHost(params), getPort(params), null, createQuery(params, null), null); + if (i > 1) + { + fragment.append(","); + } + fragment.append(extraUri.toASCIIString()); + + } + Map params = staticConnectors[0].getParams(); + return new URI(SchemaConstants.TCP, null, getHost(params), getPort(params), null, createQuery(params, query), fragment.toString()); + } + + private static int getPort(Map params) + { + Object port = params.get("port"); + if (port instanceof String) + { + return Integer.valueOf((String) port); + } + return port != null ? (int) port : 5445; + } + + private static String getHost(Map params) + { + return params.get("host") != null ? (String) params.get("host") : "localhost"; + } + + private static String createQuery(Map params, String query) + { + StringBuilder cb; + if (query == null) + { + cb = new StringBuilder(); + } + else + { + cb = new StringBuilder(query); + } + for (String param : params.keySet()) + { + if (cb.length() > 0) + { + cb.append("&"); + } + cb.append(param).append("=").append(params.get(param)); + } + return cb.toString(); + } +} diff --git a/activemq-core-client/src/main/java/org/apache/activemq/uri/UDPServerLocatorSchema.java b/activemq-core-client/src/main/java/org/apache/activemq/uri/UDPServerLocatorSchema.java new file mode 100644 index 0000000000..ef1d96b73c --- /dev/null +++ b/activemq-core-client/src/main/java/org/apache/activemq/uri/UDPServerLocatorSchema.java @@ -0,0 +1,89 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.uri; + +import org.apache.activemq.api.core.DiscoveryGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; +import org.apache.activemq.api.core.client.ActiveMQClient; +import org.apache.activemq.api.core.client.ServerLocator; +import org.apache.activemq.utils.uri.SchemaConstants; +import org.apache.activemq.utils.uri.URISchema; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author Andy Taylor + */ +public class UDPServerLocatorSchema extends AbstractServerLocatorSchema +{ + protected static List IGNORED = new ArrayList<>(); + static + { + IGNORED.add("localBindAddress"); + IGNORED.add("localBindPort"); + } + @Override + public String getSchemaName() + { + return SchemaConstants.UDP; + } + + @Override + protected ServerLocator internalNewObject(URI uri, Map query) throws Exception + { + ConnectionOptions options = newConnectionOptions(uri, query); + + DiscoveryGroupConfiguration dgc = getDiscoveryGroupConfiguration(uri, query, getHost(uri), getPort(uri)); + + if (options.isHa()) + { + return ActiveMQClient.createServerLocatorWithHA(dgc); + } + else + { + return ActiveMQClient.createServerLocatorWithoutHA(dgc); + } + } + + @Override + protected URI internalNewURI(ServerLocator bean) throws Exception + { + DiscoveryGroupConfiguration dgc = bean.getDiscoveryGroupConfiguration(); + UDPBroadcastEndpointFactory endpoint = (UDPBroadcastEndpointFactory) dgc.getBroadcastEndpointFactory(); + dgc.setBroadcastEndpointFactory(endpoint); + String query = URISchema.getData(IGNORED, bean, dgc, endpoint); + return new URI(SchemaConstants.UDP, null, endpoint.getGroupAddress(), endpoint.getGroupPort(), null, query, null); + } + + public static DiscoveryGroupConfiguration getDiscoveryGroupConfiguration(URI uri, Map query, String host, int port) throws Exception + { + UDPBroadcastEndpointFactory endpointFactoryConfiguration = new UDPBroadcastEndpointFactory() + .setGroupAddress(host) + .setGroupPort(port); + + URISchema.setData(uri, endpointFactoryConfiguration, query); + + DiscoveryGroupConfiguration dgc = URISchema.setData(uri, new DiscoveryGroupConfiguration(), query) + .setBroadcastEndpointFactory(endpointFactoryConfiguration); + + URISchema.setData(uri, dgc, query); + return dgc; + } +} diff --git a/activemq-jms-client/pom.xml b/activemq-jms-client/pom.xml index c40729ac29..629b8ee441 100644 --- a/activemq-jms-client/pom.xml +++ b/activemq-jms-client/pom.xml @@ -37,6 +37,13 @@ org.jboss.logging jboss-logging-processor + + org.apache.activemq + activemq-core-client + ${project.version} + test + test-jar + org.apache.activemq activemq-core-client diff --git a/activemq-jms-client/src/main/java/org/apache/activemq/api/jms/ActiveMQJMSClient.java b/activemq-jms-client/src/main/java/org/apache/activemq/api/jms/ActiveMQJMSClient.java index 8649459a00..181de27d05 100644 --- a/activemq-jms-client/src/main/java/org/apache/activemq/api/jms/ActiveMQJMSClient.java +++ b/activemq-jms-client/src/main/java/org/apache/activemq/api/jms/ActiveMQJMSClient.java @@ -29,6 +29,9 @@ import org.apache.activemq.jms.client.ActiveMQTopicConnectionFactory; import org.apache.activemq.jms.client.ActiveMQXAConnectionFactory; import org.apache.activemq.jms.client.ActiveMQXAQueueConnectionFactory; import org.apache.activemq.jms.client.ActiveMQXATopicConnectionFactory; +import org.apache.activemq.uri.ConnectionFactoryParser; + +import java.net.URI; /** * A utility class for creating ActiveMQ client-side JMS managed resources. @@ -37,6 +40,16 @@ import org.apache.activemq.jms.client.ActiveMQXATopicConnectionFactory; */ public class ActiveMQJMSClient { + /** + * Creates a ActiveMQConnectionFactory; + * + * @return the ActiveMQConnectionFactory + */ + public static ActiveMQConnectionFactory createConnectionFactory(final String url) throws Exception + { + ConnectionFactoryParser parser = new ConnectionFactoryParser(); + return parser.newObject(new URI(url)); + } /** * Creates a ActiveMQConnectionFactory that receives cluster topology updates from the cluster as diff --git a/activemq-jms-client/src/main/java/org/apache/activemq/jms/client/ActiveMQConnectionFactory.java b/activemq-jms-client/src/main/java/org/apache/activemq/jms/client/ActiveMQConnectionFactory.java index 5ec04d0b5d..5383077781 100644 --- a/activemq-jms-client/src/main/java/org/apache/activemq/jms/client/ActiveMQConnectionFactory.java +++ b/activemq-jms-client/src/main/java/org/apache/activemq/jms/client/ActiveMQConnectionFactory.java @@ -33,16 +33,24 @@ import javax.jms.XATopicConnection; import javax.naming.NamingException; import javax.naming.Reference; import javax.naming.Referenceable; -import java.io.Serializable; +import java.io.Externalizable; +import java.io.IOException; +import java.io.InvalidObjectException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.net.URI; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.api.core.TransportConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.core.client.ClientSessionFactory; import org.apache.activemq.api.core.client.ActiveMQClient; import org.apache.activemq.api.core.client.ServerLocator; import org.apache.activemq.api.jms.JMSFactoryType; import org.apache.activemq.jms.referenceable.ConnectionFactoryObjectFactory; import org.apache.activemq.jms.referenceable.SerializableObjectRefAddr; +import org.apache.activemq.uri.ConnectionFactoryParser; +import org.apache.activemq.uri.ServerLocatorParser; /** * ActiveMQ implementation of a JMS ConnectionFactory. @@ -50,11 +58,9 @@ import org.apache.activemq.jms.referenceable.SerializableObjectRefAddr; * @author Ovidiu Feodorov * @author Tim Fox */ -public class ActiveMQConnectionFactory implements Serializable, Referenceable, ConnectionFactory, XAConnectionFactory +public class ActiveMQConnectionFactory implements Externalizable, Referenceable, ConnectionFactory, XAConnectionFactory { - private static final long serialVersionUID = -2810634789345348326L; - - private final ServerLocator serverLocator; + private ServerLocator serverLocator; private String clientID; @@ -62,7 +68,58 @@ public class ActiveMQConnectionFactory implements Serializable, Referenceable, C private int transactionBatchSize = ActiveMQClient.DEFAULT_ACK_BATCH_SIZE; - private boolean readOnly; + private boolean readOnly; + + public void writeExternal(ObjectOutput out) throws IOException + { + ConnectionFactoryParser parser = new ConnectionFactoryParser(); + String scheme; + if (serverLocator.getDiscoveryGroupConfiguration() != null) + { + if (serverLocator.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory() instanceof UDPBroadcastEndpointFactory) + { + scheme = "udp"; + } + else + { + scheme = "jgroups"; + } + } + else + { + scheme = "tcp"; + } + try + { + URI uri = parser.createSchema(scheme, this); + out.writeUTF(uri.toASCIIString()); + } + catch (Exception e) + { + if (e instanceof IOException) + { + throw (IOException) e; + } + throw new IOException(e); + } + } + + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException + { + String url = in.readUTF(); + ConnectionFactoryParser parser = new ConnectionFactoryParser(); + ServerLocatorParser locatorParser = new ServerLocatorParser(); + try + { + URI uri = new URI(url); + serverLocator = locatorParser.newObject(uri); + parser.populateObject(uri, this); + } + catch (Exception e) + { + throw new InvalidObjectException(e.getMessage()); + } + } public ActiveMQConnectionFactory() { @@ -559,7 +616,6 @@ public class ActiveMQConnectionFactory implements Serializable, Referenceable, C public synchronized int getInitialConnectAttempts() { - checkWrite(); return serverLocator.getInitialConnectAttempts(); } diff --git a/activemq-jms-client/src/main/java/org/apache/activemq/jms/client/ActiveMQJMSConnectionFactory.java b/activemq-jms-client/src/main/java/org/apache/activemq/jms/client/ActiveMQJMSConnectionFactory.java index d762cbc9ef..0bc852bf4b 100644 --- a/activemq-jms-client/src/main/java/org/apache/activemq/jms/client/ActiveMQJMSConnectionFactory.java +++ b/activemq-jms-client/src/main/java/org/apache/activemq/jms/client/ActiveMQJMSConnectionFactory.java @@ -67,5 +67,4 @@ public class ActiveMQJMSConnectionFactory extends ActiveMQConnectionFactory impl { super(ha, initialConnectors); } - } diff --git a/activemq-jms-client/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java b/activemq-jms-client/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java index a600b31c84..2f9735eebf 100644 --- a/activemq-jms-client/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java +++ b/activemq-jms-client/src/main/java/org/apache/activemq/jndi/ActiveMQInitialContextFactory.java @@ -21,34 +21,14 @@ import javax.jms.Topic; import javax.naming.Context; import javax.naming.NamingException; import javax.naming.spi.InitialContextFactory; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; -import java.util.List; import java.util.Map; -import java.util.Properties; -import java.util.StringTokenizer; -import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import org.apache.activemq.api.core.DiscoveryGroupConfiguration; -import org.apache.activemq.api.core.JGroupsBroadcastGroupConfiguration; -import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; -import org.apache.activemq.api.core.client.ActiveMQClient; import org.apache.activemq.api.jms.ActiveMQJMSClient; -import org.apache.activemq.api.jms.JMSFactoryType; -import org.apache.activemq.core.client.ActiveMQClientLogger; -import org.apache.activemq.core.remoting.impl.netty.NettyConnectorFactory; -import org.apache.activemq.core.remoting.impl.netty.TransportConstants; import org.apache.activemq.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.uri.ConnectionFactoryParser; /** * A factory of the ActiveMQ InitialContext which contains @@ -59,52 +39,40 @@ import org.apache.activemq.jms.client.ActiveMQConnectionFactory; */ public class ActiveMQInitialContextFactory implements InitialContextFactory { - public static final String CONNECTION_FACTORY_NAMES = "connectionFactoryNames"; public static final String REFRESH_TIMEOUT = "refreshTimeout"; public static final String DISCOVERY_INITIAL_WAIT_TIMEOUT = "discoveryInitialWaitTimeout"; - - private static final String[] DEFAULT_CONNECTION_FACTORY_NAMES = {"ConnectionFactory", "XAConnectionFactory", "QueueConnectionFactory", "TopicConnectionFactory"}; - public static final String TCP_SCHEME = "tcp"; - public static final String JGROUPS_SCHEME = "jgroups"; - public static final String UDP_SCHEME = "udp"; - public static final String VM_SCHEME = "vm"; - public static final String HA = "ha"; - public static final String CF_TYPE = "type"; - public static final String QUEUE_CF = "QUEUE_CF"; - public static final String TOPIC_CF = "TOPIC_CF"; - public static final String QUEUE_XA_CF = "QUEUE_XA_CF"; - public static final String TOPIC_XA_CF = "TOPIC_XA_CF"; - public static final String XA_CF = "XA_CF"; public static final String DYNAMIC_QUEUE_CONTEXT = "dynamicQueues"; public static final String DYNAMIC_TOPIC_CONTEXT = "dynamicTopics"; - - private String connectionPrefix = "connection."; + private String connectionFactoryPrefix = "connectionFactory."; private String queuePrefix = "queue."; private String topicPrefix = "topic."; public Context getInitialContext(Hashtable environment) throws NamingException { // lets create a factory - Map data = new ConcurrentHashMap(); - String[] names = getConnectionFactoryNames(environment); - for (int i = 0; i < names.length; i++) + Map data = new ConcurrentHashMap<>(); + for (Iterator iter = environment.entrySet().iterator(); iter.hasNext(); ) { - ActiveMQConnectionFactory factory = null; - String name = names[i]; - - try + Map.Entry entry = (Map.Entry) iter.next(); + String key = entry.getKey().toString(); + if (key.startsWith(connectionFactoryPrefix)) { - factory = createConnectionFactory(name, environment); + String jndiName = key.substring(connectionFactoryPrefix.length()); + try + { + ActiveMQConnectionFactory factory = createConnectionFactory((String) environment.get(key)); + data.put(jndiName, factory); + } + catch (Exception e) + { + e.printStackTrace(); + throw new NamingException("Invalid broker URL"); + } } - catch (Exception e) - { - e.printStackTrace(); - throw new NamingException("Invalid broker URL"); - } - - data.put(name, factory); } + + createQueues(data, environment); createTopics(data, environment); @@ -160,58 +128,6 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory return new ReadOnlyContext(environment, data); } - protected ActiveMQConnectionFactory createConnectionFactory(String name, Hashtable environment) throws URISyntaxException, MalformedURLException - { - Hashtable connectionFactoryProperties = new Hashtable(environment); - if (DEFAULT_CONNECTION_FACTORY_NAMES[1].equals(name)) - { - connectionFactoryProperties.put(CF_TYPE, XA_CF); - } - if (DEFAULT_CONNECTION_FACTORY_NAMES[2].equals(name)) - { - connectionFactoryProperties.put(CF_TYPE, QUEUE_CF); - } - if (DEFAULT_CONNECTION_FACTORY_NAMES[3].equals(name)) - { - connectionFactoryProperties.put(CF_TYPE, TOPIC_CF); - } - String prefix = connectionPrefix + name + "."; - for (Iterator iter = environment.entrySet().iterator(); iter.hasNext(); ) - { - Map.Entry entry = (Map.Entry) iter.next(); - String key = (String) entry.getKey(); - if (key.startsWith(prefix)) - { - // Rename the key... - connectionFactoryProperties.remove(key); - key = key.substring(prefix.length()); - connectionFactoryProperties.put(key, entry.getValue()); - } - } - return createConnectionFactory(connectionFactoryProperties); - } - - protected String[] getConnectionFactoryNames(Map environment) - { - String factoryNames = (String) environment.get(CONNECTION_FACTORY_NAMES); - if (factoryNames != null) - { - List list = new ArrayList(); - for (StringTokenizer enumeration = new StringTokenizer(factoryNames, ","); enumeration.hasMoreTokens(); ) - { - list.add(enumeration.nextToken().trim()); - } - int size = list.size(); - if (size > 0) - { - String[] answer = new String[size]; - list.toArray(answer); - return answer; - } - } - return DEFAULT_CONNECTION_FACTORY_NAMES; - } - protected void createQueues(Map data, Hashtable environment) { for (Iterator iter = environment.entrySet().iterator(); iter.hasNext(); ) @@ -259,238 +175,9 @@ public class ActiveMQInitialContextFactory implements InitialContextFactory /** * Factory method to create a new connection factory from the given environment */ - protected ActiveMQConnectionFactory createConnectionFactory(Hashtable environment) throws URISyntaxException, MalformedURLException + protected ActiveMQConnectionFactory createConnectionFactory(String uri) throws Exception { - ActiveMQConnectionFactory connectionFactory; - Map transportConfig = new HashMap(); - - if (environment.containsKey(Context.PROVIDER_URL)) - { - URI providerURI = new URI(((String)environment.get(Context.PROVIDER_URL))); - - if (providerURI.getQuery() != null) - { - try - { - transportConfig = parseQuery(providerURI.getQuery()); - } - catch (URISyntaxException e) - { - } - } - - if (providerURI.getScheme().equals(TCP_SCHEME)) - { - String[] connectors = providerURI.getAuthority().split(","); - TransportConfiguration[] transportConfigurations = new TransportConfiguration[connectors.length]; - for (int i = 0; i < connectors.length; i++) - { - Map individualTransportConfig = new HashMap(transportConfig); - String[] hostAndPort = connectors[i].split(":"); - individualTransportConfig.put(TransportConstants.HOST_PROP_NAME, hostAndPort[0]); - individualTransportConfig.put(TransportConstants.PORT_PROP_NAME, hostAndPort[1]); - transportConfigurations[i] = new TransportConfiguration(NettyConnectorFactory.class.getCanonicalName(), individualTransportConfig); - } - - if (Boolean.TRUE.equals(environment.get(HA))) - { - connectionFactory = ActiveMQJMSClient.createConnectionFactoryWithHA(getJmsFactoryType(environment), transportConfigurations); - } - else - { - connectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(getJmsFactoryType(environment), transportConfigurations); - } - } - else if (providerURI.getScheme().equals(UDP_SCHEME)) - { - DiscoveryGroupConfiguration dgc = new DiscoveryGroupConfiguration() - .setRefreshTimeout(transportConfig.containsKey(REFRESH_TIMEOUT) ? Long.parseLong((String) transportConfig.get(REFRESH_TIMEOUT)) : ActiveMQClient.DEFAULT_DISCOVERY_REFRESH_TIMEOUT) - .setDiscoveryInitialWaitTimeout(transportConfig.containsKey(DISCOVERY_INITIAL_WAIT_TIMEOUT) ? Long.parseLong((String) transportConfig.get(DISCOVERY_INITIAL_WAIT_TIMEOUT)) : ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT) - .setBroadcastEndpointFactoryConfiguration(new UDPBroadcastGroupConfiguration() - .setGroupAddress(providerURI.getHost()) - .setGroupPort(providerURI.getPort()) - .setLocalBindAddress(transportConfig.containsKey(TransportConstants.LOCAL_ADDRESS_PROP_NAME) ? (String) transportConfig.get(TransportConstants.LOCAL_ADDRESS_PROP_NAME) : null) - .setLocalBindPort(transportConfig.containsKey(TransportConstants.LOCAL_PORT_PROP_NAME) ? Integer.parseInt((String) transportConfig.get(TransportConstants.LOCAL_PORT_PROP_NAME)) : -1)); - if (Boolean.TRUE.equals(environment.get(HA))) - { - connectionFactory = ActiveMQJMSClient.createConnectionFactoryWithHA(dgc, getJmsFactoryType(environment)); - } - else - { - connectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(dgc, getJmsFactoryType(environment)); - } - } - else if (providerURI.getScheme().equals(JGROUPS_SCHEME)) - { - JGroupsBroadcastGroupConfiguration config = new JGroupsBroadcastGroupConfiguration(providerURI.getAuthority(), providerURI.getPath() != null ? providerURI.getPath() : UUID.randomUUID().toString()); - - DiscoveryGroupConfiguration dgc = new DiscoveryGroupConfiguration() - .setRefreshTimeout(transportConfig.containsKey(REFRESH_TIMEOUT) ? Long.parseLong((String) transportConfig.get(REFRESH_TIMEOUT)) : ActiveMQClient.DEFAULT_DISCOVERY_REFRESH_TIMEOUT) - .setDiscoveryInitialWaitTimeout(transportConfig.containsKey(DISCOVERY_INITIAL_WAIT_TIMEOUT) ? Long.parseLong((String) transportConfig.get(DISCOVERY_INITIAL_WAIT_TIMEOUT)) : ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT) - .setBroadcastEndpointFactoryConfiguration(config); - if (Boolean.TRUE.equals(environment.get(HA))) - { - connectionFactory = ActiveMQJMSClient.createConnectionFactoryWithHA(dgc, getJmsFactoryType(environment)); - } - else - { - connectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(dgc, getJmsFactoryType(environment)); - } - } - else if (providerURI.getScheme().equals(VM_SCHEME)) - { - Map inVmTransportConfig = new HashMap(); - inVmTransportConfig.put("serverId", providerURI.getHost()); - TransportConfiguration tc = new TransportConfiguration("org.apache.activemq.core.remoting.impl.invm.InVMConnectorFactory", inVmTransportConfig); - connectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(getJmsFactoryType(environment), tc); - } - else - { - throw new IllegalArgumentException("Invalid scheme"); - } - } - else - { - TransportConfiguration tc = new TransportConfiguration("org.apache.activemq.core.remoting.impl.invm.InVMConnectorFactory"); - connectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(getJmsFactoryType(environment), tc); - } - - Properties properties = new Properties(); - properties.putAll(environment); - - for (Object key : environment.keySet()) - { - invokeSetter(connectionFactory, (String) key, environment.get(key)); - } - - return connectionFactory; - } - - private JMSFactoryType getJmsFactoryType(Hashtable environment) - { - JMSFactoryType ultimateType = JMSFactoryType.CF; // default value - if (environment.containsKey(CF_TYPE)) - { - String tempType = (String) environment.get(CF_TYPE); - if (QUEUE_CF.equals(tempType)) - { - ultimateType = JMSFactoryType.QUEUE_CF; - } - else if (TOPIC_CF.equals(tempType)) - { - ultimateType = JMSFactoryType.TOPIC_CF; - } - else if (QUEUE_XA_CF.equals(tempType)) - { - ultimateType = JMSFactoryType.QUEUE_XA_CF; - } - else if (TOPIC_XA_CF.equals(tempType)) - { - ultimateType = JMSFactoryType.TOPIC_XA_CF; - } - else if (XA_CF.equals(tempType)) - { - ultimateType = JMSFactoryType.XA_CF; - } - } - return ultimateType; - } - - - public static Map parseQuery(String uri) throws URISyntaxException - { - try - { - uri = uri.substring(uri.lastIndexOf("?") + 1); // get only the relevant part of the query - Map rc = new HashMap(); - if (uri != null && !uri.isEmpty()) - { - String[] parameters = uri.split("&"); - for (int i = 0; i < parameters.length; i++) - { - int p = parameters[i].indexOf("="); - if (p >= 0) - { - String name = URLDecoder.decode(parameters[i].substring(0, p), "UTF-8"); - String value = URLDecoder.decode(parameters[i].substring(p + 1), "UTF-8"); - rc.put(name, value); - } - else - { - rc.put(parameters[i], null); - } - } - } - return rc; - } - catch (UnsupportedEncodingException e) - { - throw (URISyntaxException) new URISyntaxException(e.toString(), "Invalid encoding").initCause(e); - } - } - - public String getConnectionPrefix() - { - return connectionPrefix; - } - - public void setConnectionPrefix(String connectionPrefix) - { - this.connectionPrefix = connectionPrefix; - } - - private void invokeSetter(Object target, final String propertyName, final Object propertyValue) - { - Method setter = null; - - Method[] methods = target.getClass().getMethods(); - - // turn something like "consumerWindowSize" to "setConsumerWindowSize" - String setterMethodName = "set" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); - - for (Method m : methods) - { - if (m.getName().equals(setterMethodName)) - { - setter = m; - break; - } - } - - try - { - if (setter != null) - { - ActiveMQClientLogger.LOGGER.info("Invoking: " + setter + " that takes a " + setter.getParameterTypes()[0] + " with a " + propertyValue.getClass()); - if (propertyValue.getClass() == String.class && setter.getParameterTypes()[0] != String.class) - { - String stringPropertyValue = (String) propertyValue; - if (setter.getParameterTypes()[0] == Integer.TYPE) - { - setter.invoke(target, Integer.parseInt(stringPropertyValue)); - } - else if (setter.getParameterTypes()[0] == Long.TYPE) - { - setter.invoke(target, Long.parseLong(stringPropertyValue)); - } - else if (setter.getParameterTypes()[0] == Double.TYPE) - { - setter.invoke(target, Double.parseDouble(stringPropertyValue)); - } - else if (setter.getParameterTypes()[0] == Boolean.TYPE) - { - setter.invoke(target, Boolean.parseBoolean(stringPropertyValue)); - } - } - else - { - setter.invoke(target, propertyValue); - } - } - } - catch (Exception e) - { - ActiveMQClientLogger.LOGGER.warn("Caught exception during invocation of: " + setter, e); - } + ConnectionFactoryParser parser = new ConnectionFactoryParser(); + return parser.newObject(uri); } } diff --git a/activemq-jms-client/src/main/java/org/apache/activemq/uri/AbstractCFSchema.java b/activemq-jms-client/src/main/java/org/apache/activemq/uri/AbstractCFSchema.java index 3e4c01e5a9..7608afbe6e 100644 --- a/activemq-jms-client/src/main/java/org/apache/activemq/uri/AbstractCFSchema.java +++ b/activemq-jms-client/src/main/java/org/apache/activemq/uri/AbstractCFSchema.java @@ -31,15 +31,15 @@ import org.apache.activemq.utils.uri.URISchema; public abstract class AbstractCFSchema extends URISchema { - protected ConnectionOptions newConectionOptions(URI uri, Map query) throws Exception + protected JMSConnectionOptions newConectionOptions(URI uri, Map query) throws Exception { String type = query.get("type"); // We do this check here to guarantee proper logging - if (ConnectionOptions.convertCFType(type) == null) + if (JMSConnectionOptions.convertCFType(type) == null) { ActiveMQClientLogger.LOGGER.invalidCFType(type, uri.toString()); } - return setData(uri, new ConnectionOptions(), query); + return setData(uri, new JMSConnectionOptions(), query); } } diff --git a/activemq-jms-client/src/main/java/org/apache/activemq/uri/ConnectionFactoryParser.java b/activemq-jms-client/src/main/java/org/apache/activemq/uri/ConnectionFactoryParser.java index 88ef45ef7b..ec2e8db4fc 100644 --- a/activemq-jms-client/src/main/java/org/apache/activemq/uri/ConnectionFactoryParser.java +++ b/activemq-jms-client/src/main/java/org/apache/activemq/uri/ConnectionFactoryParser.java @@ -28,7 +28,9 @@ public class ConnectionFactoryParser extends URIFactoryAndy Taylor + */ +public class InVMSchema extends AbstractCFSchema +{ + @Override + public String getSchemaName() + { + return SchemaConstants.VM; + } + + @Override + protected ActiveMQConnectionFactory internalNewObject(URI uri, Map query) throws Exception + { + JMSConnectionOptions options = newConectionOptions(uri, query); + ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(options.getFactoryTypeEnum(), InVMServerLocatorSchema.createTransportConfiguration(uri)); + return URISchema.setData(uri, factory, query); + } + + @Override + protected URI internalNewURI(ActiveMQConnectionFactory bean) throws Exception + { + return InVMServerLocatorSchema.getUri(bean.getStaticConnectors()); + } +} diff --git a/activemq-jms-client/src/main/java/org/apache/activemq/uri/JGroupsSchema.java b/activemq-jms-client/src/main/java/org/apache/activemq/uri/JGroupsSchema.java index 302facd300..4d92153ff8 100644 --- a/activemq-jms-client/src/main/java/org/apache/activemq/uri/JGroupsSchema.java +++ b/activemq-jms-client/src/main/java/org/apache/activemq/uri/JGroupsSchema.java @@ -17,14 +17,17 @@ package org.apache.activemq.uri; +import java.io.NotSerializableException; import java.net.URI; import java.util.Map; -import java.util.UUID; +import org.apache.activemq.api.core.BroadcastEndpointFactory; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; -import org.apache.activemq.api.core.JGroupsBroadcastGroupConfiguration; +import org.apache.activemq.api.core.JGroupsFileBroadcastEndpointFactory; +import org.apache.activemq.api.core.JGroupsPropertiesBroadcastEndpointFactory; import org.apache.activemq.api.jms.ActiveMQJMSClient; import org.apache.activemq.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.utils.uri.SchemaConstants; import org.apache.activemq.utils.uri.URISchema; /** @@ -36,34 +39,48 @@ public class JGroupsSchema extends AbstractCFSchema @Override public String getSchemaName() { - return "jgroups"; + return SchemaConstants.JGROUPS; } - @Override public ActiveMQConnectionFactory internalNewObject(URI uri, Map query) throws Exception { - ConnectionOptions options = newConectionOptions(uri, query); - - System.out.println("authority = " + uri.getAuthority() + " path = " + uri.getPath()); - - JGroupsBroadcastGroupConfiguration jgroupsConfig = new JGroupsBroadcastGroupConfiguration(uri.getAuthority(), uri.getPath() != null ? uri.getPath() : UUID.randomUUID().toString()); - - URISchema.setData(uri, jgroupsConfig, query); - - - DiscoveryGroupConfiguration dcConfig = new DiscoveryGroupConfiguration().setBroadcastEndpointFactoryConfiguration(jgroupsConfig); - - URISchema.setData(uri, dcConfig, query); + JMSConnectionOptions options = newConectionOptions(uri, query); + DiscoveryGroupConfiguration dcConfig = JGroupsServerLocatorSchema.getDiscoveryGroupConfiguration(uri, query); + ActiveMQConnectionFactory factory; if (options.isHa()) { - return ActiveMQJMSClient.createConnectionFactoryWithHA(dcConfig, options.getFactoryTypeEnum()); + factory = ActiveMQJMSClient.createConnectionFactoryWithHA(dcConfig, options.getFactoryTypeEnum()); } else { - return ActiveMQJMSClient.createConnectionFactoryWithoutHA(dcConfig, options.getFactoryTypeEnum()); + factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(dcConfig, options.getFactoryTypeEnum()); } + return URISchema.setData(uri, factory, query); + } + + @Override + protected URI internalNewURI(ActiveMQConnectionFactory bean) throws Exception + { + DiscoveryGroupConfiguration dgc = bean.getDiscoveryGroupConfiguration(); + BroadcastEndpointFactory endpoint = dgc.getBroadcastEndpointFactory(); + String auth; + if (endpoint instanceof JGroupsFileBroadcastEndpointFactory) + { + auth = ((JGroupsFileBroadcastEndpointFactory) endpoint).getChannelName(); + } + else if (endpoint instanceof JGroupsPropertiesBroadcastEndpointFactory) + { + auth = ((JGroupsPropertiesBroadcastEndpointFactory) endpoint).getChannelName(); + } + else + { + throw new NotSerializableException(endpoint + "not serializable"); + } + String query = URISchema.getData(null, bean, dgc, endpoint); + dgc.setBroadcastEndpointFactory(endpoint); + return new URI(SchemaConstants.JGROUPS, null, auth, -1, null, query, null); } } diff --git a/activemq-jms-client/src/main/java/org/apache/activemq/uri/ConnectionOptions.java b/activemq-jms-client/src/main/java/org/apache/activemq/uri/JMSConnectionOptions.java similarity index 75% rename from activemq-jms-client/src/main/java/org/apache/activemq/uri/ConnectionOptions.java rename to activemq-jms-client/src/main/java/org/apache/activemq/uri/JMSConnectionOptions.java index c9a46b38c8..8855fd799a 100644 --- a/activemq-jms-client/src/main/java/org/apache/activemq/uri/ConnectionOptions.java +++ b/activemq-jms-client/src/main/java/org/apache/activemq/uri/JMSConnectionOptions.java @@ -26,50 +26,10 @@ import org.apache.activemq.api.jms.JMSFactoryType; * @author clebertsuconic */ -public class ConnectionOptions +public class JMSConnectionOptions extends ConnectionOptions { - - private boolean ha; - private JMSFactoryType factoryType = JMSFactoryType.CF; - private String host; - - private int port; - - public ConnectionOptions setHost(String host) - { - this.host = host; - return this; - } - - public String getHost() - { - return host; - } - - - public ConnectionOptions setPort(int port) - { - this.port = port; - return this; - } - - public int getPort() - { - return port; - } - - public boolean isHa() - { - return ha; - } - - public void setHa(boolean ha) - { - this.ha = ha; - } - public JMSFactoryType getFactoryTypeEnum() { return factoryType; @@ -96,7 +56,7 @@ public class ConnectionOptions { if (type == null) { - return null; + return JMSFactoryType.CF; } else { @@ -112,8 +72,7 @@ public class ConnectionOptions @Override public String toString() { - return "ConnectionOptions{" + - "ha=" + ha + + return "JMSConnectionOptions{" + ", factoryType=" + factoryType + '}'; } diff --git a/activemq-jms-client/src/main/java/org/apache/activemq/uri/TCPSchema.java b/activemq-jms-client/src/main/java/org/apache/activemq/uri/TCPSchema.java new file mode 100644 index 0000000000..a9b756564e --- /dev/null +++ b/activemq-jms-client/src/main/java/org/apache/activemq/uri/TCPSchema.java @@ -0,0 +1,67 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.uri; + +import org.apache.activemq.api.core.TransportConfiguration; +import org.apache.activemq.api.jms.ActiveMQJMSClient; +import org.apache.activemq.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.utils.uri.SchemaConstants; +import org.apache.activemq.utils.uri.URISchema; + +import java.net.URI; +import java.util.Map; + +/** + * @author Andy Taylor + */ +public class TCPSchema extends AbstractCFSchema +{ + @Override + public String getSchemaName() + { + return SchemaConstants.TCP; + } + + @Override + protected ActiveMQConnectionFactory internalNewObject(URI uri, Map query) throws Exception + { + JMSConnectionOptions options = newConectionOptions(uri, query); + + TransportConfiguration[] configurations = TCPServerLocatorSchema.getTransportConfigurations(uri, query); + + ActiveMQConnectionFactory factory; + + if (options.isHa()) + { + factory = ActiveMQJMSClient.createConnectionFactoryWithHA(options.getFactoryTypeEnum(), configurations); + } + else + { + factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(options.getFactoryTypeEnum(), configurations); + } + + return URISchema.setData(uri, factory, query); + } + + @Override + protected URI internalNewURI(ActiveMQConnectionFactory bean) throws Exception + { + String query = URISchema.getData(null, bean); + TransportConfiguration[] staticConnectors = bean.getStaticConnectors(); + return TCPServerLocatorSchema.getURI(query, staticConnectors); + } +} diff --git a/activemq-jms-client/src/main/java/org/apache/activemq/uri/UDPSchema.java b/activemq-jms-client/src/main/java/org/apache/activemq/uri/UDPSchema.java index b604233459..fdf613bb5f 100644 --- a/activemq-jms-client/src/main/java/org/apache/activemq/uri/UDPSchema.java +++ b/activemq-jms-client/src/main/java/org/apache/activemq/uri/UDPSchema.java @@ -17,15 +17,14 @@ package org.apache.activemq.uri; -import java.io.PrintStream; import java.net.URI; import java.util.Map; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.jms.ActiveMQJMSClient; -import org.apache.activemq.core.remoting.impl.netty.TransportConstants; import org.apache.activemq.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.utils.uri.SchemaConstants; import org.apache.activemq.utils.uri.URISchema; /** @@ -37,29 +36,35 @@ public class UDPSchema extends AbstractCFSchema @Override public String getSchemaName() { - return "udp"; + return SchemaConstants.UDP; } - @Override public ActiveMQConnectionFactory internalNewObject(URI uri, Map query) throws Exception { - ConnectionOptions options = newConectionOptions(uri, query); + JMSConnectionOptions options = newConectionOptions(uri, query); - DiscoveryGroupConfiguration dgc = URISchema.setData(uri, new DiscoveryGroupConfiguration(), query) - .setBroadcastEndpointFactoryConfiguration(new UDPBroadcastGroupConfiguration() - .setGroupAddress(getHost(uri)) - .setGroupPort(getPort(uri)) - .setLocalBindAddress(query.containsKey(TransportConstants.LOCAL_ADDRESS_PROP_NAME) ? (String) query.get(TransportConstants.LOCAL_ADDRESS_PROP_NAME) : null) - .setLocalBindPort(query.containsKey(TransportConstants.LOCAL_PORT_PROP_NAME) ? Integer.parseInt((String) query.get(TransportConstants.LOCAL_PORT_PROP_NAME)) : -1)); + DiscoveryGroupConfiguration dgc = UDPServerLocatorSchema.getDiscoveryGroupConfiguration(uri, query, getHost(uri), getPort(uri)); + ActiveMQConnectionFactory factory; if (options.isHa()) { - return ActiveMQJMSClient.createConnectionFactoryWithHA(dgc, options.getFactoryTypeEnum()); + factory = ActiveMQJMSClient.createConnectionFactoryWithHA(dgc, options.getFactoryTypeEnum()); } else { - return ActiveMQJMSClient.createConnectionFactoryWithoutHA(dgc, options.getFactoryTypeEnum()); + factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(dgc, options.getFactoryTypeEnum()); } + return URISchema.setData(uri, factory, query); + } + + @Override + protected URI internalNewURI(ActiveMQConnectionFactory bean) throws Exception + { + DiscoveryGroupConfiguration dgc = bean.getDiscoveryGroupConfiguration(); + UDPBroadcastEndpointFactory endpoint = (UDPBroadcastEndpointFactory) dgc.getBroadcastEndpointFactory(); + String query = URISchema.getData(UDPServerLocatorSchema.IGNORED, bean, dgc, endpoint); + dgc.setBroadcastEndpointFactory(endpoint); + return new URI(SchemaConstants.UDP, null, endpoint.getGroupAddress(), endpoint.getGroupPort(), null, query, null); } } diff --git a/activemq-jms-client/src/test/java/org/apache/activemq/uri/ConnectionFactoryURITest.java b/activemq-jms-client/src/test/java/org/apache/activemq/uri/ConnectionFactoryURITest.java index 19fb50a3e3..7e922fba64 100644 --- a/activemq-jms-client/src/test/java/org/apache/activemq/uri/ConnectionFactoryURITest.java +++ b/activemq-jms-client/src/test/java/org/apache/activemq/uri/ConnectionFactoryURITest.java @@ -17,11 +17,31 @@ package org.apache.activemq.uri; -import javax.jms.ConnectionFactory; -import javax.jms.XAQueueConnectionFactory; +import java.beans.PropertyDescriptor; +import java.lang.reflect.InvocationTargetException; import java.net.URI; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import org.apache.activemq.api.core.BroadcastEndpointFactory; +import org.apache.activemq.api.core.DiscoveryGroupConfiguration; +import org.apache.activemq.api.core.JGroupsFileBroadcastEndpointFactory; +import org.apache.activemq.api.core.JGroupsPropertiesBroadcastEndpointFactory; +import org.apache.activemq.api.core.TransportConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; +import org.apache.activemq.api.jms.ActiveMQJMSClient; +import org.apache.activemq.api.jms.JMSFactoryType; +import org.apache.activemq.core.remoting.impl.netty.NettyConnectorFactory; +import org.apache.activemq.core.remoting.impl.netty.TransportConstants; import org.apache.activemq.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.jms.client.ActiveMQJMSConnectionFactory; +import org.apache.activemq.jms.client.ActiveMQQueueConnectionFactory; +import org.apache.activemq.jms.client.ActiveMQTopicConnectionFactory; +import org.apache.activemq.jms.client.ActiveMQXAQueueConnectionFactory; +import org.apache.activemq.jms.client.ActiveMQXATopicConnectionFactory; +import org.apache.activemq.tests.util.RandomUtil; +import org.apache.commons.beanutils.BeanUtilsBean; import org.junit.Assert; import org.junit.Test; @@ -33,13 +53,212 @@ public class ConnectionFactoryURITest { ConnectionFactoryParser parser = new ConnectionFactoryParser(); + @Test + public void testQUEUE_XA_CF() throws Exception + { + ActiveMQConnectionFactory factory = parser.newObject(new URI("tcp://localhost:3030?ha=true&type=QUEUE_XA_CF")); + + Assert.assertTrue(ActiveMQXAQueueConnectionFactory.class.getName().equals(factory.getClass().getName())); + } + + @Test + public void testTOPICXA_CF() throws Exception + { + ActiveMQConnectionFactory factory = parser.newObject(new URI("tcp://localhost:3030?ha=true&type=TOPIC_XA_CF")); + + Assert.assertTrue(ActiveMQXATopicConnectionFactory.class.getName().equals(factory.getClass().getName())); + } + @Test + + public void testQUEUE_CF() throws Exception + { + ActiveMQConnectionFactory factory = parser.newObject(new URI("tcp://localhost:3030?ha=true&type=QUEUE_CF")); + + Assert.assertTrue(ActiveMQQueueConnectionFactory.class.getName().equals(factory.getClass().getName())); + } + + @Test + public void testTOPIC_CF() throws Exception + { + ActiveMQConnectionFactory factory = parser.newObject(new URI("tcp://localhost:3030?ha=true&type=TOPIC_CF")); + + Assert.assertTrue(ActiveMQTopicConnectionFactory.class.getName().equals(factory.getClass().getName())); + } + + @Test + public void testCF() throws Exception + { + ActiveMQConnectionFactory factory = parser.newObject(new URI("tcp://localhost:3030?ha=true&type=CF")); + + Assert.assertTrue(ActiveMQJMSConnectionFactory.class.getName().equals(factory.getClass().getName())); + } + + @Test + public void testNoCF() throws Exception + { + ActiveMQConnectionFactory factory = parser.newObject(new URI("tcp://localhost:3030?ha=true")); + + Assert.assertTrue(ActiveMQJMSConnectionFactory.class.getName().equals(factory.getClass().getName())); + } + + @Test + public void testTCPAllProperties() throws Exception + { + StringBuilder sb = new StringBuilder(); + sb.append("tcp://localhost:3030?ha=true"); + BeanUtilsBean bean = new BeanUtilsBean(); + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(true, (TransportConfiguration) null); + populate(sb, bean, factory); + ActiveMQConnectionFactory factory2 = parser.newObject(new URI(sb.toString())); + checkEquals(bean, factory, factory2); + } + + @Test + public void testTCPAllNettyConnectorProperties() throws Exception + { + Map props = new HashMap<>(); + Set allowableConnectorKeys = TransportConstants.ALLOWABLE_CONNECTOR_KEYS; + StringBuilder sb = new StringBuilder(); + sb.append("tcp://localhost:3030?ha=true"); + populateConnectorParams(props, allowableConnectorKeys, sb); + ActiveMQConnectionFactory factory = parser.newObject(new URI(sb.toString())); + + Map params = factory.getStaticConnectors()[0].getParams(); + Assert.assertEquals(params.get("host"), "localhost"); + Assert.assertEquals(params.get("port"), 3030); + for (Map.Entry entry : params.entrySet()) + { + if (!entry.getKey().equals("host") && !entry.getKey().equals("port")) + { + Assert.assertEquals(entry.getValue(), props.get(entry.getKey())); + } + } + } + + + @Test + public void testTCPAllNettyConnectorPropertiesMultiple() throws Exception + { + Map props = new HashMap<>(); + Set allowableConnectorKeys = TransportConstants.ALLOWABLE_CONNECTOR_KEYS; + StringBuilder sb = new StringBuilder(); + sb.append("(tcp://localhost0:5445?");//localhost1:5446,localhost2:5447,localhost3:5448)&ha=true"); + populateConnectorParams(props, allowableConnectorKeys, sb); + Map props2 = new HashMap<>(); + sb.append(",tcp://localhost1:5446?"); + populateConnectorParams(props2, allowableConnectorKeys, sb); + Map props3 = new HashMap<>(); + sb.append(",tcp://localhost2:5447?"); + populateConnectorParams(props3, allowableConnectorKeys, sb); + sb.append(")?ha=true&clientID=myID"); + + ActiveMQConnectionFactory factory = parser.newObject(sb.toString()); + + TransportConfiguration[] staticConnectors = factory.getStaticConnectors(); + Assert.assertEquals(3, staticConnectors.length); + checkTC(props, staticConnectors[0],0); + checkTC(props2, staticConnectors[1],1); + checkTC(props3, staticConnectors[2],2); + } + + private void checkTC(Map props, TransportConfiguration staticConnector, int offfSet) + { + TransportConfiguration connector = staticConnector; + Assert.assertEquals(connector.getParams().get("host"), "localhost" + offfSet); + Assert.assertEquals(connector.getParams().get("port"), (5445 + offfSet)); + Map params = connector.getParams(); + for (Map.Entry entry : params.entrySet()) + { + if (!entry.getKey().equals("host") && !entry.getKey().equals("port")) + { + Assert.assertEquals(entry.getValue(), props.get(entry.getKey())); + } + } + } + + private void populateConnectorParams(Map props, Set allowableConnectorKeys, StringBuilder sb) + { + for (String allowableConnectorKey : allowableConnectorKeys) + { + if (!allowableConnectorKey.equals("host") && !allowableConnectorKey.equals("port")) + { + String value = RandomUtil.randomString(); + props.put(allowableConnectorKey, value); + sb.append("&").append(allowableConnectorKey).append("=").append(value); + } + } + } + + @Test + public void testTCPURI() throws Exception + { + TransportConfiguration tc = new TransportConfiguration(NettyConnectorFactory.class.getName()); + HashMap params = new HashMap<>(); + params.put("host", "localhost1"); + params.put("port", 5446); + TransportConfiguration tc2 = new TransportConfiguration(NettyConnectorFactory.class.getName(), params); + HashMap params2 = new HashMap<>(); + params2.put("host", "localhost2"); + params2.put("port", 5447); + TransportConfiguration tc3 = new TransportConfiguration(NettyConnectorFactory.class.getName(), params2); + ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, tc, tc2, tc3); + URI tcp = parser.createSchema("tcp", connectionFactoryWithHA); + ActiveMQConnectionFactory factory = parser.newObject(tcp); + BeanUtilsBean bean = new BeanUtilsBean(); + checkEquals(bean, connectionFactoryWithHA, factory); + } @Test public void testUDP() throws Exception { ActiveMQConnectionFactory factory = parser.newObject(new URI("udp://localhost:3030?ha=true&type=QUEUE_XA_CF")); - Assert.assertTrue(factory instanceof XAQueueConnectionFactory); + Assert.assertTrue(ActiveMQXAQueueConnectionFactory.class.getName().equals(factory.getClass().getName())); + } + + @Test + public void testUDPAllProperties() throws Exception + { + StringBuilder sb = new StringBuilder(); + sb.append("udp://localhost:3030?ha=true"); + BeanUtilsBean bean = new BeanUtilsBean(); + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(true, (TransportConfiguration) null); + populate(sb, bean, factory); + ActiveMQConnectionFactory factory2 = parser.newObject(new URI(sb.toString())); + checkEquals(bean, factory, factory2); + } + + @Test + public void testUDPURI() throws Exception + { + DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration(); + UDPBroadcastEndpointFactory endpoint = new UDPBroadcastEndpointFactory(); + endpoint.setGroupPort(3333).setGroupAddress("wahey").setLocalBindPort(555).setLocalBindAddress("uhuh"); + discoveryGroupConfiguration.setName("foo") + .setRefreshTimeout(12345) + .setDiscoveryInitialWaitTimeout(5678) + .setBroadcastEndpointFactory(endpoint); + ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF); + URI tcp = parser.createSchema("udp", connectionFactoryWithHA); + ActiveMQConnectionFactory factory = parser.newObject(tcp); + DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration(); + Assert.assertNotNull(dgc); + BroadcastEndpointFactory befc = dgc.getBroadcastEndpointFactory(); + Assert.assertNotNull(befc); + Assert.assertTrue(befc instanceof UDPBroadcastEndpointFactory); + UDPBroadcastEndpointFactory ubgc = (UDPBroadcastEndpointFactory) befc; + Assert.assertEquals(ubgc.getGroupAddress(), "wahey"); + Assert.assertEquals(ubgc.getGroupPort(), 3333); + //these 2 are transient + Assert.assertEquals(ubgc.getLocalBindAddress(), null); + Assert.assertEquals(ubgc.getLocalBindPort(), -1); + Assert.assertEquals(dgc.getName(), "foo"); + Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5678); + Assert.assertEquals(dgc.getRefreshTimeout(), 12345); + + + BeanUtilsBean bean = new BeanUtilsBean(); + checkEquals(bean, connectionFactoryWithHA, factory); } @Test @@ -47,14 +266,149 @@ public class ConnectionFactoryURITest { ActiveMQConnectionFactory factory = parser.newObject(new URI("udp://localhost:3030?ha=true&type=QUEUE_XA_CFInvalid")); - Assert.assertTrue(factory instanceof ConnectionFactory); + Assert.assertTrue(ActiveMQJMSConnectionFactory.class.getName().equals(factory.getClass().getName())); } @Test - public void testJGroups() throws Exception + public void testJGroupsFile() throws Exception { - ActiveMQConnectionFactory factory = parser.newObject(new URI("jgroups://test.xml?test=33")); + ActiveMQConnectionFactory factory = parser.newObject(new URI("jgroups://channel-name?file=/path/to/some/file/channel-file.xml&test=33")); -// Assert.assertTrue(factory instanceof ConnectionFactory); + Assert.assertTrue(ActiveMQJMSConnectionFactory.class.getName().equals(factory.getClass().getName())); + JGroupsFileBroadcastEndpointFactory broadcastEndpointFactory = (JGroupsFileBroadcastEndpointFactory) factory.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory(); + Assert.assertEquals(broadcastEndpointFactory.getFile(), "/path/to/some/file/channel-file.xml"); + Assert.assertEquals(broadcastEndpointFactory.getChannelName(), "channel-name"); + } + + @Test + public void testJGroupsKeyValue() throws Exception + { + ActiveMQConnectionFactory factory = parser.newObject(new URI("jgroups://channel-name?properties=param=value;param2=value2&test=33")); + + Assert.assertTrue(ActiveMQJMSConnectionFactory.class.getName().equals(factory.getClass().getName())); + JGroupsPropertiesBroadcastEndpointFactory broadcastEndpointFactory = (JGroupsPropertiesBroadcastEndpointFactory) factory.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory(); + Assert.assertEquals(broadcastEndpointFactory.getProperties(), "param=value;param2=value2"); + Assert.assertEquals(broadcastEndpointFactory.getChannelName(), "channel-name"); + } + + @Test + public void testJGroupsAllProperties() throws Exception + { + StringBuilder sb = new StringBuilder(); + sb.append("jgroups://?file=param=value;param=value&channelName=channelName&ha=true"); + BeanUtilsBean bean = new BeanUtilsBean(); + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(true, (TransportConfiguration) null); + populate(sb, bean, factory); + ActiveMQConnectionFactory factory2 = parser.newObject(new URI(sb.toString())); + checkEquals(bean, factory, factory2); + } + + + @Test + public void testJGroupsFileURI() throws Exception + { + DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration(); + JGroupsFileBroadcastEndpointFactory endpointFactory = new JGroupsFileBroadcastEndpointFactory() + .setChannelName("channel-name") + .setFile("channel-file.xml"); + discoveryGroupConfiguration.setName("foo") + .setRefreshTimeout(12345) + .setDiscoveryInitialWaitTimeout(5678) + .setBroadcastEndpointFactory(endpointFactory); + ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF); + URI tcp = parser.createSchema("jgroups", connectionFactoryWithHA); + ActiveMQConnectionFactory factory = parser.newObject(tcp); + DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration(); + Assert.assertNotNull(dgc); + BroadcastEndpointFactory befc = dgc.getBroadcastEndpointFactory(); + Assert.assertNotNull(befc); + Assert.assertTrue(befc instanceof JGroupsFileBroadcastEndpointFactory); + Assert.assertEquals(dgc.getName(), "foo"); + Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5678); + Assert.assertEquals(dgc.getRefreshTimeout(), 12345); + JGroupsFileBroadcastEndpointFactory fileBroadcastEndpointFactory = (JGroupsFileBroadcastEndpointFactory) befc; + Assert.assertEquals(fileBroadcastEndpointFactory.getFile(), "channel-file.xml"); + Assert.assertEquals(fileBroadcastEndpointFactory.getChannelName(), "channel-name"); + + + BeanUtilsBean bean = new BeanUtilsBean(); + checkEquals(bean, connectionFactoryWithHA, factory); + } + + @Test + public void testJGroupsPropertiesURI() throws Exception + { + DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration(); + JGroupsPropertiesBroadcastEndpointFactory endpointFactory = new JGroupsPropertiesBroadcastEndpointFactory() + .setChannelName("channel-name") + .setProperties("param=val,param2-val2"); + discoveryGroupConfiguration.setName("foo") + .setRefreshTimeout(12345) + .setDiscoveryInitialWaitTimeout(5678) + .setBroadcastEndpointFactory(endpointFactory); + ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF); + URI tcp = parser.createSchema("jgroups", connectionFactoryWithHA); + ActiveMQConnectionFactory factory = parser.newObject(tcp); + DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration(); + Assert.assertNotNull(dgc); + BroadcastEndpointFactory broadcastEndpointFactory = dgc.getBroadcastEndpointFactory(); + Assert.assertNotNull(broadcastEndpointFactory); + Assert.assertTrue(broadcastEndpointFactory instanceof JGroupsPropertiesBroadcastEndpointFactory); + Assert.assertEquals(dgc.getName(), "foo"); + Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5678); + Assert.assertEquals(dgc.getRefreshTimeout(), 12345); + JGroupsPropertiesBroadcastEndpointFactory propertiesBroadcastEndpointFactory = (JGroupsPropertiesBroadcastEndpointFactory) broadcastEndpointFactory; + Assert.assertEquals(propertiesBroadcastEndpointFactory.getProperties(), "param=val,param2-val2"); + Assert.assertEquals(propertiesBroadcastEndpointFactory.getChannelName(), "channel-name"); + + BeanUtilsBean bean = new BeanUtilsBean(); + checkEquals(bean, connectionFactoryWithHA, factory); + } + + private void populate(StringBuilder sb, BeanUtilsBean bean, ActiveMQConnectionFactory factory) throws IllegalAccessException, InvocationTargetException + { + PropertyDescriptor[] descriptors = bean.getPropertyUtils().getPropertyDescriptors(factory); + for (PropertyDescriptor descriptor : descriptors) + { + if (descriptor.getWriteMethod() != null && descriptor.getReadMethod() != null) + { + if (descriptor.getPropertyType() == String.class) + { + String value = RandomUtil.randomString(); + bean.setProperty(factory, descriptor.getName(), value); + sb.append("&").append(descriptor.getName()).append("=").append(value); + } + else if (descriptor.getPropertyType() == int.class) + { + int value = RandomUtil.randomPositiveInt(); + bean.setProperty(factory, descriptor.getName(), value); + sb.append("&").append(descriptor.getName()).append("=").append(value); + } + else if (descriptor.getPropertyType() == long.class) + { + long value = RandomUtil.randomPositiveLong(); + bean.setProperty(factory, descriptor.getName(), value); + sb.append("&").append(descriptor.getName()).append("=").append(value); + } + else if (descriptor.getPropertyType() == double.class) + { + double value = RandomUtil.randomDouble(); + bean.setProperty(factory, descriptor.getName(), value); + sb.append("&").append(descriptor.getName()).append("=").append(value); + } + } + } + } + + private void checkEquals(BeanUtilsBean bean, ActiveMQConnectionFactory factory, ActiveMQConnectionFactory factory2) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException + { + PropertyDescriptor[] descriptors = bean.getPropertyUtils().getPropertyDescriptors(factory); + for (PropertyDescriptor descriptor : descriptors) + { + if (descriptor.getWriteMethod() != null && descriptor.getReadMethod() != null) + { + Assert.assertEquals(descriptor.getName() + " incorrect", bean.getProperty(factory, descriptor.getName()),bean.getProperty(factory2, descriptor.getName())); + } + } } } diff --git a/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java index 1675f3f11a..a67721843a 100644 --- a/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java +++ b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java @@ -39,11 +39,12 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.activemq.api.core.ActiveMQException; -import org.apache.activemq.api.core.BroadcastEndpointFactoryConfiguration; +import org.apache.activemq.api.core.BroadcastEndpointFactory; +import org.apache.activemq.api.core.ChannelBroadcastEndpointFactory; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; -import org.apache.activemq.api.core.JGroupsBroadcastGroupConfiguration; +import org.apache.activemq.api.core.JGroupsFileBroadcastEndpointFactory; import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.core.client.ClientSession; import org.apache.activemq.api.core.client.ClientSessionFactory; import org.apache.activemq.api.core.client.ActiveMQClient; @@ -1873,13 +1874,13 @@ public class ActiveMQResourceAdapter implements ResourceAdapter, Serializable if (discoveryAddress != null || jgroupsFileName != null || jgroupsLocatorClassName != null) { - BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration = null; + BroadcastEndpointFactory endpointFactory = null; if (jgroupsLocatorClassName != null) { String jchannelRefName = raProperties.getJgroupsChannelRefName(); JChannel jchannel = ActiveMQRaUtils.locateJGroupsChannel(jgroupsLocatorClassName, jchannelRefName); - endpointFactoryConfiguration = new JGroupsBroadcastGroupConfiguration(jchannel, jgroupsChannel); + endpointFactory = new ChannelBroadcastEndpointFactory(jchannel, jgroupsChannel); } else if (discoveryAddress != null) { @@ -1892,7 +1893,7 @@ public class ActiveMQResourceAdapter implements ResourceAdapter, Serializable String localBindAddress = overrideProperties.getDiscoveryLocalBindAddress() != null ? overrideProperties.getDiscoveryLocalBindAddress() : raProperties.getDiscoveryLocalBindAddress(); - endpointFactoryConfiguration = new UDPBroadcastGroupConfiguration() + endpointFactory = new UDPBroadcastEndpointFactory() .setGroupAddress(discoveryAddress) .setGroupPort(discoveryPort) .setLocalBindAddress(localBindAddress) @@ -1900,7 +1901,9 @@ public class ActiveMQResourceAdapter implements ResourceAdapter, Serializable } else if (jgroupsFileName != null) { - endpointFactoryConfiguration = new JGroupsBroadcastGroupConfiguration(jgroupsFileName, jgroupsChannel); + endpointFactory = new JGroupsFileBroadcastEndpointFactory() + .setChannelName(jgroupsChannel) + .setFile(jgroupsFileName); } Long refreshTimeout = overrideProperties.getDiscoveryRefreshTimeout() != null ? overrideProperties.getDiscoveryRefreshTimeout() : raProperties.getDiscoveryRefreshTimeout(); @@ -1920,7 +1923,7 @@ public class ActiveMQResourceAdapter implements ResourceAdapter, Serializable DiscoveryGroupConfiguration groupConfiguration = new DiscoveryGroupConfiguration() .setRefreshTimeout(refreshTimeout) .setDiscoveryInitialWaitTimeout(initialTimeout) - .setBroadcastEndpointFactoryConfiguration(endpointFactoryConfiguration); + .setBroadcastEndpointFactory(endpointFactory); if (ActiveMQRALogger.LOGGER.isDebugEnabled()) { @@ -2008,7 +2011,7 @@ public class ActiveMQResourceAdapter implements ResourceAdapter, Serializable if (connectorClassName == null) { - BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration = null; + BroadcastEndpointFactory endpointFactory = null; if (discoveryAddress != null) { Integer discoveryPort = overrideProperties.getDiscoveryPort() != null ? overrideProperties.getDiscoveryPort() @@ -2020,7 +2023,7 @@ public class ActiveMQResourceAdapter implements ResourceAdapter, Serializable String localBindAddress = overrideProperties.getDiscoveryLocalBindAddress() != null ? overrideProperties.getDiscoveryLocalBindAddress() : raProperties.getDiscoveryLocalBindAddress(); - endpointFactoryConfiguration = new UDPBroadcastGroupConfiguration() + endpointFactory = new UDPBroadcastEndpointFactory() .setGroupAddress(discoveryAddress) .setGroupPort(discoveryPort) .setLocalBindAddress(localBindAddress) @@ -2028,7 +2031,9 @@ public class ActiveMQResourceAdapter implements ResourceAdapter, Serializable } else if (jgroupsFileName != null) { - endpointFactoryConfiguration = new JGroupsBroadcastGroupConfiguration(jgroupsFileName, jgroupsChannel); + endpointFactory = new JGroupsFileBroadcastEndpointFactory() + .setChannelName(jgroupsChannel) + .setFile(jgroupsFileName); } else { @@ -2037,9 +2042,9 @@ public class ActiveMQResourceAdapter implements ResourceAdapter, Serializable { String jgroupsChannelRefName = raProperties.getJgroupsChannelRefName(); JChannel jchannel = ActiveMQRaUtils.locateJGroupsChannel(jgroupsLocatorClass, jgroupsChannelRefName); - endpointFactoryConfiguration = new JGroupsBroadcastGroupConfiguration(jchannel, jgroupsChannel); + endpointFactory = new ChannelBroadcastEndpointFactory(jchannel, jgroupsChannel); } - if (endpointFactoryConfiguration == null) + if (endpointFactory == null) { throw new IllegalArgumentException("must provide either TransportType or DiscoveryGroupAddress and DiscoveryGroupPort for ActiveMQ ResourceAdapter Connection Factory"); } @@ -2061,7 +2066,7 @@ public class ActiveMQResourceAdapter implements ResourceAdapter, Serializable DiscoveryGroupConfiguration groupConfiguration = new DiscoveryGroupConfiguration() .setRefreshTimeout(refreshTimeout) .setDiscoveryInitialWaitTimeout(initialTimeout) - .setBroadcastEndpointFactoryConfiguration(endpointFactoryConfiguration); + .setBroadcastEndpointFactory(endpointFactory); groupConfiguration.setRefreshTimeout(refreshTimeout); diff --git a/activemq-server/src/main/java/org/apache/activemq/core/config/Configuration.java b/activemq-server/src/main/java/org/apache/activemq/core/config/Configuration.java index c814979cdb..1090257579 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/config/Configuration.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/config/Configuration.java @@ -16,7 +16,6 @@ */ package org.apache.activemq.core.config; -import java.io.Serializable; import java.util.List; import java.util.Map; import java.util.Set; @@ -35,7 +34,7 @@ import org.apache.activemq.core.settings.impl.AddressSettings; * * @author Tim Fox */ -public interface Configuration extends Serializable +public interface Configuration { /** * To be used on dependency management on the application server diff --git a/activemq-server/src/main/java/org/apache/activemq/core/config/impl/ConfigurationImpl.java b/activemq-server/src/main/java/org/apache/activemq/core/config/impl/ConfigurationImpl.java index 3c39a8b0cb..9afd93d094 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/config/impl/ConfigurationImpl.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/config/impl/ConfigurationImpl.java @@ -20,6 +20,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -51,7 +52,7 @@ import org.apache.activemq.core.settings.impl.AddressSettings; * @author Tim Fox */ -public class ConfigurationImpl implements Configuration +public class ConfigurationImpl implements Configuration, Serializable { // Constants ------------------------------------------------------------------------------ diff --git a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/FileConfigurationParser.java b/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/FileConfigurationParser.java index 8ebea6ec0f..a4010fe281 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/FileConfigurationParser.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/deployers/impl/FileConfigurationParser.java @@ -27,14 +27,14 @@ import java.util.Map; import java.util.Set; import org.apache.activemq.api.config.ActiveMQDefaultConfiguration; -import org.apache.activemq.api.core.BroadcastEndpointFactoryConfiguration; +import org.apache.activemq.api.core.BroadcastEndpointFactory; import org.apache.activemq.api.core.BroadcastGroupConfiguration; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; -import org.apache.activemq.api.core.JGroupsBroadcastGroupConfiguration; +import org.apache.activemq.api.core.JGroupsFileBroadcastEndpointFactory; import org.apache.activemq.api.core.Pair; import org.apache.activemq.api.core.SimpleString; import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.core.client.ActiveMQClient; import org.apache.activemq.core.config.BridgeConfiguration; import org.apache.activemq.core.config.ClusterConnectionConfiguration; @@ -1268,15 +1268,17 @@ public final class FileConfigurationParser extends XMLConfigurationUtil // TODO: validate if either jgroups or UDP is being filled - BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration; + BroadcastEndpointFactory endpointFactory; if (jgroupsFile != null) { - endpointFactoryConfiguration = new JGroupsBroadcastGroupConfiguration(jgroupsFile, jgroupsChannel); + endpointFactory = new JGroupsFileBroadcastEndpointFactory() + .setFile(jgroupsFile) + .setChannelName(jgroupsChannel); } else { - endpointFactoryConfiguration = new UDPBroadcastGroupConfiguration() + endpointFactory = new UDPBroadcastEndpointFactory() .setGroupAddress(groupAddress) .setGroupPort(groupPort) .setLocalBindAddress(localAddress) @@ -1287,7 +1289,7 @@ public final class FileConfigurationParser extends XMLConfigurationUtil .setName(name) .setBroadcastPeriod(broadcastPeriod) .setConnectorInfos(connectorNames) - .setEndpointFactoryConfiguration(endpointFactoryConfiguration); + .setEndpointFactory(endpointFactory); mainConfig.getBroadcastGroupConfigurations().add(config); } @@ -1317,14 +1319,16 @@ public final class FileConfigurationParser extends XMLConfigurationUtil String jgroupsChannel = getString(e, "jgroups-channel", null, Validators.NO_CHECK); // TODO: validate if either jgroups or UDP is being filled - BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration; + BroadcastEndpointFactory endpointFactory; if (jgroupsFile != null) { - endpointFactoryConfiguration = new JGroupsBroadcastGroupConfiguration(jgroupsFile, jgroupsChannel); + endpointFactory = new JGroupsFileBroadcastEndpointFactory() + .setFile(jgroupsFile) + .setChannelName(jgroupsChannel); } else { - endpointFactoryConfiguration = new UDPBroadcastGroupConfiguration() + endpointFactory = new UDPBroadcastEndpointFactory() .setGroupAddress(groupAddress) .setGroupPort(groupPort) .setLocalBindAddress(localBindAddress) @@ -1335,7 +1339,7 @@ public final class FileConfigurationParser extends XMLConfigurationUtil .setName(name) .setRefreshTimeout(refreshTimeout) .setDiscoveryInitialWaitTimeout(discoveryInitialWaitTimeout) - .setBroadcastEndpointFactoryConfiguration(endpointFactoryConfiguration); + .setBroadcastEndpointFactory(endpointFactory); if (mainConfig.getDiscoveryGroupConfigurations().containsKey(name)) { diff --git a/activemq-server/src/main/java/org/apache/activemq/core/management/impl/BroadcastGroupControlImpl.java b/activemq-server/src/main/java/org/apache/activemq/core/management/impl/BroadcastGroupControlImpl.java index 506dd8f1eb..f20fb2174c 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/management/impl/BroadcastGroupControlImpl.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/management/impl/BroadcastGroupControlImpl.java @@ -19,7 +19,7 @@ package org.apache.activemq.core.management.impl; import javax.management.MBeanOperationInfo; import org.apache.activemq.api.core.BroadcastGroupConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.core.management.BroadcastGroupControl; import org.apache.activemq.core.persistence.StorageManager; import org.apache.activemq.core.server.cluster.BroadcastGroup; @@ -130,9 +130,9 @@ public class BroadcastGroupControlImpl extends AbstractControl implements Broadc clearIO(); try { - if (configuration.getEndpointFactoryConfiguration() instanceof UDPBroadcastGroupConfiguration) + if (configuration.getEndpointFactory() instanceof UDPBroadcastEndpointFactory) { - return ((UDPBroadcastGroupConfiguration)configuration.getEndpointFactoryConfiguration()).getGroupAddress(); + return ((UDPBroadcastEndpointFactory)configuration.getEndpointFactory()).getGroupAddress(); } throw new Exception("Invalid request because this is not a UDP Broadcast configuration."); } @@ -147,9 +147,9 @@ public class BroadcastGroupControlImpl extends AbstractControl implements Broadc clearIO(); try { - if (configuration.getEndpointFactoryConfiguration() instanceof UDPBroadcastGroupConfiguration) + if (configuration.getEndpointFactory() instanceof UDPBroadcastEndpointFactory) { - return ((UDPBroadcastGroupConfiguration)configuration.getEndpointFactoryConfiguration()).getGroupPort(); + return ((UDPBroadcastEndpointFactory)configuration.getEndpointFactory()).getGroupPort(); } throw new Exception("Invalid request because this is not a UDP Broadcast configuration."); } @@ -164,9 +164,9 @@ public class BroadcastGroupControlImpl extends AbstractControl implements Broadc clearIO(); try { - if (configuration.getEndpointFactoryConfiguration() instanceof UDPBroadcastGroupConfiguration) + if (configuration.getEndpointFactory() instanceof UDPBroadcastEndpointFactory) { - return ((UDPBroadcastGroupConfiguration)configuration.getEndpointFactoryConfiguration()).getLocalBindPort(); + return ((UDPBroadcastEndpointFactory)configuration.getEndpointFactory()).getLocalBindPort(); } throw new Exception("Invalid request because this is not a UDP Broadcast configuration."); } diff --git a/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/invm/InVMAcceptorFactory.java b/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/invm/InVMAcceptorFactory.java index df30e00f8a..1495571bb2 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/invm/InVMAcceptorFactory.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/invm/InVMAcceptorFactory.java @@ -17,7 +17,6 @@ package org.apache.activemq.core.remoting.impl.invm; import java.util.Map; -import java.util.Set; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; diff --git a/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/invm/InVMConnectorFactory.java b/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/invm/InVMConnectorFactory.java index 5de4161ad6..e800bd1633 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/invm/InVMConnectorFactory.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/invm/InVMConnectorFactory.java @@ -17,7 +17,6 @@ package org.apache.activemq.core.remoting.impl.invm; import java.util.Map; -import java.util.Set; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; diff --git a/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/invm/TransportConstants.java b/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/invm/TransportConstants.java index 9987383215..45b75d4d98 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/invm/TransportConstants.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/invm/TransportConstants.java @@ -16,11 +16,6 @@ */ package org.apache.activemq.core.remoting.impl.invm; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.apache.activemq.api.config.ActiveMQDefaultConfiguration; /** * A TransportConstants diff --git a/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/netty/NettyAcceptorFactory.java b/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/netty/NettyAcceptorFactory.java index 1bb545b90a..674200cf0e 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/netty/NettyAcceptorFactory.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/remoting/impl/netty/NettyAcceptorFactory.java @@ -17,7 +17,6 @@ package org.apache.activemq.core.remoting.impl.netty; import java.util.Map; -import java.util.Set; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; diff --git a/activemq-server/src/main/java/org/apache/activemq/core/remoting/server/impl/RemotingServiceImpl.java b/activemq-server/src/main/java/org/apache/activemq/core/remoting/server/impl/RemotingServiceImpl.java index 9cb009abdc..6baf3de67e 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/remoting/server/impl/RemotingServiceImpl.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/remoting/server/impl/RemotingServiceImpl.java @@ -242,21 +242,6 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle AcceptorFactory factory = (AcceptorFactory) clazz.newInstance(); - // Check valid properties - - if (info.getParams() != null) - { - Set invalid = ConfigurationHelper.checkKeys(factory.getAllowableProperties(), info.getParams() - .keySet()); - - if (!invalid.isEmpty()) - { - ActiveMQServerLogger.LOGGER.invalidAcceptorKeys(ConfigurationHelper.stringSetToCommaListString(invalid)); - - continue; - } - } - Map supportedProtocols = new ConcurrentHashMap(); String protocol = ConfigurationHelper.getStringProperty(TransportConstants.PROTOCOL_PROP_NAME, null, diff --git a/activemq-server/src/main/java/org/apache/activemq/core/server/cluster/ClusterManager.java b/activemq-server/src/main/java/org/apache/activemq/core/server/cluster/ClusterManager.java index 7d09fdd9e3..5c5362ea4c 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/server/cluster/ClusterManager.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/server/cluster/ClusterManager.java @@ -856,7 +856,7 @@ public final class ClusterManager implements ActiveMQComponent if (group == null) { group = new BroadcastGroupImpl(nodeManager, config.getName(), - config.getBroadcastPeriod(), scheduledExecutor, config.getEndpointFactoryConfiguration().createBroadcastEndpointFactory()); + config.getBroadcastPeriod(), scheduledExecutor, config.getEndpointFactory()); for (String connectorInfo : config.getConnectorInfos()) { diff --git a/activemq-server/src/main/java/org/apache/activemq/spi/core/remoting/AcceptorFactory.java b/activemq-server/src/main/java/org/apache/activemq/spi/core/remoting/AcceptorFactory.java index 02dbb35308..2d9232367c 100644 --- a/activemq-server/src/main/java/org/apache/activemq/spi/core/remoting/AcceptorFactory.java +++ b/activemq-server/src/main/java/org/apache/activemq/spi/core/remoting/AcceptorFactory.java @@ -17,7 +17,6 @@ package org.apache.activemq.spi.core.remoting; import java.util.Map; -import java.util.Set; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; diff --git a/activemq-server/src/test/java/org/apache/activemq/core/config/impl/FileConfigurationTest.java b/activemq-server/src/test/java/org/apache/activemq/core/config/impl/FileConfigurationTest.java index 182cd7f857..c7fc2c4900 100644 --- a/activemq-server/src/test/java/org/apache/activemq/core/config/impl/FileConfigurationTest.java +++ b/activemq-server/src/test/java/org/apache/activemq/core/config/impl/FileConfigurationTest.java @@ -22,7 +22,7 @@ import org.apache.activemq.api.core.BroadcastGroupConfiguration; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.api.core.SimpleString; import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.core.config.BridgeConfiguration; import org.apache.activemq.core.config.ClusterConnectionConfiguration; import org.apache.activemq.core.config.Configuration; @@ -141,7 +141,7 @@ public class FileConfigurationTest extends ConfigurationImplTest Assert.assertEquals(2, conf.getBroadcastGroupConfigurations().size()); for (BroadcastGroupConfiguration bc : conf.getBroadcastGroupConfigurations()) { - UDPBroadcastGroupConfiguration udpBc = (UDPBroadcastGroupConfiguration) bc.getEndpointFactoryConfiguration(); + UDPBroadcastEndpointFactory udpBc = (UDPBroadcastEndpointFactory) bc.getEndpointFactory(); if (bc.getName().equals("bg1")) { Assert.assertEquals("bg1", bc.getName()); @@ -165,16 +165,16 @@ public class FileConfigurationTest extends ConfigurationImplTest Assert.assertEquals(2, conf.getDiscoveryGroupConfigurations().size()); DiscoveryGroupConfiguration dc = conf.getDiscoveryGroupConfigurations().get("dg1"); Assert.assertEquals("dg1", dc.getName()); - Assert.assertEquals("192.168.0.120", ((UDPBroadcastGroupConfiguration) dc.getBroadcastEndpointFactoryConfiguration()).getGroupAddress()); - assertEquals("172.16.8.10", ((UDPBroadcastGroupConfiguration) dc.getBroadcastEndpointFactoryConfiguration()).getLocalBindAddress()); - Assert.assertEquals(11999, ((UDPBroadcastGroupConfiguration) dc.getBroadcastEndpointFactoryConfiguration()).getGroupPort()); + Assert.assertEquals("192.168.0.120", ((UDPBroadcastEndpointFactory) dc.getBroadcastEndpointFactory()).getGroupAddress()); + assertEquals("172.16.8.10", ((UDPBroadcastEndpointFactory) dc.getBroadcastEndpointFactory()).getLocalBindAddress()); + Assert.assertEquals(11999, ((UDPBroadcastEndpointFactory) dc.getBroadcastEndpointFactory()).getGroupPort()); Assert.assertEquals(12345, dc.getRefreshTimeout()); dc = conf.getDiscoveryGroupConfigurations().get("dg2"); Assert.assertEquals("dg2", dc.getName()); - Assert.assertEquals("192.168.0.121", ((UDPBroadcastGroupConfiguration) dc.getBroadcastEndpointFactoryConfiguration()).getGroupAddress()); - assertEquals("172.16.8.11", ((UDPBroadcastGroupConfiguration) dc.getBroadcastEndpointFactoryConfiguration()).getLocalBindAddress()); - Assert.assertEquals(12999, ((UDPBroadcastGroupConfiguration) dc.getBroadcastEndpointFactoryConfiguration()).getGroupPort()); + Assert.assertEquals("192.168.0.121", ((UDPBroadcastEndpointFactory) dc.getBroadcastEndpointFactory()).getGroupAddress()); + assertEquals("172.16.8.11", ((UDPBroadcastEndpointFactory) dc.getBroadcastEndpointFactory()).getLocalBindAddress()); + Assert.assertEquals(12999, ((UDPBroadcastEndpointFactory) dc.getBroadcastEndpointFactory()).getGroupPort()); Assert.assertEquals(23456, dc.getRefreshTimeout()); Assert.assertEquals(2, conf.getDivertConfigurations().size()); diff --git a/docs/user-manual/en/using-jms.md b/docs/user-manual/en/using-jms.md index 0fe7595229..81aac795e9 100644 --- a/docs/user-manual/en/using-jms.md +++ b/docs/user-manual/en/using-jms.md @@ -64,38 +64,27 @@ A JMS connection factory is used by the client to make connections to the server. It knows the location of the server it is connecting to, as well as many other configuration parameters. -By default, a `javax.naming.Context` instance created using the -`org.apache.activemq.jndi.ActiveMQInitialContextFactory` will -automatically have the following connection factories available for -lookup: - -- `ConnectionFactory` - -- `XAConnectionFactory` - -- `QueueConnectionFactory` - -- `TopicConnectionFactory` - Here's a simple example of the JNDI context environment for a client looking up a connection factory to access an *embedded* instance of ActiveMQ: java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory + connectionFactory.invmConnectionFactory=vm://0 -It's really as simple as that. As noted previously, any JNDI context -created with the `ActiveMQInitialContextFactory` will have a set of -default connection factories available. Therefore, only the -`java.naming.factory.initial` property is required to access an embedded -broker. +In this instance we have created a connection factory that is bound to +`invmConnectionFactory`, any entry with prefix `connectionFactory.` will + create a connection factory. In certain situations there could be multiple server instances running within a particular JVM. In that situation each server would typically have an InVM acceptor with a unique server-ID. A client using JMS and -JNDI can account for this by specifying a -`javax.naming.Context.PROVIDER_URL` (`String` value of -"java.naming.provider.url") in the JNDI environment like `vm://2` where -`2` is the server-ID for acceptor. +JNDI can account for this by specifying a connction factory for each +server, like so: + + java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory + connectionFactory.invmConnectionFactory0=vm://0 + connectionFactory.invmConnectionFactory1=vm://1 + connectionFactory.invmConnectionFactory2=vm://2 Here is a list of all the supported URL schemes: @@ -108,19 +97,17 @@ Here is a list of all the supported URL schemes: - `jgroups` Most clients won't be connecting to an embedded broker. Clients will -most commonly connect across a network a remote broker. In that case the -client can use the `javax.naming.Context.PROVIDER_URL` (`String` value -of "java.naming.provider.url") in the JNDI environment to specify where -to connect. Here's a simple example of a client configuring a connection -factory to connect to a remote broker running on myhost:5445: +most commonly connect across a network a remote broker. Here's a simple +example of a client configuring a connection factory to connect to a +remote broker running on myhost:5445: java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory - java.naming.provider.url=tcp://myhost:5445 + connectionFactory.ConnectionFactory=tcp://myhost:5445 In the example above the client is using the `tcp` scheme for the provider URL. A client may also specify multiple comma-delimited host:port combinations in the URL (e.g. -`tcp://remote-host1:5445,remote-host2:5445`). Whether there is one or +`(tcp://remote-host1:5445,remote-host2:5445)`). Whether there is one or many host:port combinations in the URL they are treated as the *initial connector(s)* for the underlying connection. @@ -132,13 +119,24 @@ Each scheme has a specific set of properties which can be set using the traditional URL query string format (e.g. `scheme://host:port?key1=value1&key2=value2`) to customize the underlying transport mechanism. For example, if a client wanted to -connect to a remote server using TCP and SSL it would use a -`Context.PROVIDER_URL` of `tcp://remote-host:5445?ssl-enabled=true`. +connect to a remote server using TCP and SSL it would create a connection +factory like so, `tcp://remote-host:5445?ssl-enabled=true`. All the properties available for the `tcp` scheme are described in [the documentation regarding the Netty transport](#configuring-transports.netty). +Note if you are using the `tcp` scheme and multiple addresses then a query +can be applied to all the url's or just to an individual connector, so where +you have + +- `(tcp://remote-host1:5445?httpEnabled=true,remote-host2:5445?httpEnabled=true)?clientID=1234` + +then the `httpEnabled` property is only set on the individual connectors where as the `clientId` +is set on the actual connection factory. Any connector specific properties set on the whole +URI will be applied to all the connectors. + + The `udp` scheme supports 4 properties: - `local-address` - If you are running with multiple network @@ -169,48 +167,23 @@ The `udp` scheme supports 4 properties: value for this parameter is 10000 milliseconds. Lastly, the `jgroups` scheme is supported which provides an alternative -to the `udp` scheme for server discovery. The URL pattern is as follows -`jgroups://` where -`` refers to an XML file on the classpath -that contains the JGroups configuration. +to the `udp` scheme for server discovery. The URL pattern is either +`jgroups://channelName?file=jgroups-xml-conf-filename` +where`jgroups-xml-conf-filename` refers to an XML file on the classpath +that contains the JGroups configuration or it can be +`jgroups://channelName?properties=some-jgroups-properties`. In both instance the +`channelName` is the name given to the jgroups channel created. The `refresh-timeout` and `discovery-initial-wait-timeout` properties are supported just like with `udp`. -Although a `javax.naming.Context` instance created using the -`org.apache.activemq.jndi.ActiveMQInitialContextFactory` will -automatically have some connection factories present, it is possible for -a client to specify its own connection factories. This is done using the -`org.apache.activemq.jndi.ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES` -property (String value of "connectionFactoryNames"). The value for this -property is a comma delimited String of all the connection factories the -client wishes to create. For example: +The default type for the default connection factory is of type `javax.jms.ConnectionFactory`. +This can be changed by setting the type like so java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory - java.naming.provider.url=tcp://localhost:5445 - connectionFactoryNames=myConnectionFactory + java.naming.provider.url=tcp://localhost:5445?type=CF -In this example, the client is creating a connection factory named -"myConnectionFactory." This replaces all the default connection -factories so that only the "myConnectionFactory" connection factory is -available to the client. - -Aside from the underlying transport, the underlying connection factory -implementation can also be configured using special properties. To -configure a particular connection factory the client would follow this -pattern for the property name to set in the environment: -`connection..`. For example, if -the client wanted to customize the default connection factory -"ConnectionFactory" to support high-availability then it would do this: - - java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory - java.naming.provider.url=tcp://myhost:5445 - connection.ConnectionFactory.ha=true - -Any property available on the underlying -`org.apache.activemq.jms.client.ActiveMQConnectionFactory` can be set -this way in addition to the `ha` (boolean) and `type` (String) -properties. Here are the different options for the `type`: +In this example it is still set to the default, below shows a list of types that can be set. #### Configuration for Connection Factory Types diff --git a/examples/jms/aerogear/src/main/resources/jndi.properties b/examples/jms/aerogear/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/aerogear/src/main/resources/jndi.properties +++ b/examples/jms/aerogear/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/jms/example/ApplicationLayerFailoverExample.java b/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/jms/example/ApplicationLayerFailoverExample.java index 0c6e02385c..98373ac375 100644 --- a/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/jms/example/ApplicationLayerFailoverExample.java +++ b/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/jms/example/ApplicationLayerFailoverExample.java @@ -154,7 +154,7 @@ public class ApplicationLayerFailoverExample extends ActiveMQExample // Step 1. Get an initial context for looking up JNDI from the server Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", "tcp://127.0.0.1:" + (5445 + server)); + properties.put("connectionFactory.ConnectionFactory", "tcp://127.0.0.1:" + (5445 + server)); properties.put("queue.queue/exampleQueue", "exampleQueue"); initialContext = new InitialContext(properties); diff --git a/examples/jms/bridge/src/main/java/org/apache/activemq/jms/example/BridgeExample.java b/examples/jms/bridge/src/main/java/org/apache/activemq/jms/example/BridgeExample.java index 4f235b3fad..502a3e8b66 100644 --- a/examples/jms/bridge/src/main/java/org/apache/activemq/jms/example/BridgeExample.java +++ b/examples/jms/bridge/src/main/java/org/apache/activemq/jms/example/BridgeExample.java @@ -59,7 +59,7 @@ public class BridgeExample extends ActiveMQExample Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", "tcp://127.0.0.1:5445"); + properties.put("connectionFactory.ConnectionFactory", "tcp://127.0.0.1:5445"); properties.put("queue.queue/sausage-factory", "sausage-factory"); ic0 = new InitialContext(properties); @@ -75,7 +75,7 @@ public class BridgeExample extends ActiveMQExample properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", "tcp://127.0.0.1:5446"); + properties.put("connectionFactory.ConnectionFactory", "tcp://127.0.0.1:5446"); properties.put("queue.queue/mincing-machine", "mincing-machine"); ic1 = new InitialContext(properties); diff --git a/examples/jms/browser/src/main/resources/jndi.properties b/examples/jms/browser/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/browser/src/main/resources/jndi.properties +++ b/examples/jms/browser/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/client-kickoff/src/main/resources/jndi.properties b/examples/jms/client-kickoff/src/main/resources/jndi.properties index 142c406165..26a519cb94 100644 --- a/examples/jms/client-kickoff/src/main/resources/jndi.properties +++ b/examples/jms/client-kickoff/src/main/resources/jndi.properties @@ -16,4 +16,4 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 diff --git a/examples/jms/client-side-failoverlistener/src/main/resources/jndi.properties b/examples/jms/client-side-failoverlistener/src/main/resources/jndi.properties index 6feb57f155..8f3fcff6d4 100644 --- a/examples/jms/client-side-failoverlistener/src/main/resources/jndi.properties +++ b/examples/jms/client-side-failoverlistener/src/main/resources/jndi.properties @@ -16,9 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1 queue.queue/exampleQueue=exampleQueue -connection.ConnectionFactory.ha=true -connection.ConnectionFactory.retryInterval=1000 -connection.ConnectionFactory.retryIntervalMultiplier=1.0 -connection.ConnectionFactory.reconnectAttempts=-1 diff --git a/examples/jms/client-side-load-balancing/src/main/resources/jndi.properties b/examples/jms/client-side-load-balancing/src/main/resources/jndi.properties index e1bd34602e..81cf89854d 100644 --- a/examples/jms/client-side-load-balancing/src/main/resources/jndi.properties +++ b/examples/jms/client-side-load-balancing/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=udp://231.7.7.7:9876 +connectionFactory.ConnectionFactory=udp://231.7.7.7:9876 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/clustered-durable-subscription/src/main/java/org/apache/activemq/jms/example/ClusteredDurableSubscriptionExample.java b/examples/jms/clustered-durable-subscription/src/main/java/org/apache/activemq/jms/example/ClusteredDurableSubscriptionExample.java index 4b39f6cb28..4e4afc04ab 100644 --- a/examples/jms/clustered-durable-subscription/src/main/java/org/apache/activemq/jms/example/ClusteredDurableSubscriptionExample.java +++ b/examples/jms/clustered-durable-subscription/src/main/java/org/apache/activemq/jms/example/ClusteredDurableSubscriptionExample.java @@ -60,7 +60,7 @@ public class ClusteredDurableSubscriptionExample extends ActiveMQExample // Step 1. Get an initial context for looking up JNDI from server 0 Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[0]); + properties.put("connectionFactory.ConnectionFactory", args[0]); properties.put("topic.topic/exampleTopic", "exampleTopic"); ic0 = new InitialContext(properties); @@ -74,7 +74,7 @@ public class ClusteredDurableSubscriptionExample extends ActiveMQExample properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[1]); + properties.put("connectionFactory.ConnectionFactory", args[1]); ic1 = new InitialContext(properties); // Step 5. Look-up a JMS Connection Factory object from JNDI on server 1 diff --git a/examples/jms/clustered-grouping/src/main/java/org/apache/activemq/jms/example/ClusteredGroupingExample.java b/examples/jms/clustered-grouping/src/main/java/org/apache/activemq/jms/example/ClusteredGroupingExample.java index e5ead040e3..869f5ed427 100644 --- a/examples/jms/clustered-grouping/src/main/java/org/apache/activemq/jms/example/ClusteredGroupingExample.java +++ b/examples/jms/clustered-grouping/src/main/java/org/apache/activemq/jms/example/ClusteredGroupingExample.java @@ -62,7 +62,7 @@ public class ClusteredGroupingExample extends ActiveMQExample // Step 1. Get an initial context for looking up JNDI from server 0 Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[0]); + properties.put("connectionFactory.ConnectionFactory", args[0]); properties.put("queue.queue/exampleQueue", "exampleQueue"); ic0 = new InitialContext(properties); @@ -75,7 +75,7 @@ public class ClusteredGroupingExample extends ActiveMQExample // Step 4. Get an initial context for looking up JNDI from server 1 properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[1]); + properties.put("connectionFactory.ConnectionFactory", args[1]); ic1 = new InitialContext(properties); // Step 5. Look-up a JMS Connection Factory object from JNDI on server 1 @@ -84,7 +84,7 @@ public class ClusteredGroupingExample extends ActiveMQExample // Step 4. Get an initial context for looking up JNDI from server 2 properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[2]); + properties.put("connectionFactory.ConnectionFactory", args[2]); ic2 = new InitialContext(properties); // Step 5. Look-up a JMS Connection Factory object from JNDI on server 2 diff --git a/examples/jms/clustered-jgroups/src/main/java/org/apache/activemq/jms/example/ClusteredJgroupsExample.java b/examples/jms/clustered-jgroups/src/main/java/org/apache/activemq/jms/example/ClusteredJgroupsExample.java index 87e38d7e38..bdf6699e4f 100644 --- a/examples/jms/clustered-jgroups/src/main/java/org/apache/activemq/jms/example/ClusteredJgroupsExample.java +++ b/examples/jms/clustered-jgroups/src/main/java/org/apache/activemq/jms/example/ClusteredJgroupsExample.java @@ -58,7 +58,7 @@ public class ClusteredJgroupsExample extends ActiveMQExample // Step 1. Get an initial context for looking up JNDI from server 0 Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[0]); + properties.put("connectionFactory.ConnectionFactory", args[0]); properties.put("queue.queue/exampleQueue", "exampleQueue"); ic0 = new InitialContext(properties); @@ -71,7 +71,7 @@ public class ClusteredJgroupsExample extends ActiveMQExample // Step 4. Get an initial context for looking up JNDI from server 1 properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[1]); + properties.put("connectionFactory.ConnectionFactory", args[1]); ic1 = new InitialContext(properties); // Step 5. Look-up a JMS Connection Factory object from JNDI on server 1 diff --git a/examples/jms/clustered-jgroups/src/main/resources/activemq/server0/client-jndi.properties b/examples/jms/clustered-jgroups/src/main/resources/activemq/server0/client-jndi.properties index 142c406165..26a519cb94 100644 --- a/examples/jms/clustered-jgroups/src/main/resources/activemq/server0/client-jndi.properties +++ b/examples/jms/clustered-jgroups/src/main/resources/activemq/server0/client-jndi.properties @@ -16,4 +16,4 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 diff --git a/examples/jms/clustered-queue/src/main/java/org/apache/activemq/jms/example/ClusteredQueueExample.java b/examples/jms/clustered-queue/src/main/java/org/apache/activemq/jms/example/ClusteredQueueExample.java index 2da188157f..bdc8be3704 100644 --- a/examples/jms/clustered-queue/src/main/java/org/apache/activemq/jms/example/ClusteredQueueExample.java +++ b/examples/jms/clustered-queue/src/main/java/org/apache/activemq/jms/example/ClusteredQueueExample.java @@ -58,7 +58,7 @@ public class ClusteredQueueExample extends ActiveMQExample // Step 1. Get an initial context for looking up JNDI from server 0 Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[0]); + properties.put("connectionFactory.ConnectionFactory", args[0]); properties.put("queue.queue/exampleQueue", "exampleQueue"); ic0 = new InitialContext(properties); @@ -71,7 +71,7 @@ public class ClusteredQueueExample extends ActiveMQExample // Step 4. Get an initial context for looking up JNDI from server 1 properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[1]); + properties.put("connectionFactory.ConnectionFactory", args[1]); ic1 = new InitialContext(properties); // Step 5. Look-up a JMS Connection Factory object from JNDI on server 1 diff --git a/examples/jms/clustered-standalone/src/main/java/org/apache/activemq/jms/example/ClusteredStandaloneExample.java b/examples/jms/clustered-standalone/src/main/java/org/apache/activemq/jms/example/ClusteredStandaloneExample.java index e516469560..60dc7d33d3 100644 --- a/examples/jms/clustered-standalone/src/main/java/org/apache/activemq/jms/example/ClusteredStandaloneExample.java +++ b/examples/jms/clustered-standalone/src/main/java/org/apache/activemq/jms/example/ClusteredStandaloneExample.java @@ -56,18 +56,18 @@ public class ClusteredStandaloneExample extends ActiveMQExample { Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[0]); + properties.put("connectionFactory.ConnectionFactory", args[0]); properties.put("topic.topic/exampleTopic", "exampleTopic"); initialContext0 = new InitialContext(properties); properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[1]); + properties.put("connectionFactory.ConnectionFactory", args[1]); initialContext1 = new InitialContext(properties); properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[2]); + properties.put("connectionFactory.ConnectionFactory", args[2]); initialContext2 = new InitialContext(properties); // First we demonstrate a distributed topic. diff --git a/examples/jms/clustered-static-discovery/src/main/java/org/apache/activemq/jms/example/StaticClusteredQueueExample.java b/examples/jms/clustered-static-discovery/src/main/java/org/apache/activemq/jms/example/StaticClusteredQueueExample.java index f724c92683..e587536bae 100644 --- a/examples/jms/clustered-static-discovery/src/main/java/org/apache/activemq/jms/example/StaticClusteredQueueExample.java +++ b/examples/jms/clustered-static-discovery/src/main/java/org/apache/activemq/jms/example/StaticClusteredQueueExample.java @@ -62,7 +62,7 @@ public class StaticClusteredQueueExample extends ActiveMQExample // Step 1. Get an initial context for looking up JNDI from server 3 Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[3]); + properties.put("connectionFactory.ConnectionFactory", args[3]); properties.put("queue.queue/exampleQueue", "exampleQueue"); ic0 = new InitialContext(properties); diff --git a/examples/jms/clustered-static-oneway/src/main/java/org/apache/activemq/jms/example/ClusterStaticOnewayExample.java b/examples/jms/clustered-static-oneway/src/main/java/org/apache/activemq/jms/example/ClusterStaticOnewayExample.java index c88d2e4135..0ddefeba9e 100644 --- a/examples/jms/clustered-static-oneway/src/main/java/org/apache/activemq/jms/example/ClusterStaticOnewayExample.java +++ b/examples/jms/clustered-static-oneway/src/main/java/org/apache/activemq/jms/example/ClusterStaticOnewayExample.java @@ -60,7 +60,7 @@ public class ClusterStaticOnewayExample extends ActiveMQExample // Step 1. Get an initial context for looking up JNDI from server 0 Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[0]); + properties.put("connectionFactory.ConnectionFactory", args[0]); properties.put("queue.queue/exampleQueue", "exampleQueue"); ic0 = new InitialContext(properties); diff --git a/examples/jms/clustered-topic/src/main/java/org/apache/activemq/jms/example/ClusteredTopicExample.java b/examples/jms/clustered-topic/src/main/java/org/apache/activemq/jms/example/ClusteredTopicExample.java index ca98789f3a..61e3d65563 100644 --- a/examples/jms/clustered-topic/src/main/java/org/apache/activemq/jms/example/ClusteredTopicExample.java +++ b/examples/jms/clustered-topic/src/main/java/org/apache/activemq/jms/example/ClusteredTopicExample.java @@ -58,7 +58,7 @@ public class ClusteredTopicExample extends ActiveMQExample // Step 1. Get an initial context for looking up JNDI from server 0 Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[0]); + properties.put("connectionFactory.ConnectionFactory", args[0]); properties.put("topic.topic/exampleTopic", "exampleTopic"); ic0 = new InitialContext(properties); @@ -71,7 +71,7 @@ public class ClusteredTopicExample extends ActiveMQExample // Step 4. Get an initial context for looking up JNDI from server 1 properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[1]); + properties.put("connectionFactory.ConnectionFactory", args[1]); ic1 = new InitialContext(properties); // Step 5. Look-up a JMS Connection Factory object from JNDI on server 1 diff --git a/examples/jms/colocated-failover-scale-down/src/main/java/org/apache/activemq/jms/example/ColocatedFailoverScaleDownExample.java b/examples/jms/colocated-failover-scale-down/src/main/java/org/apache/activemq/jms/example/ColocatedFailoverScaleDownExample.java index f5e5a2977b..bc2358979e 100644 --- a/examples/jms/colocated-failover-scale-down/src/main/java/org/apache/activemq/jms/example/ColocatedFailoverScaleDownExample.java +++ b/examples/jms/colocated-failover-scale-down/src/main/java/org/apache/activemq/jms/example/ColocatedFailoverScaleDownExample.java @@ -58,17 +58,13 @@ public class ColocatedFailoverScaleDownExample extends ActiveMQExample // Step 1. Get an initial context for looking up JNDI for both servers Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[1]); + properties.put("connectionFactory.ConnectionFactory", args[1]); initialContext1 = new InitialContext(properties); properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[0]); + properties.put("connectionFactory.ConnectionFactory", args[0] + "?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1"); properties.put("queue.queue/exampleQueue", "exampleQueue"); - properties.put("connection.ConnectionFactory.ha", true); - properties.put("connection.ConnectionFactory.retryInterval", 1000); - properties.put("connection.ConnectionFactory.retryIntervalMultiplier", 1.0); - properties.put("connection.ConnectionFactory.reconnectAttempts", -1); initialContext = new InitialContext(properties); // Step 2. Look up the JMS resources from JNDI diff --git a/examples/jms/colocated-failover/src/main/java/org/apache/activemq/jms/example/ColocatedFailoverExample.java b/examples/jms/colocated-failover/src/main/java/org/apache/activemq/jms/example/ColocatedFailoverExample.java index 1e912e092f..4c6a9a9b84 100644 --- a/examples/jms/colocated-failover/src/main/java/org/apache/activemq/jms/example/ColocatedFailoverExample.java +++ b/examples/jms/colocated-failover/src/main/java/org/apache/activemq/jms/example/ColocatedFailoverExample.java @@ -56,17 +56,13 @@ public class ColocatedFailoverExample extends ActiveMQExample // Step 1. Get an initial context for looking up JNDI for both servers Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[1]); + properties.put("connectionFactory.ConnectionFactory", args[1]); initialContext1 = new InitialContext(properties); properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[0]); + properties.put("connectionFactory.ConnectionFactory", args[0] + "?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1"); properties.put("queue.queue/exampleQueue", "exampleQueue"); - properties.put("connection.ConnectionFactory.ha", true); - properties.put("connection.ConnectionFactory.retryInterval", 1000); - properties.put("connection.ConnectionFactory.retryIntervalMultiplier", 1.0); - properties.put("connection.ConnectionFactory.reconnectAttempts", -1); initialContext = new InitialContext(properties); // Step 2. Look up the JMS resources from JNDI diff --git a/examples/jms/consumer-rate-limit/src/main/resources/jndi.properties b/examples/jms/consumer-rate-limit/src/main/resources/jndi.properties index e0f10fcd27..9692146fd7 100644 --- a/examples/jms/consumer-rate-limit/src/main/resources/jndi.properties +++ b/examples/jms/consumer-rate-limit/src/main/resources/jndi.properties @@ -16,6 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.consumerMaxRate=10 +connectionFactory.ConnectionFactory=tcp://localhost:5445?consumerMaxRate=10 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/dead-letter/src/main/resources/jndi.properties b/examples/jms/dead-letter/src/main/resources/jndi.properties index cb6ac0eed3..d9700fded0 100644 --- a/examples/jms/dead-letter/src/main/resources/jndi.properties +++ b/examples/jms/dead-letter/src/main/resources/jndi.properties @@ -16,6 +16,6 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue queue.queue/deadLetterQueue=deadLetterQueue diff --git a/examples/jms/delayed-redelivery/src/main/resources/jndi.properties b/examples/jms/delayed-redelivery/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/delayed-redelivery/src/main/resources/jndi.properties +++ b/examples/jms/delayed-redelivery/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/divert/src/main/java/org/apache/activemq/jms/example/DivertExample.java b/examples/jms/divert/src/main/java/org/apache/activemq/jms/example/DivertExample.java index 57e4327d99..4f197cebc3 100644 --- a/examples/jms/divert/src/main/java/org/apache/activemq/jms/example/DivertExample.java +++ b/examples/jms/divert/src/main/java/org/apache/activemq/jms/example/DivertExample.java @@ -61,7 +61,7 @@ public class DivertExample extends ActiveMQExample // Step 1. Create an initial context to perform the JNDI lookup on the London server Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[0]); + properties.put("connectionFactory.ConnectionFactory", args[0]); properties.put("queue.queue/orders", "orders"); properties.put("topic.topic/priceUpdates", "priceUpdates"); properties.put("topic.topic/spyTopic", "spyTopic"); @@ -80,7 +80,7 @@ public class DivertExample extends ActiveMQExample // Step 6. Create an initial context to perform the JNDI lookup on the New York server properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[1]); + properties.put("connectionFactory.ConnectionFactory", args[1]); properties.put("topic.topic/newYorkPriceUpdates", "newYorkPriceUpdates"); initialContextNewYork = new InitialContext(properties); diff --git a/examples/jms/durable-subscription/src/main/resources/jndi.properties b/examples/jms/durable-subscription/src/main/resources/jndi.properties index 65fc26e536..9c96675b88 100644 --- a/examples/jms/durable-subscription/src/main/resources/jndi.properties +++ b/examples/jms/durable-subscription/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 topic.topic/exampleTopic=exampleTopic diff --git a/examples/jms/expiry/src/main/resources/jndi.properties b/examples/jms/expiry/src/main/resources/jndi.properties index 1ea8e7c67c..82edb2e76e 100644 --- a/examples/jms/expiry/src/main/resources/jndi.properties +++ b/examples/jms/expiry/src/main/resources/jndi.properties @@ -16,6 +16,6 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue queue.queue/expiryQueue=expiryQueue diff --git a/examples/jms/ha-policy-autobackup/src/main/java/org/apache/activemq/jms/example/HAPolicyAutoBackupExample.java b/examples/jms/ha-policy-autobackup/src/main/java/org/apache/activemq/jms/example/HAPolicyAutoBackupExample.java index 4fbcdcb8e1..86b6f985dd 100644 --- a/examples/jms/ha-policy-autobackup/src/main/java/org/apache/activemq/jms/example/HAPolicyAutoBackupExample.java +++ b/examples/jms/ha-policy-autobackup/src/main/java/org/apache/activemq/jms/example/HAPolicyAutoBackupExample.java @@ -67,21 +67,13 @@ public class HAPolicyAutoBackupExample extends ActiveMQExample // Step 1. Get an initial context for looking up JNDI from server 0 and 1 Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[0]); + properties.put("connectionFactory.ConnectionFactory", args[0] + "?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1"); properties.put("queue.queue/exampleQueue", "exampleQueue"); - properties.put("connection.ConnectionFactory.ha", true); - properties.put("connection.ConnectionFactory.retryInterval", 1000); - properties.put("connection.ConnectionFactory.retryIntervalMultiplier", 1.0); - properties.put("connection.ConnectionFactory.reconnectAttempts", -1); ic0 = new InitialContext(properties); properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[1]); - properties.put("connection.ConnectionFactory.ha", true); - properties.put("connection.ConnectionFactory.retryInterval", 1000); - properties.put("connection.ConnectionFactory.retryIntervalMultiplier", 1.0); - properties.put("connection.ConnectionFactory.reconnectAttempts", -1); + properties.put("connectionFactory.ConnectionFactory", args[1] + "?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1"); ic1 = new InitialContext(properties); // Step 2. Look-up the JMS Queue object from JNDI diff --git a/examples/jms/http-transport/src/main/resources/jndi.properties b/examples/jms/http-transport/src/main/resources/jndi.properties index c3cfd6c7f6..7bc4a11be6 100644 --- a/examples/jms/http-transport/src/main/resources/jndi.properties +++ b/examples/jms/http-transport/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:8080?http-enabled=true +connectionFactory.ConnectionFactory=tcp://localhost:8080?http-enabled=true queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/interceptor/src/main/resources/jndi.properties b/examples/jms/interceptor/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/interceptor/src/main/resources/jndi.properties +++ b/examples/jms/interceptor/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/jms-auto-closeable/src/main/resources/jndi.properties b/examples/jms/jms-auto-closeable/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/jms-auto-closeable/src/main/resources/jndi.properties +++ b/examples/jms/jms-auto-closeable/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/jms-bridge/src/main/java/org/apache/activemq/jms/example/JMSBridgeExample.java b/examples/jms/jms-bridge/src/main/java/org/apache/activemq/jms/example/JMSBridgeExample.java index 0eaa6353f6..83b4228654 100644 --- a/examples/jms/jms-bridge/src/main/java/org/apache/activemq/jms/example/JMSBridgeExample.java +++ b/examples/jms/jms-bridge/src/main/java/org/apache/activemq/jms/example/JMSBridgeExample.java @@ -165,7 +165,7 @@ public class JMSBridgeExample private static Hashtable createJndiParams(String server) { Hashtable jndiProps = new Hashtable(); - jndiProps.put("java.naming.provider.url", server); + jndiProps.put("connectionFactory.ConnectionFactory", server); jndiProps.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); jndiProps.put("queue.target/queue", "target"); jndiProps.put("topic.source/topic", "topic"); diff --git a/examples/jms/jms-completion-listener/src/main/resources/jndi.properties b/examples/jms/jms-completion-listener/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/jms-completion-listener/src/main/resources/jndi.properties +++ b/examples/jms/jms-completion-listener/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/jms-context/src/main/resources/jndi.properties b/examples/jms/jms-context/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/jms-context/src/main/resources/jndi.properties +++ b/examples/jms/jms-context/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/jms-shared-consumer/src/main/resources/jndi.properties b/examples/jms/jms-shared-consumer/src/main/resources/jndi.properties index 65fc26e536..9c96675b88 100644 --- a/examples/jms/jms-shared-consumer/src/main/resources/jndi.properties +++ b/examples/jms/jms-shared-consumer/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 topic.topic/exampleTopic=exampleTopic diff --git a/examples/jms/jmx/src/main/resources/jndi.properties b/examples/jms/jmx/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/jmx/src/main/resources/jndi.properties +++ b/examples/jms/jmx/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/large-message/src/main/resources/jndi.properties b/examples/jms/large-message/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/large-message/src/main/resources/jndi.properties +++ b/examples/jms/large-message/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/last-value-queue/src/main/resources/jndi.properties b/examples/jms/last-value-queue/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/last-value-queue/src/main/resources/jndi.properties +++ b/examples/jms/last-value-queue/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/management-notifications/src/main/resources/jndi.properties b/examples/jms/management-notifications/src/main/resources/jndi.properties index 62c20c6363..a9953c335c 100644 --- a/examples/jms/management-notifications/src/main/resources/jndi.properties +++ b/examples/jms/management-notifications/src/main/resources/jndi.properties @@ -16,6 +16,6 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue topic.topic/notificationsTopic=notificationsTopic diff --git a/examples/jms/management/src/main/resources/jndi.properties b/examples/jms/management/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/management/src/main/resources/jndi.properties +++ b/examples/jms/management/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/message-counters/src/main/resources/jndi.properties b/examples/jms/message-counters/src/main/resources/jndi.properties index 1ea8e7c67c..82edb2e76e 100644 --- a/examples/jms/message-counters/src/main/resources/jndi.properties +++ b/examples/jms/message-counters/src/main/resources/jndi.properties @@ -16,6 +16,6 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue queue.queue/expiryQueue=expiryQueue diff --git a/examples/jms/message-group/src/main/resources/jndi.properties b/examples/jms/message-group/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/message-group/src/main/resources/jndi.properties +++ b/examples/jms/message-group/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/message-group2/src/main/resources/jndi.properties b/examples/jms/message-group2/src/main/resources/jndi.properties index e77a1a222c..58fe8fb2aa 100644 --- a/examples/jms/message-group2/src/main/resources/jndi.properties +++ b/examples/jms/message-group2/src/main/resources/jndi.properties @@ -16,6 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.groupID=Group-0 +connectionFactory.ConnectionFactory=tcp://localhost:5445?groupID=Group-0 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/message-priority/src/main/resources/jndi.properties b/examples/jms/message-priority/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/message-priority/src/main/resources/jndi.properties +++ b/examples/jms/message-priority/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/multiple-failover-failback/src/main/resources/jndi.properties b/examples/jms/multiple-failover-failback/src/main/resources/jndi.properties index 99e6a96118..8f3fcff6d4 100644 --- a/examples/jms/multiple-failover-failback/src/main/resources/jndi.properties +++ b/examples/jms/multiple-failover-failback/src/main/resources/jndi.properties @@ -16,9 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.ha=true -connection.ConnectionFactory.retryInterval=1000 -connection.ConnectionFactory.retryIntervalMultiplier=1.0 -connection.ConnectionFactory.reconnectAttempts=-1 +connectionFactory.ConnectionFactory=tcp://localhost:5445?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/multiple-failover/src/main/resources/jndi.properties b/examples/jms/multiple-failover/src/main/resources/jndi.properties index 99e6a96118..8f3fcff6d4 100644 --- a/examples/jms/multiple-failover/src/main/resources/jndi.properties +++ b/examples/jms/multiple-failover/src/main/resources/jndi.properties @@ -16,9 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.ha=true -connection.ConnectionFactory.retryInterval=1000 -connection.ConnectionFactory.retryIntervalMultiplier=1.0 -connection.ConnectionFactory.reconnectAttempts=-1 +connectionFactory.ConnectionFactory=tcp://localhost:5445?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/no-consumer-buffering/src/main/resources/jndi.properties b/examples/jms/no-consumer-buffering/src/main/resources/jndi.properties index 6c55f6736a..40afd87d79 100644 --- a/examples/jms/no-consumer-buffering/src/main/resources/jndi.properties +++ b/examples/jms/no-consumer-buffering/src/main/resources/jndi.properties @@ -16,6 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.consumerWindowSize=0 +connectionFactory.ConnectionFactory=tcp://localhost:5445?consumerWindowSize=0 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/non-transaction-failover/src/main/resources/jndi.properties b/examples/jms/non-transaction-failover/src/main/resources/jndi.properties index 99e6a96118..8f3fcff6d4 100644 --- a/examples/jms/non-transaction-failover/src/main/resources/jndi.properties +++ b/examples/jms/non-transaction-failover/src/main/resources/jndi.properties @@ -16,9 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.ha=true -connection.ConnectionFactory.retryInterval=1000 -connection.ConnectionFactory.retryIntervalMultiplier=1.0 -connection.ConnectionFactory.reconnectAttempts=-1 +connectionFactory.ConnectionFactory=tcp://localhost:5445?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/paging/src/main/resources/jndi.properties b/examples/jms/paging/src/main/resources/jndi.properties index 04d55cba31..a85328e7f1 100644 --- a/examples/jms/paging/src/main/resources/jndi.properties +++ b/examples/jms/paging/src/main/resources/jndi.properties @@ -16,6 +16,6 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue queue.queue/pagingQueue=pagingQueue diff --git a/examples/jms/perf/src/main/resources/jndi.properties b/examples/jms/perf/src/main/resources/jndi.properties index 9121768af2..4a50fa84d4 100644 --- a/examples/jms/perf/src/main/resources/jndi.properties +++ b/examples/jms/perf/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445?tcp-no-delay=false&tcp-send-buffer-size=1048576&tcp-receive-buffer-size=1048576 +connectionFactory.ConnectionFactory=tcp://localhost:5445?tcp-no-delay=false&tcp-send-buffer-size=1048576&tcp-receive-buffer-size=1048576 queue.perfQueue=perfQueue diff --git a/examples/jms/pre-acknowledge/src/main/resources/jndi.properties b/examples/jms/pre-acknowledge/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/pre-acknowledge/src/main/resources/jndi.properties +++ b/examples/jms/pre-acknowledge/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/producer-rate-limit/src/main/resources/jndi.properties b/examples/jms/producer-rate-limit/src/main/resources/jndi.properties index fe67b3b829..3ab55a5355 100644 --- a/examples/jms/producer-rate-limit/src/main/resources/jndi.properties +++ b/examples/jms/producer-rate-limit/src/main/resources/jndi.properties @@ -16,6 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.producerMaxRate=50 +connectionFactory.ConnectionFactory=tcp://localhost:5445?producerMaxRate=50 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/queue-message-redistribution/src/main/java/org/apache/activemq/jms/example/QueueMessageRedistributionExample.java b/examples/jms/queue-message-redistribution/src/main/java/org/apache/activemq/jms/example/QueueMessageRedistributionExample.java index b2c473c274..a64e0f6c58 100644 --- a/examples/jms/queue-message-redistribution/src/main/java/org/apache/activemq/jms/example/QueueMessageRedistributionExample.java +++ b/examples/jms/queue-message-redistribution/src/main/java/org/apache/activemq/jms/example/QueueMessageRedistributionExample.java @@ -60,7 +60,7 @@ public class QueueMessageRedistributionExample extends ActiveMQExample // Step 1. Get an initial context for looking up JNDI from server 0 Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[0]); + properties.put("connectionFactory.ConnectionFactory", args[0]); properties.put("queue.queue/exampleQueue", "exampleQueue"); ic0 = new InitialContext(properties); @@ -73,7 +73,7 @@ public class QueueMessageRedistributionExample extends ActiveMQExample // Step 4. Get an initial context for looking up JNDI from server 1 properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[1]); + properties.put("connectionFactory.ConnectionFactory", args[1]); ic1 = new InitialContext(properties); // Step 5. Look-up a JMS Connection Factory object from JNDI on server 1 diff --git a/examples/jms/queue-requestor/src/main/resources/jndi.properties b/examples/jms/queue-requestor/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/queue-requestor/src/main/resources/jndi.properties +++ b/examples/jms/queue-requestor/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/queue-selector/src/main/resources/jndi.properties b/examples/jms/queue-selector/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/queue-selector/src/main/resources/jndi.properties +++ b/examples/jms/queue-selector/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/queue/src/main/resources/jndi.properties b/examples/jms/queue/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/queue/src/main/resources/jndi.properties +++ b/examples/jms/queue/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/reattach-node/src/main/java/org/apache/activemq/jms/example/ReattachExample.java b/examples/jms/reattach-node/src/main/java/org/apache/activemq/jms/example/ReattachExample.java index 9a9d58fbc2..eeb5856f33 100644 --- a/examples/jms/reattach-node/src/main/java/org/apache/activemq/jms/example/ReattachExample.java +++ b/examples/jms/reattach-node/src/main/java/org/apache/activemq/jms/example/ReattachExample.java @@ -140,7 +140,7 @@ public class ReattachExample extends ActiveMQExample { Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", "tcp://localhost:5446"); + properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:5446"); InitialContext initialContext = new InitialContext(properties); ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("ConnectionFactory"); diff --git a/examples/jms/reattach-node/src/main/resources/jndi.properties b/examples/jms/reattach-node/src/main/resources/jndi.properties index bc3c80f834..639551e036 100644 --- a/examples/jms/reattach-node/src/main/resources/jndi.properties +++ b/examples/jms/reattach-node/src/main/resources/jndi.properties @@ -16,10 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.retryInterval=1000 -connection.ConnectionFactory.retryIntervalMultiplier=1.0 -connection.ConnectionFactory.reconnectAttempts=-1 -connection.ConnectionFactory.failoverOnServerShutdown=true -connection.ConnectionFactory.confirmationWindowSize=1048576 +connectionFactory.ConnectionFactory=tcp://localhost:5445?retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1&failoverOnServerShutdown=true&confirmationWindowSize=1048576 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/replicated-failback-static/src/main/resources/jndi.properties b/examples/jms/replicated-failback-static/src/main/resources/jndi.properties index 99e6a96118..8f3fcff6d4 100644 --- a/examples/jms/replicated-failback-static/src/main/resources/jndi.properties +++ b/examples/jms/replicated-failback-static/src/main/resources/jndi.properties @@ -16,9 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.ha=true -connection.ConnectionFactory.retryInterval=1000 -connection.ConnectionFactory.retryIntervalMultiplier=1.0 -connection.ConnectionFactory.reconnectAttempts=-1 +connectionFactory.ConnectionFactory=tcp://localhost:5445?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/replicated-failback/src/main/resources/jndi.properties b/examples/jms/replicated-failback/src/main/resources/jndi.properties index 99e6a96118..8f3fcff6d4 100644 --- a/examples/jms/replicated-failback/src/main/resources/jndi.properties +++ b/examples/jms/replicated-failback/src/main/resources/jndi.properties @@ -16,9 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.ha=true -connection.ConnectionFactory.retryInterval=1000 -connection.ConnectionFactory.retryIntervalMultiplier=1.0 -connection.ConnectionFactory.reconnectAttempts=-1 +connectionFactory.ConnectionFactory=tcp://localhost:5445?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/replicated-multiple-failover/src/main/resources/jndi.properties b/examples/jms/replicated-multiple-failover/src/main/resources/jndi.properties index 99e6a96118..8f3fcff6d4 100644 --- a/examples/jms/replicated-multiple-failover/src/main/resources/jndi.properties +++ b/examples/jms/replicated-multiple-failover/src/main/resources/jndi.properties @@ -16,9 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.ha=true -connection.ConnectionFactory.retryInterval=1000 -connection.ConnectionFactory.retryIntervalMultiplier=1.0 -connection.ConnectionFactory.reconnectAttempts=-1 +connectionFactory.ConnectionFactory=tcp://localhost:5445?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/replicated-transaction-failover/src/main/resources/jndi.properties b/examples/jms/replicated-transaction-failover/src/main/resources/jndi.properties index 99e6a96118..8f3fcff6d4 100644 --- a/examples/jms/replicated-transaction-failover/src/main/resources/jndi.properties +++ b/examples/jms/replicated-transaction-failover/src/main/resources/jndi.properties @@ -16,9 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.ha=true -connection.ConnectionFactory.retryInterval=1000 -connection.ConnectionFactory.retryIntervalMultiplier=1.0 -connection.ConnectionFactory.reconnectAttempts=-1 +connectionFactory.ConnectionFactory=tcp://localhost:5445?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/request-reply/src/main/resources/jndi.properties b/examples/jms/request-reply/src/main/resources/jndi.properties index 99e6a96118..8f3fcff6d4 100644 --- a/examples/jms/request-reply/src/main/resources/jndi.properties +++ b/examples/jms/request-reply/src/main/resources/jndi.properties @@ -16,9 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.ha=true -connection.ConnectionFactory.retryInterval=1000 -connection.ConnectionFactory.retryIntervalMultiplier=1.0 -connection.ConnectionFactory.reconnectAttempts=-1 +connectionFactory.ConnectionFactory=tcp://localhost:5445?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/scale-down/src/main/java/org/apache/activemq/jms/example/ScaleDownExample.java b/examples/jms/scale-down/src/main/java/org/apache/activemq/jms/example/ScaleDownExample.java index 3d29180cc6..0bcc4bc63e 100644 --- a/examples/jms/scale-down/src/main/java/org/apache/activemq/jms/example/ScaleDownExample.java +++ b/examples/jms/scale-down/src/main/java/org/apache/activemq/jms/example/ScaleDownExample.java @@ -56,21 +56,13 @@ public class ScaleDownExample extends ActiveMQExample // Step 1. Get an initial context for looking up JNDI for both servers Hashtable properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[0]); - properties.put("connection.ConnectionFactory.ha", true); - properties.put("connection.ConnectionFactory.retryInterval", 1000); - properties.put("connection.ConnectionFactory.retryIntervalMultiplier", 1.0); - properties.put("connection.ConnectionFactory.reconnectAttempts", -1); + properties.put("connectionFactory.ConnectionFactory", args[0] + "?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1"); properties.put("queue.queue/exampleQueue", "exampleQueue"); initialContext = new InitialContext(properties); properties = new Hashtable(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - properties.put("java.naming.provider.url", args[1]); - properties.put("connection.ConnectionFactory.ha", true); - properties.put("connection.ConnectionFactory.retryInterval", 1000); - properties.put("connection.ConnectionFactory.retryIntervalMultiplier", 1.0); - properties.put("connection.ConnectionFactory.reconnectAttempts", -1); + properties.put("connectionFactory.ConnectionFactory", args[1] + "?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1"); initialContext1 = new InitialContext(properties); // Step 2. Look up the JMS resources from JNDI diff --git a/examples/jms/scheduled-message/src/main/resources/jndi.properties b/examples/jms/scheduled-message/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/scheduled-message/src/main/resources/jndi.properties +++ b/examples/jms/scheduled-message/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/security/src/main/resources/jndi.properties b/examples/jms/security/src/main/resources/jndi.properties index 792ace4365..f7af861d1a 100644 --- a/examples/jms/security/src/main/resources/jndi.properties +++ b/examples/jms/security/src/main/resources/jndi.properties @@ -16,7 +16,7 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 topic.topic/genericTopic=genericTopic topic.topic/europeTopic=news.europe.europeTopic topic.topic/usTopic=news.us.usTopic diff --git a/examples/jms/send-acknowledgements/src/main/resources/jndi.properties b/examples/jms/send-acknowledgements/src/main/resources/jndi.properties index a6bcbcea6d..ed1d694aae 100644 --- a/examples/jms/send-acknowledgements/src/main/resources/jndi.properties +++ b/examples/jms/send-acknowledgements/src/main/resources/jndi.properties @@ -16,6 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.confirmationWindowSize=1048576 +connectionFactory.ConnectionFactory=tcp://localhost:5445?confirmationWindowSize=1048576 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/ssl-enabled/src/main/resources/jndi.properties b/examples/jms/ssl-enabled/src/main/resources/jndi.properties index 4bcf3c7c36..2bbd86808b 100644 --- a/examples/jms/ssl-enabled/src/main/resources/jndi.properties +++ b/examples/jms/ssl-enabled/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5500?ssl-enabled=true&trust-store-path=activemq/server0/activemq.example.truststore&trust-store-password=activemqexample +connectionFactory.ConnectionFactory=tcp://localhost:5500?ssl-enabled=true&trust-store-path=activemq/server0/activemq.example.truststore&trust-store-password=activemqexample queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/static-selector-jms/src/main/resources/jndi.properties b/examples/jms/static-selector-jms/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/static-selector-jms/src/main/resources/jndi.properties +++ b/examples/jms/static-selector-jms/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/static-selector/src/main/resources/jndi.properties b/examples/jms/static-selector/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/static-selector/src/main/resources/jndi.properties +++ b/examples/jms/static-selector/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/stomp-websockets/src/main/resources/jndi.properties b/examples/jms/stomp-websockets/src/main/resources/jndi.properties index 03499b1f27..b509e71b12 100644 --- a/examples/jms/stomp-websockets/src/main/resources/jndi.properties +++ b/examples/jms/stomp-websockets/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 topic.topic/chat=chat diff --git a/examples/jms/stomp/src/main/resources/jndi.properties b/examples/jms/stomp/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/stomp/src/main/resources/jndi.properties +++ b/examples/jms/stomp/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/stomp1.1/src/main/resources/jndi.properties b/examples/jms/stomp1.1/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/stomp1.1/src/main/resources/jndi.properties +++ b/examples/jms/stomp1.1/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/stomp1.2/src/main/resources/jndi.properties b/examples/jms/stomp1.2/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/stomp1.2/src/main/resources/jndi.properties +++ b/examples/jms/stomp1.2/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/stop-server-failover/src/main/resources/jndi.properties b/examples/jms/stop-server-failover/src/main/resources/jndi.properties index 99e6a96118..8f3fcff6d4 100644 --- a/examples/jms/stop-server-failover/src/main/resources/jndi.properties +++ b/examples/jms/stop-server-failover/src/main/resources/jndi.properties @@ -16,9 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.ha=true -connection.ConnectionFactory.retryInterval=1000 -connection.ConnectionFactory.retryIntervalMultiplier=1.0 -connection.ConnectionFactory.reconnectAttempts=-1 +connectionFactory.ConnectionFactory=tcp://localhost:5445?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/symmetric-cluster/src/main/java/org/apache/activemq/jms/example/SymmetricClusterExample.java b/examples/jms/symmetric-cluster/src/main/java/org/apache/activemq/jms/example/SymmetricClusterExample.java index 235226a49f..c7925e428d 100644 --- a/examples/jms/symmetric-cluster/src/main/java/org/apache/activemq/jms/example/SymmetricClusterExample.java +++ b/examples/jms/symmetric-cluster/src/main/java/org/apache/activemq/jms/example/SymmetricClusterExample.java @@ -26,8 +26,7 @@ import javax.jms.TextMessage; import javax.jms.Topic; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; -import org.apache.activemq.api.core.client.ActiveMQClient; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.jms.ActiveMQJMSClient; import org.apache.activemq.api.jms.JMSFactoryType; import org.apache.activemq.common.example.ActiveMQExample; @@ -82,10 +81,10 @@ public class SymmetricClusterExample extends ActiveMQExample // connection factory directly we avoid having to worry about a JNDI look-up. // In an app server environment you could use HA-JNDI to lookup from the clustered JNDI servers without // having to know about a specific one. - UDPBroadcastGroupConfiguration udpCfg = new UDPBroadcastGroupConfiguration(); + UDPBroadcastEndpointFactory udpCfg = new UDPBroadcastEndpointFactory(); udpCfg.setGroupAddress("231.7.7.7").setGroupPort(9876); DiscoveryGroupConfiguration groupConfiguration = new DiscoveryGroupConfiguration(); - groupConfiguration.setBroadcastEndpointFactoryConfiguration(udpCfg); + groupConfiguration.setBroadcastEndpointFactory(udpCfg); ConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithHA(groupConfiguration, JMSFactoryType.CF); diff --git a/examples/jms/temp-queue/src/main/resources/jndi.properties b/examples/jms/temp-queue/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/temp-queue/src/main/resources/jndi.properties +++ b/examples/jms/temp-queue/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/topic-hierarchies/src/main/resources/jndi.properties b/examples/jms/topic-hierarchies/src/main/resources/jndi.properties index 142c406165..26a519cb94 100644 --- a/examples/jms/topic-hierarchies/src/main/resources/jndi.properties +++ b/examples/jms/topic-hierarchies/src/main/resources/jndi.properties @@ -16,4 +16,4 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 diff --git a/examples/jms/topic-selector-example1/src/main/resources/jndi.properties b/examples/jms/topic-selector-example1/src/main/resources/jndi.properties index 65fc26e536..9c96675b88 100644 --- a/examples/jms/topic-selector-example1/src/main/resources/jndi.properties +++ b/examples/jms/topic-selector-example1/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 topic.topic/exampleTopic=exampleTopic diff --git a/examples/jms/topic-selector-example2/src/main/resources/jndi.properties b/examples/jms/topic-selector-example2/src/main/resources/jndi.properties index 65fc26e536..9c96675b88 100644 --- a/examples/jms/topic-selector-example2/src/main/resources/jndi.properties +++ b/examples/jms/topic-selector-example2/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 topic.topic/exampleTopic=exampleTopic diff --git a/examples/jms/topic/src/main/resources/jndi.properties b/examples/jms/topic/src/main/resources/jndi.properties index 65fc26e536..9c96675b88 100644 --- a/examples/jms/topic/src/main/resources/jndi.properties +++ b/examples/jms/topic/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 topic.topic/exampleTopic=exampleTopic diff --git a/examples/jms/transaction-failover/src/main/resources/jndi.properties b/examples/jms/transaction-failover/src/main/resources/jndi.properties index 99e6a96118..8f3fcff6d4 100644 --- a/examples/jms/transaction-failover/src/main/resources/jndi.properties +++ b/examples/jms/transaction-failover/src/main/resources/jndi.properties @@ -16,9 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -connection.ConnectionFactory.ha=true -connection.ConnectionFactory.retryInterval=1000 -connection.ConnectionFactory.retryIntervalMultiplier=1.0 -connection.ConnectionFactory.reconnectAttempts=-1 +connectionFactory.ConnectionFactory=tcp://localhost:5445?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/transactional/src/main/resources/jndi.properties b/examples/jms/transactional/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/transactional/src/main/resources/jndi.properties +++ b/examples/jms/transactional/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/xa-heuristic/src/main/resources/jndi.properties b/examples/jms/xa-heuristic/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/xa-heuristic/src/main/resources/jndi.properties +++ b/examples/jms/xa-heuristic/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/xa-receive/src/main/resources/jndi.properties b/examples/jms/xa-receive/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/xa-receive/src/main/resources/jndi.properties +++ b/examples/jms/xa-receive/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/jms/xa-send/src/main/resources/jndi.properties b/examples/jms/xa-send/src/main/resources/jndi.properties index 6364ce46d9..85eda3dd51 100644 --- a/examples/jms/xa-send/src/main/resources/jndi.properties +++ b/examples/jms/xa-send/src/main/resources/jndi.properties @@ -16,5 +16,5 @@ # under the License. java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 +connectionFactory.ConnectionFactory=tcp://localhost:5445 queue.queue/exampleQueue=exampleQueue diff --git a/examples/soak/normal/src/main/java/org/apache/activemq/jms/soak/example/SoakReceiver.java b/examples/soak/normal/src/main/java/org/apache/activemq/jms/soak/example/SoakReceiver.java index bc890b8569..3f6b5308cd 100644 --- a/examples/soak/normal/src/main/java/org/apache/activemq/jms/soak/example/SoakReceiver.java +++ b/examples/soak/normal/src/main/java/org/apache/activemq/jms/soak/example/SoakReceiver.java @@ -64,7 +64,7 @@ public class SoakReceiver SoakParams params = SoakBase.getParams(fileName); Hashtable jndiProps = new Hashtable(); - jndiProps.put("java.naming.provider.url", jndiURL); + jndiProps.put("connectionFactory.ConnectionFactory", jndiURL); jndiProps.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); final SoakReceiver receiver = new SoakReceiver(jndiProps, params); diff --git a/examples/soak/normal/src/main/java/org/apache/activemq/jms/soak/example/SoakSender.java b/examples/soak/normal/src/main/java/org/apache/activemq/jms/soak/example/SoakSender.java index 360f88f39b..1b9e7f4ef5 100644 --- a/examples/soak/normal/src/main/java/org/apache/activemq/jms/soak/example/SoakSender.java +++ b/examples/soak/normal/src/main/java/org/apache/activemq/jms/soak/example/SoakSender.java @@ -55,7 +55,7 @@ public class SoakSender SoakParams params = SoakBase.getParams(fileName); Hashtable jndiProps = new Hashtable(); - jndiProps.put("java.naming.provider.url", jndiURL); + jndiProps.put("connectionFactory.ConnectionFactory", jndiURL); jndiProps.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); final SoakSender sender = new SoakSender(jndiProps, params); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/client/ServerLocatorSerializationTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/client/ServerLocatorSerializationTest.java deleted file mode 100644 index 4a4ca0e950..0000000000 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/client/ServerLocatorSerializationTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.tests.integration.client; -import org.junit.Before; -import org.junit.After; - -import org.junit.Test; - -import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.client.ClientSession; -import org.apache.activemq.api.core.client.ClientSessionFactory; -import org.apache.activemq.api.core.client.ActiveMQClient; -import org.apache.activemq.api.core.client.ServerLocator; -import org.apache.activemq.api.jms.ActiveMQJMSClient; -import org.apache.activemq.api.jms.JMSFactoryType; -import org.apache.activemq.core.client.impl.ServerLocatorImpl; -import org.apache.activemq.core.config.Configuration; -import org.apache.activemq.core.server.ActiveMQServer; -import org.apache.activemq.jms.client.ActiveMQConnectionFactory; -import org.apache.activemq.tests.integration.IntegrationTestLogger; -import org.apache.activemq.tests.util.ServiceTestBase; - -import javax.jms.Connection; -import javax.jms.Session; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - -public class ServerLocatorSerializationTest extends ServiceTestBase -{ - private ActiveMQServer server; - private static final IntegrationTestLogger log = IntegrationTestLogger.LOGGER; - - @Override - @Before - public void setUp() throws Exception - { - super.setUp(); - Configuration configuration = createDefaultConfig(isNetty()); - server = createServer(false, configuration); - server.start(); - } - - @Override - @After - public void tearDown() throws Exception - { - server.stop(); - super.tearDown(); - } - - @Test - public void testLocatorSerialization() throws Exception - { - log.info("Starting Netty locator"); - ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false, generateParams(0, isNetty()))); - - ClientSessionFactory csf = createSessionFactory(locator); - ClientSession session = csf.createSession(false, false); - session.close(); - csf.close(); - - log.info("Serializing locator"); - ServerLocatorImpl locatorImpl = (ServerLocatorImpl) locator; - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(bos); - out.writeObject(locatorImpl); - - log.info("De-serializing locator"); - ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bis); - locatorImpl = (ServerLocatorImpl) in.readObject(); - - csf = createSessionFactory(locator); - session = csf.createSession(false, false); - session.close(); - csf.close(); - - locator.close(); - locatorImpl.close(); - } - - @Test - public void testConnectionFactorySerialization() throws Exception - { - log.info("Starting connection factory"); - ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration("org.apache.activemq.core.remoting.impl.netty.NettyConnectorFactory")); - - Connection connection = cf.createConnection(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - session.close(); - connection.close(); - - log.info("Serializing connection factory"); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(bos); - out.writeObject(cf); - - log.info("De-serializing connection factory"); - ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bis); - cf = (ActiveMQConnectionFactory) in.readObject(); - - connection = cf.createConnection(); - session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - session.close(); - connection.close(); - - cf.close(); - } - - public boolean isNetty() - { - return true; - } -} diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/client/SessionFactoryTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/client/SessionFactoryTest.java index 3779a3a99f..73f8f11445 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/client/SessionFactoryTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/client/SessionFactoryTest.java @@ -16,10 +16,6 @@ */ package org.apache.activemq.tests.integration.client; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -27,7 +23,7 @@ import java.util.List; import org.apache.activemq.api.core.BroadcastGroupConfiguration; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.core.client.ClientSession; import org.apache.activemq.api.core.client.ClientSessionFactory; import org.apache.activemq.api.core.client.ActiveMQClient; @@ -52,9 +48,9 @@ import org.junit.Test; public class SessionFactoryTest extends ServiceTestBase { private final DiscoveryGroupConfiguration groupConfiguration = new DiscoveryGroupConfiguration() - .setBroadcastEndpointFactoryConfiguration(new UDPBroadcastGroupConfiguration() - .setGroupAddress(getUDPDiscoveryAddress()) - .setGroupPort(getUDPDiscoveryPort())); + .setBroadcastEndpointFactory(new UDPBroadcastEndpointFactory() + .setGroupAddress(getUDPDiscoveryAddress()) + .setGroupPort(getUDPDiscoveryPort())); private ActiveMQServer liveService; @@ -69,34 +65,6 @@ public class SessionFactoryTest extends ServiceTestBase startServer(); } - @Test - public void testSerializable() throws Exception - { - ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(InVMConnectorFactory.class.getName())); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - ObjectOutputStream oos = new ObjectOutputStream(baos); - - oos.writeObject(locator); - - oos.close(); - - byte[] bytes = baos.toByteArray(); - - ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - - ObjectInputStream ois = new ObjectInputStream(bais); - - ServerLocator csi = (ServerLocator) ois.readObject(); - - Assert.assertNotNull(csi); - - csi.close(); - - locator.close(); - } - @Test public void testCloseUnusedClientSessionFactoryWithoutGlobalPools() throws Exception { @@ -576,10 +544,10 @@ public class SessionFactoryTest extends ServiceTestBase .setName(bcGroupName) .setBroadcastPeriod(broadcastPeriod) .setConnectorInfos(Arrays.asList(liveTC.getName())) - .setEndpointFactoryConfiguration(new UDPBroadcastGroupConfiguration() - .setGroupAddress(getUDPDiscoveryAddress()) - .setGroupPort(getUDPDiscoveryPort()) - .setLocalBindPort(localBindPort)); + .setEndpointFactory(new UDPBroadcastEndpointFactory() + .setGroupAddress(getUDPDiscoveryAddress()) + .setGroupPort(getUDPDiscoveryPort()) + .setLocalBindPort(localBindPort)); List bcConfigs1 = new ArrayList(); bcConfigs1.add(bcConfig1); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/cluster/bridge/BridgeWithDiscoveryGroupStartTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/cluster/bridge/BridgeWithDiscoveryGroupStartTest.java index fad41188ba..6ab2816b24 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/cluster/bridge/BridgeWithDiscoveryGroupStartTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/cluster/bridge/BridgeWithDiscoveryGroupStartTest.java @@ -27,7 +27,7 @@ import org.apache.activemq.api.core.BroadcastGroupConfiguration; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.api.core.SimpleString; import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.core.client.ClientConsumer; import org.apache.activemq.api.core.client.ClientMessage; import org.apache.activemq.api.core.client.ClientProducer; @@ -121,13 +121,13 @@ public class BridgeWithDiscoveryGroupStartTest extends ServiceTestBase ArrayList list = new ArrayList(); list.add(server1tc.getName()); - UDPBroadcastGroupConfiguration endpoint = new UDPBroadcastGroupConfiguration().setGroupAddress(groupAddress).setGroupPort(port); + UDPBroadcastEndpointFactory endpoint = new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress).setGroupPort(port); BroadcastGroupConfiguration bcConfig = new BroadcastGroupConfiguration() .setName("bg1") .setBroadcastPeriod(250) .setConnectorInfos(list) - .setEndpointFactoryConfiguration(endpoint); + .setEndpointFactory(endpoint); server0.getConfiguration().getBroadcastGroupConfigurations().add(bcConfig); @@ -135,7 +135,7 @@ public class BridgeWithDiscoveryGroupStartTest extends ServiceTestBase .setName("dg1") .setRefreshTimeout(5000) .setDiscoveryInitialWaitTimeout(5000) - .setBroadcastEndpointFactoryConfiguration(endpoint); + .setBroadcastEndpointFactory(endpoint); server0.getConfiguration().getDiscoveryGroupConfigurations().put(dcConfig.getName(), dcConfig); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/cluster/distribution/ClusterTestBase.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/cluster/distribution/ClusterTestBase.java index 7370f33c67..212c7e79b6 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/cluster/distribution/ClusterTestBase.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/cluster/distribution/ClusterTestBase.java @@ -38,7 +38,7 @@ import org.apache.activemq.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.api.core.Message; import org.apache.activemq.api.core.SimpleString; import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.core.client.ClientConsumer; import org.apache.activemq.api.core.client.ClientMessage; import org.apache.activemq.api.core.client.ClientProducer; @@ -1787,19 +1787,19 @@ public abstract class ClusterTestBase extends ServiceTestBase List connectorPairs = new ArrayList(); connectorPairs.add(connector.getName()); - UDPBroadcastGroupConfiguration endpoint = new UDPBroadcastGroupConfiguration().setGroupAddress(groupAddress).setGroupPort(port); + UDPBroadcastEndpointFactory endpoint = new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress).setGroupPort(port); BroadcastGroupConfiguration bcConfig = new BroadcastGroupConfiguration() .setName("bg1") .setBroadcastPeriod(200) .setConnectorInfos(connectorPairs) - .setEndpointFactoryConfiguration(endpoint); + .setEndpointFactory(endpoint); DiscoveryGroupConfiguration dcConfig = new DiscoveryGroupConfiguration() .setName("dg1") .setRefreshTimeout(1000) .setDiscoveryInitialWaitTimeout(1000) - .setBroadcastEndpointFactoryConfiguration(endpoint); + .setBroadcastEndpointFactory(endpoint); Configuration configuration = createBasicConfig(node) .setJournalMaxIO_AIO(1000) @@ -1858,19 +1858,19 @@ public abstract class ClusterTestBase extends ServiceTestBase List connectorPairs = new ArrayList(); connectorPairs.add(connector.getName()); - UDPBroadcastGroupConfiguration endpoint = new UDPBroadcastGroupConfiguration().setGroupAddress(groupAddress).setGroupPort(port); + UDPBroadcastEndpointFactory endpoint = new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress).setGroupPort(port); BroadcastGroupConfiguration bcConfig = new BroadcastGroupConfiguration() .setName("bg1") .setBroadcastPeriod(1000) .setConnectorInfos(connectorPairs) - .setEndpointFactoryConfiguration(endpoint); + .setEndpointFactory(endpoint); DiscoveryGroupConfiguration dcConfig = new DiscoveryGroupConfiguration() .setName("dg1") .setRefreshTimeout(5000) .setDiscoveryInitialWaitTimeout(5000) - .setBroadcastEndpointFactoryConfiguration(endpoint); + .setBroadcastEndpointFactory(endpoint); Configuration configuration = createBasicConfig(sharedStorage ? liveNode : node) .clearAcceptorConfigurations() diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/cluster/topology/HAClientTopologyWithDiscoveryTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/cluster/topology/HAClientTopologyWithDiscoveryTest.java index 6ca28bc573..550f9fa6be 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/cluster/topology/HAClientTopologyWithDiscoveryTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/cluster/topology/HAClientTopologyWithDiscoveryTest.java @@ -17,7 +17,7 @@ package org.apache.activemq.tests.integration.cluster.topology; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.core.client.ActiveMQClient; import org.apache.activemq.api.core.client.ServerLocator; @@ -65,9 +65,9 @@ public class HAClientTopologyWithDiscoveryTest extends TopologyClusterTestBase protected ServerLocator createHAServerLocator() { ServerLocator locator = ActiveMQClient.createServerLocatorWithHA(new DiscoveryGroupConfiguration() - .setBroadcastEndpointFactoryConfiguration(new UDPBroadcastGroupConfiguration() - .setGroupAddress(groupAddress) - .setGroupPort(groupPort))); + .setBroadcastEndpointFactory(new UDPBroadcastEndpointFactory() + .setGroupAddress(groupAddress) + .setGroupPort(groupPort))); locator.setBlockOnNonDurableSend(true); locator.setBlockOnDurableSend(true); addServerLocator(locator); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/discovery/DiscoveryBaseTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/discovery/DiscoveryBaseTest.java index 473bda3ea9..76ccce65c1 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/discovery/DiscoveryBaseTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/discovery/DiscoveryBaseTest.java @@ -26,7 +26,7 @@ import java.util.Map; import org.apache.activemq.api.core.SimpleString; import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.core.cluster.DiscoveryEntry; import org.apache.activemq.core.cluster.DiscoveryGroup; import org.apache.activemq.core.cluster.DiscoveryListener; @@ -169,12 +169,11 @@ public class DiscoveryBaseTest extends UnitTestCase final InetAddress groupAddress, final int groupPort) throws Exception { - return new BroadcastGroupImpl(new FakeNodeManager(nodeID), name, 0, null, new UDPBroadcastGroupConfiguration() + return new BroadcastGroupImpl(new FakeNodeManager(nodeID), name, 0, null, new UDPBroadcastEndpointFactory() .setGroupAddress(groupAddress.getHostAddress()) .setGroupPort(groupPort) .setLocalBindAddress(localAddress != null ? localAddress.getHostAddress() : null) - .setLocalBindPort(localPort) - .createBroadcastEndpointFactory()); + .setLocalBindPort(localPort)); } protected DiscoveryGroup newDiscoveryGroup(final String nodeID, final String name, final InetAddress localBindAddress, @@ -186,11 +185,10 @@ public class DiscoveryBaseTest extends UnitTestCase protected DiscoveryGroup newDiscoveryGroup(final String nodeID, final String name, final InetAddress localBindAddress, final InetAddress groupAddress, final int groupPort, final long timeout, NotificationService notif) throws Exception { - return new DiscoveryGroup(nodeID, name, timeout, new UDPBroadcastGroupConfiguration() + return new DiscoveryGroup(nodeID, name, timeout, new UDPBroadcastEndpointFactory() .setGroupAddress(groupAddress.getHostAddress()) .setGroupPort(groupPort) - .setLocalBindAddress(localBindAddress != null ? localBindAddress.getHostAddress() : null) - .createBroadcastEndpointFactory(), notif); + .setLocalBindAddress(localBindAddress != null ? localBindAddress.getHostAddress() : null), notif); } protected final class FakeNodeManager extends NodeManager diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/discovery/DiscoveryStayAliveTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/discovery/DiscoveryStayAliveTest.java index cd86f0e6c1..dbf5a44faa 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/discovery/DiscoveryStayAliveTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/discovery/DiscoveryStayAliveTest.java @@ -25,7 +25,7 @@ import org.apache.activemq.api.core.ActiveMQBuffer; import org.apache.activemq.api.core.ActiveMQBuffers; import org.apache.activemq.api.core.BroadcastEndpoint; import org.apache.activemq.api.core.BroadcastEndpointFactory; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.core.cluster.DiscoveryGroup; import org.apache.activemq.core.server.cluster.impl.BroadcastGroupImpl; import org.apache.activemq.tests.util.RandomUtil; @@ -99,8 +99,8 @@ public class DiscoveryStayAliveTest extends DiscoveryBaseTest BroadcastGroupImpl bg = new BroadcastGroupImpl(new FakeNodeManager("test-nodeID"), RandomUtil.randomString(), - 1, scheduledExecutorService, new UDPBroadcastGroupConfiguration().setGroupAddress(address1). - setGroupPort(groupPort).createBroadcastEndpointFactory()); + 1, scheduledExecutorService, new UDPBroadcastEndpointFactory().setGroupAddress(address1). + setGroupPort(groupPort)); bg.start(); @@ -109,8 +109,8 @@ public class DiscoveryStayAliveTest extends DiscoveryBaseTest for (int i = 0; i < 10; i++) { - BroadcastEndpointFactory factoryEndpoint = new UDPBroadcastGroupConfiguration().setGroupAddress(address1). - setGroupPort(groupPort).createBroadcastEndpointFactory(); + BroadcastEndpointFactory factoryEndpoint = new UDPBroadcastEndpointFactory().setGroupAddress(address1). + setGroupPort(groupPort); sendBadData(factoryEndpoint); Thread.sleep(100); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/discovery/DiscoveryTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/discovery/DiscoveryTest.java index 24ee708eea..6078eca889 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/discovery/DiscoveryTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/discovery/DiscoveryTest.java @@ -16,11 +16,7 @@ */ package org.apache.activemq.tests.integration.discovery; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Arrays; @@ -30,10 +26,10 @@ import java.util.concurrent.TimeUnit; import org.apache.activemq.api.core.BroadcastEndpoint; import org.apache.activemq.api.core.BroadcastEndpointFactory; -import org.apache.activemq.api.core.JGroupsBroadcastGroupConfiguration; +import org.apache.activemq.api.core.JGroupsFileBroadcastEndpointFactory; import org.apache.activemq.api.core.SimpleString; import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.core.management.CoreNotificationType; import org.apache.activemq.core.cluster.DiscoveryEntry; import org.apache.activemq.core.cluster.DiscoveryGroup; @@ -102,7 +98,7 @@ public class DiscoveryTest extends DiscoveryBaseTest bg = new BroadcastGroupImpl(new FakeNodeManager(nodeID), RandomUtil.randomString(), - 0, null, new UDPBroadcastGroupConfiguration().setGroupAddress(address1).setGroupPort(groupPort).createBroadcastEndpointFactory()); + 0, null, new UDPBroadcastEndpointFactory().setGroupAddress(address1).setGroupPort(groupPort)); bg.start(); @@ -132,7 +128,9 @@ public class DiscoveryTest extends DiscoveryBaseTest final String nodeID = RandomUtil.randomString(); bg = new BroadcastGroupImpl(new FakeNodeManager(nodeID), "broadcast", 100, null, - new JGroupsBroadcastGroupConfiguration(TEST_JGROUPS_CONF_FILE, "tst").createBroadcastEndpointFactory()); + new JGroupsFileBroadcastEndpointFactory() + .setChannelName("tst") + .setFile(TEST_JGROUPS_CONF_FILE)); bg.start(); @@ -141,7 +139,9 @@ public class DiscoveryTest extends DiscoveryBaseTest bg.addConnector(live1); dg = new DiscoveryGroup(nodeID + "1", "broadcast", 5000L, - new JGroupsBroadcastGroupConfiguration(TEST_JGROUPS_CONF_FILE, "tst").createBroadcastEndpointFactory(), + new JGroupsFileBroadcastEndpointFactory() + .setChannelName("tst") + .setFile(TEST_JGROUPS_CONF_FILE), null); dg.start(); @@ -160,9 +160,9 @@ public class DiscoveryTest extends DiscoveryBaseTest @Test public void testJGropusChannelReferenceCounting() throws Exception { - JGroupsBroadcastGroupConfiguration jgroupsConfig = - new JGroupsBroadcastGroupConfiguration(TEST_JGROUPS_CONF_FILE, "tst"); - BroadcastEndpointFactory factory = jgroupsConfig.createBroadcastEndpointFactory(); + BroadcastEndpointFactory factory = new JGroupsFileBroadcastEndpointFactory() + .setChannelName("tst") + .setFile(TEST_JGROUPS_CONF_FILE); BroadcastEndpoint broadcaster = factory.createBroadcastEndpoint(); broadcaster.openBroadcaster(); @@ -222,9 +222,9 @@ public class DiscoveryTest extends DiscoveryBaseTest @Test public void testJGropusChannelReferenceCounting1() throws Exception { - JGroupsBroadcastGroupConfiguration jgroupsConfig = - new JGroupsBroadcastGroupConfiguration(TEST_JGROUPS_CONF_FILE, "tst"); - BroadcastEndpointFactory factory = jgroupsConfig.createBroadcastEndpointFactory(); + BroadcastEndpointFactory factory = new JGroupsFileBroadcastEndpointFactory() + .setChannelName("tst") + .setFile(TEST_JGROUPS_CONF_FILE); BroadcastEndpoint broadcaster = factory.createBroadcastEndpoint(); broadcaster.openBroadcaster(); @@ -293,9 +293,9 @@ public class DiscoveryTest extends DiscoveryBaseTest @Test public void testJGropusChannelReferenceCounting2() throws Exception { - JGroupsBroadcastGroupConfiguration jgroupsConfig = - new JGroupsBroadcastGroupConfiguration(TEST_JGROUPS_CONF_FILE, "tst"); - BroadcastEndpointFactory factory = jgroupsConfig.createBroadcastEndpointFactory(); + BroadcastEndpointFactory factory = new JGroupsFileBroadcastEndpointFactory() + .setChannelName("tst") + .setFile(TEST_JGROUPS_CONF_FILE); BroadcastEndpoint broadcaster = factory.createBroadcastEndpoint(); broadcaster.openBroadcaster(); @@ -374,13 +374,14 @@ public class DiscoveryTest extends DiscoveryBaseTest BroadcastEndpoint client = null; try { - JGroupsBroadcastGroupConfiguration jgroupsConfig = - new JGroupsBroadcastGroupConfiguration(TEST_JGROUPS_CONF_FILE, "tst"); - broadcaster = jgroupsConfig.createBroadcastEndpointFactory().createBroadcastEndpoint(); + JGroupsFileBroadcastEndpointFactory endpointFactory = new JGroupsFileBroadcastEndpointFactory() + .setChannelName("tst") + .setFile(TEST_JGROUPS_CONF_FILE); + broadcaster = endpointFactory.createBroadcastEndpoint(); broadcaster.openBroadcaster(); - client = jgroupsConfig.createBroadcastEndpointFactory().createBroadcastEndpoint(); + client = endpointFactory.createBroadcastEndpoint(); client.openClient(); @@ -1180,26 +1181,4 @@ public class DiscoveryTest extends DiscoveryBaseTest .getSimpleStringProperty(new SimpleString("name")) .toString()); } - - /** - * https://issues.jboss.org/browse/HORNETQ-1389 - * @throws Exception - */ - @Test - public void testJGroupsBroadcastGroupConfigurationSerializable() throws Exception - { - JGroupsBroadcastGroupConfiguration jgroupsConfig = - new JGroupsBroadcastGroupConfiguration(TEST_JGROUPS_CONF_FILE, "somChannel"); - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - ObjectOutputStream objectOut = new ObjectOutputStream(byteOut); - objectOut.writeObject(jgroupsConfig); - - byte[] serializedData = byteOut.toByteArray(); - ByteArrayInputStream byteIn = new ByteArrayInputStream(serializedData); - ObjectInputStream objectIn = new ObjectInputStream(byteIn); - - Object object = objectIn.readObject(); - assertNotNull(object); - assertTrue(object instanceof JGroupsBroadcastGroupConfiguration); - } } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/ActiveMQConnectionFactoryTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/ActiveMQConnectionFactoryTest.java index 6aace2bf66..ba40718a58 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/ActiveMQConnectionFactoryTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/ActiveMQConnectionFactoryTest.java @@ -34,7 +34,7 @@ import org.junit.Assert; import org.apache.activemq.api.core.BroadcastGroupConfiguration; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.core.client.ActiveMQClient; import org.apache.activemq.api.jms.ActiveMQJMSClient; import org.apache.activemq.api.jms.JMSFactoryType; @@ -169,9 +169,9 @@ public class ActiveMQConnectionFactoryTest extends UnitTestCase public void testDiscoveryConstructor() throws Exception { DiscoveryGroupConfiguration groupConfiguration = new DiscoveryGroupConfiguration() - .setBroadcastEndpointFactoryConfiguration(new UDPBroadcastGroupConfiguration() - .setGroupAddress(groupAddress) - .setGroupPort(groupPort)); + .setBroadcastEndpointFactory(new UDPBroadcastEndpointFactory() + .setGroupAddress(groupAddress) + .setGroupPort(groupPort)); ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(groupConfiguration, JMSFactoryType.CF); assertFactoryParams(cf, null, @@ -734,10 +734,10 @@ public class ActiveMQConnectionFactoryTest extends UnitTestCase .setName(bcGroupName) .setBroadcastPeriod(broadcastPeriod) .setConnectorInfos(connectorNames) - .setEndpointFactoryConfiguration(new UDPBroadcastGroupConfiguration() - .setGroupAddress(groupAddress) - .setGroupPort(groupPort) - .setLocalBindPort(localBindPort)); + .setEndpointFactory(new UDPBroadcastEndpointFactory() + .setGroupAddress(groupAddress) + .setGroupPort(groupPort) + .setLocalBindPort(localBindPort)); List bcConfigs1 = new ArrayList(); bcConfigs1.add(bcConfig1); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/SimpleJNDIClientTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/SimpleJNDIClientTest.java index 9c48cc70b9..22edf72f6d 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/SimpleJNDIClientTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/SimpleJNDIClientTest.java @@ -31,10 +31,14 @@ import java.util.List; import java.util.Map; import org.apache.activemq.api.config.ActiveMQDefaultConfiguration; +import org.apache.activemq.api.core.BroadcastEndpoint; +import org.apache.activemq.api.core.BroadcastEndpointFactory; import org.apache.activemq.api.core.BroadcastGroupConfiguration; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; +import org.apache.activemq.api.core.JGroupsFileBroadcastEndpoint; +import org.apache.activemq.api.core.JGroupsPropertiesBroadcastEndpointFactory; import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.jms.JMSFactoryType; import org.apache.activemq.core.config.Configuration; import org.apache.activemq.core.config.ha.SharedStoreMasterPolicyConfiguration; @@ -43,7 +47,6 @@ import org.apache.activemq.core.server.ActiveMQServer; import org.apache.activemq.core.server.ActiveMQServers; import org.apache.activemq.jms.client.ActiveMQConnectionFactory; import org.apache.activemq.jndi.ActiveMQInitialContextFactory; -import org.apache.activemq.tests.util.RandomUtil; import org.apache.activemq.tests.util.UnitTestCase; import org.junit.Assert; import org.junit.Before; @@ -68,43 +71,19 @@ public class SimpleJNDIClientTest extends UnitTestCase private TransportConfiguration liveTC; @Test - public void testDefaultConnectionFactories() throws NamingException, JMSException + public void testMultipleConnectionFactories() throws NamingException, JMSException { Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); + props.put("connectionFactory.VmConnectionFactory", "vm://0"); + props.put("connectionFactory.TCPConnectionFactory", "tcp://localhost:5445"); + props.put("connectionFactory.UDPConnectionFactory", "udp://" + getUDPDiscoveryAddress() + ":" + getUDPDiscoveryPort()); + props.put("connectionFactory.JGroupsConnectionFactory", "jgroups://mychannelid?file=test-jgroups-file_ping.xml"); Context ctx = new InitialContext(props); - - ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("ConnectionFactory"); - Assert.assertEquals(JMSFactoryType.CF.intValue(), ((ActiveMQConnectionFactory)connectionFactory).getFactoryType()); - connectionFactory.createConnection().close(); - - connectionFactory = (ConnectionFactory) ctx.lookup("XAConnectionFactory"); - Assert.assertEquals(JMSFactoryType.XA_CF.intValue(), ((ActiveMQConnectionFactory)connectionFactory).getFactoryType()); - connectionFactory.createConnection().close(); - - connectionFactory = (ConnectionFactory) ctx.lookup("TopicConnectionFactory"); - Assert.assertEquals(JMSFactoryType.TOPIC_CF.intValue(), ((ActiveMQConnectionFactory)connectionFactory).getFactoryType()); - connectionFactory.createConnection().close(); - - connectionFactory = (ConnectionFactory) ctx.lookup("QueueConnectionFactory"); - Assert.assertEquals(JMSFactoryType.QUEUE_CF.intValue(), ((ActiveMQConnectionFactory)connectionFactory).getFactoryType()); - connectionFactory.createConnection().close(); - } - - @Test - public void testCustomCF() throws NamingException, JMSException - { - Hashtable props = new Hashtable<>(); - props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, "myConnectionFactory"); - props.put("connection.myConnectionFactory.type", "CF"); - Context ctx = new InitialContext(props); - - ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("myConnectionFactory"); - - Assert.assertEquals(JMSFactoryType.CF.intValue(), ((ActiveMQConnectionFactory)connectionFactory).getFactoryType()); - - connectionFactory.createConnection().close(); + ctx.lookup("VmConnectionFactory"); + ctx.lookup("TCPConnectionFactory"); + ctx.lookup("UDPConnectionFactory"); + ctx.lookup("JGroupsConnectionFactory"); } @Test @@ -112,7 +91,7 @@ public class SimpleJNDIClientTest extends UnitTestCase { Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(Context.PROVIDER_URL, "vm://0"); + props.put("connectionFactory.ConnectionFactory", "vm://0"); Context ctx = new InitialContext(props); ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("ConnectionFactory"); @@ -125,7 +104,7 @@ public class SimpleJNDIClientTest extends UnitTestCase { Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(Context.PROVIDER_URL, "vm://1"); + props.put("connectionFactory.ConnectionFactory", "vm://1"); Context ctx = new InitialContext(props); ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("ConnectionFactory"); @@ -138,8 +117,7 @@ public class SimpleJNDIClientTest extends UnitTestCase { Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, "myConnectionFactory"); - props.put("connection.myConnectionFactory.type", "XA_CF"); + props.put("connectionFactory.myConnectionFactory", "vm://0?type=XA_CF"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); @@ -152,8 +130,7 @@ public class SimpleJNDIClientTest extends UnitTestCase { Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, "myConnectionFactory"); - props.put("connection.myConnectionFactory.type", "QUEUE_CF"); + props.put("connectionFactory.myConnectionFactory", "vm://0?type=QUEUE_CF"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); @@ -166,8 +143,7 @@ public class SimpleJNDIClientTest extends UnitTestCase { Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, "myConnectionFactory"); - props.put("connection.myConnectionFactory.type", "QUEUE_XA_CF"); + props.put("connectionFactory.myConnectionFactory", "vm://0?type=QUEUE_XA_CF"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); @@ -180,8 +156,7 @@ public class SimpleJNDIClientTest extends UnitTestCase { Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, "myConnectionFactory"); - props.put("connection.myConnectionFactory.type", "TOPIC_CF"); + props.put("connectionFactory.myConnectionFactory", "vm://0?type=TOPIC_CF"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); @@ -194,8 +169,7 @@ public class SimpleJNDIClientTest extends UnitTestCase { Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, "myConnectionFactory"); - props.put("connection.myConnectionFactory.type", "TOPIC_XA_CF"); + props.put("connectionFactory.myConnectionFactory", "vm://0?type=TOPIC_XA_CF"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); @@ -203,237 +177,12 @@ public class SimpleJNDIClientTest extends UnitTestCase Assert.assertEquals(JMSFactoryType.TOPIC_XA_CF.intValue(), connectionFactory.getFactoryType()); } - @Test - public void testCFWithProperties() throws NamingException, JMSException - { - // we don't test the 'ha' property here because it's not supported on a local connection factory (i.e. one - // constructed from an InitialContext where the environment doesn't contain the property "java.naming.provider.url") - - long callFailoverTimeout = RandomUtil.randomPositiveLong(); - long callTimeout = RandomUtil.randomPositiveLong(); - long clientFailureCheckPeriod = RandomUtil.randomPositiveLong(); - String clientID = RandomUtil.randomString(); - int confirmationWindowSize = RandomUtil.randomPositiveInt(); - String connectionLoadBalancingPolicyClassName = RandomUtil.randomString(); - long connectionTTL = RandomUtil.randomPositiveLong(); - int consumerMaxRate = RandomUtil.randomPositiveInt(); - int consumerWindowSize = RandomUtil.randomPositiveInt(); - int minLargeMessageSize = RandomUtil.randomPositiveInt(); - int dupsOKBatchSize = RandomUtil.randomPositiveInt(); - String groupID = RandomUtil.randomString(); - int initialConnectAttempts = RandomUtil.randomPositiveInt(); - int initialMessagePacketSize = RandomUtil.randomPositiveInt(); - long maxRetryInterval = RandomUtil.randomPositiveLong(); - int producerMaxRate = RandomUtil.randomPositiveInt(); - int producerWindowSize = RandomUtil.randomPositiveInt(); - int reconnectAttempts = RandomUtil.randomPositiveInt(); - long retryInterval = RandomUtil.randomPositiveLong(); - double retryIntervalMultiplier = RandomUtil.randomDouble(); - int scheduledThreadPoolMaxSize = RandomUtil.randomPositiveInt(); - int threadPoolMaxSize = RandomUtil.randomPositiveInt(); - int transactionBatchSize = RandomUtil.randomPositiveInt(); - boolean autoGroup = RandomUtil.randomBoolean(); - boolean blockOnAcknowledge = RandomUtil.randomBoolean(); - boolean blockOnDurableSend = RandomUtil.randomBoolean(); - boolean blockOnNonDurableSend = RandomUtil.randomBoolean(); - boolean cacheLargeMessagesClient = RandomUtil.randomBoolean(); - boolean compressLargeMessage = RandomUtil.randomBoolean(); - boolean failoverOnInitialConnection = RandomUtil.randomBoolean(); - boolean preAcknowledge = RandomUtil.randomBoolean(); - boolean useGlobalPools = RandomUtil.randomBoolean(); - - Hashtable props = new Hashtable<>(); - props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, "myConnectionFactory"); - props.put("connection.myConnectionFactory.callFailoverTimeout", callFailoverTimeout); - props.put("connection.myConnectionFactory.callTimeout", callTimeout); - props.put("connection.myConnectionFactory.clientFailureCheckPeriod", clientFailureCheckPeriod); - props.put("connection.myConnectionFactory.clientID", clientID); - props.put("connection.myConnectionFactory.confirmationWindowSize", confirmationWindowSize); - props.put("connection.myConnectionFactory.connectionLoadBalancingPolicyClassName", connectionLoadBalancingPolicyClassName); - props.put("connection.myConnectionFactory.connectionTTL", connectionTTL); - props.put("connection.myConnectionFactory.consumerMaxRate", consumerMaxRate); - props.put("connection.myConnectionFactory.consumerWindowSize", consumerWindowSize); - props.put("connection.myConnectionFactory.minLargeMessageSize", minLargeMessageSize); - props.put("connection.myConnectionFactory.dupsOKBatchSize", dupsOKBatchSize); - props.put("connection.myConnectionFactory.groupID", groupID); - props.put("connection.myConnectionFactory.initialConnectAttempts", initialConnectAttempts); - props.put("connection.myConnectionFactory.initialMessagePacketSize", initialMessagePacketSize); - props.put("connection.myConnectionFactory.maxRetryInterval", maxRetryInterval); - props.put("connection.myConnectionFactory.producerMaxRate", producerMaxRate); - props.put("connection.myConnectionFactory.producerWindowSize", producerWindowSize); - props.put("connection.myConnectionFactory.reconnectAttempts", reconnectAttempts); - props.put("connection.myConnectionFactory.retryInterval", retryInterval); - props.put("connection.myConnectionFactory.retryIntervalMultiplier", retryIntervalMultiplier); - props.put("connection.myConnectionFactory.scheduledThreadPoolMaxSize", scheduledThreadPoolMaxSize); - props.put("connection.myConnectionFactory.threadPoolMaxSize", threadPoolMaxSize); - props.put("connection.myConnectionFactory.transactionBatchSize", transactionBatchSize); - props.put("connection.myConnectionFactory.blockOnAcknowledge", blockOnAcknowledge); - props.put("connection.myConnectionFactory.blockOnDurableSend", blockOnDurableSend); - props.put("connection.myConnectionFactory.blockOnNonDurableSend", blockOnNonDurableSend); - props.put("connection.myConnectionFactory.cacheLargeMessagesClient", cacheLargeMessagesClient); - props.put("connection.myConnectionFactory.compressLargeMessage", compressLargeMessage); - props.put("connection.myConnectionFactory.failoverOnInitialConnection", failoverOnInitialConnection); - props.put("connection.myConnectionFactory.autoGroup", autoGroup); - props.put("connection.myConnectionFactory.preAcknowledge", preAcknowledge); - props.put("connection.myConnectionFactory.useGlobalPools", useGlobalPools); - Context ctx = new InitialContext(props); - - ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); - - Assert.assertEquals(callFailoverTimeout, cf.getCallFailoverTimeout()); - Assert.assertEquals(callTimeout, cf.getCallTimeout()); - Assert.assertEquals(clientFailureCheckPeriod, cf.getClientFailureCheckPeriod()); - Assert.assertEquals(clientID, cf.getClientID()); - Assert.assertEquals(confirmationWindowSize, cf.getConfirmationWindowSize()); - Assert.assertEquals(connectionLoadBalancingPolicyClassName, cf.getConnectionLoadBalancingPolicyClassName()); - Assert.assertEquals(connectionTTL, cf.getConnectionTTL()); - Assert.assertEquals(consumerMaxRate, cf.getConsumerMaxRate()); - Assert.assertEquals(consumerWindowSize, cf.getConsumerWindowSize()); - Assert.assertEquals(minLargeMessageSize, cf.getMinLargeMessageSize()); - Assert.assertEquals(dupsOKBatchSize, cf.getDupsOKBatchSize()); - Assert.assertEquals(groupID, cf.getGroupID()); - Assert.assertEquals(initialConnectAttempts, cf.getInitialConnectAttempts()); - Assert.assertEquals(initialMessagePacketSize, cf.getInitialMessagePacketSize()); - Assert.assertEquals(maxRetryInterval, cf.getMaxRetryInterval()); - Assert.assertEquals(producerMaxRate, cf.getProducerMaxRate()); - Assert.assertEquals(producerWindowSize, cf.getProducerWindowSize()); - Assert.assertEquals(reconnectAttempts, cf.getReconnectAttempts()); - Assert.assertEquals(retryInterval, cf.getRetryInterval()); - Assert.assertEquals(retryIntervalMultiplier, cf.getRetryIntervalMultiplier(), 0.0001); - Assert.assertEquals(scheduledThreadPoolMaxSize, cf.getScheduledThreadPoolMaxSize()); - Assert.assertEquals(threadPoolMaxSize, cf.getThreadPoolMaxSize()); - Assert.assertEquals(transactionBatchSize, cf.getTransactionBatchSize()); - Assert.assertEquals(autoGroup, cf.isAutoGroup()); - Assert.assertEquals(blockOnAcknowledge, cf.isBlockOnAcknowledge()); - Assert.assertEquals(blockOnDurableSend, cf.isBlockOnDurableSend()); - Assert.assertEquals(blockOnNonDurableSend, cf.isBlockOnNonDurableSend()); - Assert.assertEquals(cacheLargeMessagesClient, cf.isCacheLargeMessagesClient()); - Assert.assertEquals(compressLargeMessage, cf.isCompressLargeMessage()); - Assert.assertEquals(failoverOnInitialConnection, cf.isFailoverOnInitialConnection()); - Assert.assertEquals(preAcknowledge, cf.isPreAcknowledge()); - Assert.assertEquals(useGlobalPools, cf.isUseGlobalPools()); - } - - @Test - public void testCFWithStringProperties() throws NamingException, JMSException - { - // we don't test the 'ha' property here because it's not supported on a local connection factory (i.e. one - // constructed from an InitialContext where the environment doesn't contain the property "java.naming.provider.url") - - String callFailoverTimeout = Long.toString(RandomUtil.randomPositiveLong()); - String callTimeout = Long.toString(RandomUtil.randomPositiveLong()); - String clientFailureCheckPeriod = Long.toString(RandomUtil.randomPositiveLong()); - String clientID = RandomUtil.randomString(); - String confirmationWindowSize = Integer.toString(RandomUtil.randomPositiveInt()); - String connectionLoadBalancingPolicyClassName = RandomUtil.randomString(); - String connectionTTL = Long.toString(RandomUtil.randomPositiveLong()); - String consumerMaxRate = Integer.toString(RandomUtil.randomPositiveInt()); - String consumerWindowSize = Integer.toString(RandomUtil.randomPositiveInt()); - String minLargeMessageSize = Integer.toString(RandomUtil.randomPositiveInt()); - String dupsOKBatchSize = Integer.toString(RandomUtil.randomPositiveInt()); - String groupID = RandomUtil.randomString(); - String initialConnectAttempts = Integer.toString(RandomUtil.randomPositiveInt()); - String initialMessagePacketSize = Integer.toString(RandomUtil.randomPositiveInt()); - String maxRetryInterval = Long.toString(RandomUtil.randomPositiveLong()); - String producerMaxRate = Integer.toString(RandomUtil.randomPositiveInt()); - String producerWindowSize = Integer.toString(RandomUtil.randomPositiveInt()); - String reconnectAttempts = Integer.toString(RandomUtil.randomPositiveInt()); - String retryInterval = Long.toString(RandomUtil.randomPositiveLong()); - String retryIntervalMultiplier = Double.toString(RandomUtil.randomDouble()); - String scheduledThreadPoolMaxSize = Integer.toString(RandomUtil.randomPositiveInt()); - String threadPoolMaxSize = Integer.toString(RandomUtil.randomPositiveInt()); - String transactionBatchSize = Integer.toString(RandomUtil.randomPositiveInt()); - String autoGroup = Boolean.toString(RandomUtil.randomBoolean()); - String blockOnAcknowledge = Boolean.toString(RandomUtil.randomBoolean()); - String blockOnDurableSend = Boolean.toString(RandomUtil.randomBoolean()); - String blockOnNonDurableSend = Boolean.toString(RandomUtil.randomBoolean()); - String cacheLargeMessagesClient = Boolean.toString(RandomUtil.randomBoolean()); - String compressLargeMessage = Boolean.toString(RandomUtil.randomBoolean()); - String failoverOnInitialConnection = Boolean.toString(RandomUtil.randomBoolean()); - String preAcknowledge = Boolean.toString(RandomUtil.randomBoolean()); - String useGlobalPools = Boolean.toString(RandomUtil.randomBoolean()); - - Hashtable props = new Hashtable(); - props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, "myConnectionFactory"); - props.put("connection.myConnectionFactory.callFailoverTimeout", callFailoverTimeout); - props.put("connection.myConnectionFactory.callTimeout", callTimeout); - props.put("connection.myConnectionFactory.clientFailureCheckPeriod", clientFailureCheckPeriod); - props.put("connection.myConnectionFactory.clientID", clientID); - props.put("connection.myConnectionFactory.confirmationWindowSize", confirmationWindowSize); - props.put("connection.myConnectionFactory.connectionLoadBalancingPolicyClassName", connectionLoadBalancingPolicyClassName); - props.put("connection.myConnectionFactory.connectionTTL", connectionTTL); - props.put("connection.myConnectionFactory.consumerMaxRate", consumerMaxRate); - props.put("connection.myConnectionFactory.consumerWindowSize", consumerWindowSize); - props.put("connection.myConnectionFactory.minLargeMessageSize", minLargeMessageSize); - props.put("connection.myConnectionFactory.dupsOKBatchSize", dupsOKBatchSize); - props.put("connection.myConnectionFactory.groupID", groupID); - props.put("connection.myConnectionFactory.initialConnectAttempts", initialConnectAttempts); - props.put("connection.myConnectionFactory.initialMessagePacketSize", initialMessagePacketSize); - props.put("connection.myConnectionFactory.maxRetryInterval", maxRetryInterval); - props.put("connection.myConnectionFactory.producerMaxRate", producerMaxRate); - props.put("connection.myConnectionFactory.producerWindowSize", producerWindowSize); - props.put("connection.myConnectionFactory.reconnectAttempts", reconnectAttempts); - props.put("connection.myConnectionFactory.retryInterval", retryInterval); - props.put("connection.myConnectionFactory.retryIntervalMultiplier", retryIntervalMultiplier); - props.put("connection.myConnectionFactory.scheduledThreadPoolMaxSize", scheduledThreadPoolMaxSize); - props.put("connection.myConnectionFactory.threadPoolMaxSize", threadPoolMaxSize); - props.put("connection.myConnectionFactory.transactionBatchSize", transactionBatchSize); - props.put("connection.myConnectionFactory.blockOnAcknowledge", blockOnAcknowledge); - props.put("connection.myConnectionFactory.blockOnDurableSend", blockOnDurableSend); - props.put("connection.myConnectionFactory.blockOnNonDurableSend", blockOnNonDurableSend); - props.put("connection.myConnectionFactory.cacheLargeMessagesClient", cacheLargeMessagesClient); - props.put("connection.myConnectionFactory.compressLargeMessage", compressLargeMessage); - props.put("connection.myConnectionFactory.failoverOnInitialConnection", failoverOnInitialConnection); - props.put("connection.myConnectionFactory.autoGroup", autoGroup); - props.put("connection.myConnectionFactory.preAcknowledge", preAcknowledge); - props.put("connection.myConnectionFactory.useGlobalPools", useGlobalPools); - Context ctx = new InitialContext(props); - - ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); - - Assert.assertEquals(Long.parseLong(callFailoverTimeout), cf.getCallFailoverTimeout()); - Assert.assertEquals(Long.parseLong(callTimeout), cf.getCallTimeout()); - Assert.assertEquals(Long.parseLong(clientFailureCheckPeriod), cf.getClientFailureCheckPeriod()); - Assert.assertEquals(clientID, cf.getClientID()); - Assert.assertEquals(Integer.parseInt(confirmationWindowSize), cf.getConfirmationWindowSize()); - Assert.assertEquals(connectionLoadBalancingPolicyClassName, cf.getConnectionLoadBalancingPolicyClassName()); - Assert.assertEquals(Long.parseLong(connectionTTL), cf.getConnectionTTL()); - Assert.assertEquals(Integer.parseInt(consumerMaxRate), cf.getConsumerMaxRate()); - Assert.assertEquals(Integer.parseInt(consumerWindowSize), cf.getConsumerWindowSize()); - Assert.assertEquals(Integer.parseInt(minLargeMessageSize), cf.getMinLargeMessageSize()); - Assert.assertEquals(Integer.parseInt(dupsOKBatchSize), cf.getDupsOKBatchSize()); - Assert.assertEquals(groupID, cf.getGroupID()); - Assert.assertEquals(Integer.parseInt(initialConnectAttempts), cf.getInitialConnectAttempts()); - Assert.assertEquals(Integer.parseInt(initialMessagePacketSize), cf.getInitialMessagePacketSize()); - Assert.assertEquals(Long.parseLong(maxRetryInterval), cf.getMaxRetryInterval()); - Assert.assertEquals(Integer.parseInt(producerMaxRate), cf.getProducerMaxRate()); - Assert.assertEquals(Integer.parseInt(producerWindowSize), cf.getProducerWindowSize()); - Assert.assertEquals(Integer.parseInt(reconnectAttempts), cf.getReconnectAttempts()); - Assert.assertEquals(Long.parseLong(retryInterval), cf.getRetryInterval()); - Assert.assertEquals(Double.parseDouble(retryIntervalMultiplier), cf.getRetryIntervalMultiplier(), 0.0001); - Assert.assertEquals(Integer.parseInt(scheduledThreadPoolMaxSize), cf.getScheduledThreadPoolMaxSize()); - Assert.assertEquals(Integer.parseInt(threadPoolMaxSize), cf.getThreadPoolMaxSize()); - Assert.assertEquals(Integer.parseInt(transactionBatchSize), cf.getTransactionBatchSize()); - Assert.assertEquals(Boolean.parseBoolean(autoGroup), cf.isAutoGroup()); - Assert.assertEquals(Boolean.parseBoolean(blockOnAcknowledge), cf.isBlockOnAcknowledge()); - Assert.assertEquals(Boolean.parseBoolean(blockOnDurableSend), cf.isBlockOnDurableSend()); - Assert.assertEquals(Boolean.parseBoolean(blockOnNonDurableSend), cf.isBlockOnNonDurableSend()); - Assert.assertEquals(Boolean.parseBoolean(cacheLargeMessagesClient), cf.isCacheLargeMessagesClient()); - Assert.assertEquals(Boolean.parseBoolean(compressLargeMessage), cf.isCompressLargeMessage()); - Assert.assertEquals(Boolean.parseBoolean(failoverOnInitialConnection), cf.isFailoverOnInitialConnection()); - Assert.assertEquals(Boolean.parseBoolean(preAcknowledge), cf.isPreAcknowledge()); - Assert.assertEquals(Boolean.parseBoolean(useGlobalPools), cf.isUseGlobalPools()); - } - @Test public void testRemoteCFWithTCP() throws NamingException, JMSException { Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(Context.PROVIDER_URL, "tcp://127.0.0.1:5445"); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, "myConnectionFactory"); + props.put("connectionFactory.myConnectionFactory", "tcp://127.0.0.1:5445"); Context ctx = new InitialContext(props); ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("myConnectionFactory"); @@ -444,18 +193,14 @@ public class SimpleJNDIClientTest extends UnitTestCase @Test public void testRemoteCFWithTCPandHA() throws NamingException, JMSException { - boolean ha = true; - Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(Context.PROVIDER_URL, "tcp://127.0.0.1:5445"); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, "myConnectionFactory"); - props.put("connection.myConnectionFactory.ha", ha); + props.put("connectionFactory.myConnectionFactory", "tcp://127.0.0.1:5445?ha=true"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); - Assert.assertEquals(ha, cf.isHA()); + Assert.assertEquals(true, cf.isHA()); } @Test @@ -463,39 +208,89 @@ public class SimpleJNDIClientTest extends UnitTestCase { Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(Context.PROVIDER_URL, "jgroups://test-jgroups-file_ping.xml/"); + props.put("connectionFactory.myConnectionFactory", "jgroups://mychannelid?file=test-jgroups-file_ping.xml"); Context ctx = new InitialContext(props); - ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("ConnectionFactory"); - connectionFactory.getDiscoveryGroupConfiguration().getBroadcastEndpointFactoryConfiguration().createBroadcastEndpointFactory().createBroadcastEndpoint().close(false); + ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); + connectionFactory.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory().createBroadcastEndpoint().close(false); } @Test - public void testRemoteCFWithJgroupsWithTransportConfig() throws Exception + public void testRemoteCFWithJgroupsWithTransportConfigFile() throws Exception { Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getCanonicalName()); - props.put(Context.PROVIDER_URL, "jgroups://test-jgroups-file_ping.xml?" + + props.put("connectionFactory.myConnectionFactory", "jgroups://testChannelName?file=test-jgroups-file_ping.xml&" + ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" + ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000"); Context ctx = new InitialContext(props); + ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); + + DiscoveryGroupConfiguration discoveryGroupConfiguration = cf.getDiscoveryGroupConfiguration(); + Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout()); + Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout()); + + BroadcastEndpoint broadcastEndpoint = cf.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory().createBroadcastEndpoint(); + Assert.assertTrue(broadcastEndpoint instanceof JGroupsFileBroadcastEndpoint); + broadcastEndpoint.close(false); + } + + @Test + public void testRemoteCFWithJgroupsWithTransportConfigProps() throws Exception + { + Hashtable props = new Hashtable<>(); + props.put(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getCanonicalName()); + props.put("connectionFactory.ConnectionFactory", "jgroups://testChannelName?properties=param=value&" + + ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" + + ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000"); + Context ctx = new InitialContext(props); + ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("ConnectionFactory"); DiscoveryGroupConfiguration discoveryGroupConfiguration = cf.getDiscoveryGroupConfiguration(); Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout()); Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout()); - cf.getDiscoveryGroupConfiguration().getBroadcastEndpointFactoryConfiguration().createBroadcastEndpointFactory().createBroadcastEndpoint().close(false); + BroadcastEndpointFactory broadcastEndpointFactory = cf.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory(); + Assert.assertTrue(broadcastEndpointFactory instanceof JGroupsPropertiesBroadcastEndpointFactory); + JGroupsPropertiesBroadcastEndpointFactory endpointFactory = (JGroupsPropertiesBroadcastEndpointFactory) broadcastEndpointFactory; + Assert.assertEquals(endpointFactory.getProperties(), "param=value"); + Assert.assertEquals(endpointFactory.getChannelName(), "testChannelName"); } + + + @Test + public void testRemoteCFWithJgroupsWithTransportConfigNullProps() throws Exception + { + Hashtable props = new Hashtable<>(); + props.put(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getCanonicalName()); + props.put("connectionFactory.ConnectionFactory", "jgroups://testChannelName?" + + ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" + + ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000"); + Context ctx = new InitialContext(props); + + ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("ConnectionFactory"); + + DiscoveryGroupConfiguration discoveryGroupConfiguration = cf.getDiscoveryGroupConfiguration(); + Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout()); + Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout()); + + BroadcastEndpointFactory broadcastEndpointFactory = cf.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory(); + Assert.assertTrue(broadcastEndpointFactory instanceof JGroupsPropertiesBroadcastEndpointFactory); + JGroupsPropertiesBroadcastEndpointFactory endpointFactory = (JGroupsPropertiesBroadcastEndpointFactory) broadcastEndpointFactory; + Assert.assertEquals(endpointFactory.getProperties(), null); + Assert.assertEquals(endpointFactory.getChannelName(), "testChannelName"); + } + + @Test public void testRemoteCFWithUDP() throws NamingException, JMSException { Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(Context.PROVIDER_URL, "udp://" + getUDPDiscoveryAddress() + ":" + getUDPDiscoveryPort()); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, "myConnectionFactory"); + props.put("connectionFactory.myConnectionFactory", "udp://" + getUDPDiscoveryAddress() + ":" + getUDPDiscoveryPort()); Context ctx = new InitialContext(props); ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("myConnectionFactory"); @@ -508,12 +303,11 @@ public class SimpleJNDIClientTest extends UnitTestCase { Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getCanonicalName()); - props.put(Context.PROVIDER_URL, "udp://" + getUDPDiscoveryAddress() + ":" + getUDPDiscoveryPort() + "?" + + props.put("connectionFactory.myConnectionFactory", "udp://" + getUDPDiscoveryAddress() + ":" + getUDPDiscoveryPort() + "?" + TransportConstants.LOCAL_ADDRESS_PROP_NAME + "=127.0.0.1&" + TransportConstants.LOCAL_PORT_PROP_NAME + "=1198&" + ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" + ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000"); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, "myConnectionFactory"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); @@ -522,11 +316,12 @@ public class SimpleJNDIClientTest extends UnitTestCase Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout()); Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout()); - UDPBroadcastGroupConfiguration udpBroadcastGroupConfiguration = (UDPBroadcastGroupConfiguration) discoveryGroupConfiguration.getBroadcastEndpointFactoryConfiguration(); - Assert.assertEquals("127.0.0.1", udpBroadcastGroupConfiguration.getLocalBindAddress()); - Assert.assertEquals(1198, udpBroadcastGroupConfiguration.getLocalBindPort()); - Assert.assertEquals(getUDPDiscoveryAddress(), udpBroadcastGroupConfiguration.getGroupAddress()); - Assert.assertEquals(getUDPDiscoveryPort(), udpBroadcastGroupConfiguration.getGroupPort()); + UDPBroadcastEndpointFactory udpBroadcastEndpointFactory = (UDPBroadcastEndpointFactory) discoveryGroupConfiguration.getBroadcastEndpointFactory(); + //these 2 are transient so are ignored + Assert.assertEquals(null, udpBroadcastEndpointFactory.getLocalBindAddress()); + Assert.assertEquals(-1, udpBroadcastEndpointFactory.getLocalBindPort()); + Assert.assertEquals(getUDPDiscoveryAddress(), udpBroadcastEndpointFactory.getGroupAddress()); + Assert.assertEquals(getUDPDiscoveryPort(), udpBroadcastEndpointFactory.getGroupPort()); } @Test @@ -534,8 +329,7 @@ public class SimpleJNDIClientTest extends UnitTestCase { Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(Context.PROVIDER_URL, "tcp://127.0.0.1:5445,127.0.0.2:5446"); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, "myConnectionFactory"); + props.put("connectionFactory.myConnectionFactory", "tcp://127.0.0.1:5445/httpEnabled=true&foo=bar,tcp://127.0.0.2:5446?httpEnabled=false?clientID=myClientID"); Context ctx = new InitialContext(props); ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("myConnectionFactory"); @@ -548,7 +342,7 @@ public class SimpleJNDIClientTest extends UnitTestCase { Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); - props.put(Context.PROVIDER_URL, "tcp://127.0.0.1:5445?" + + props.put("connectionFactory.myConnectionFactory", "tcp://127.0.0.1:5445?" + TransportConstants.SSL_ENABLED_PROP_NAME + "=mySSLEnabledPropValue&" + TransportConstants.HTTP_ENABLED_PROP_NAME + "=myHTTPEnabledPropValue&" + TransportConstants.HTTP_CLIENT_IDLE_PROP_NAME + "=myHTTPClientIdlePropValue&" + @@ -578,7 +372,6 @@ public class SimpleJNDIClientTest extends UnitTestCase ActiveMQDefaultConfiguration.getPropMaskPassword() + "=myPropMaskPassword&" + ActiveMQDefaultConfiguration.getPropPasswordCodec() + "=myPropPasswordCodec&" + TransportConstants.NETTY_CONNECT_TIMEOUT + "=myNettyConnectTimeout&"); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, "myConnectionFactory"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); @@ -634,7 +427,7 @@ public class SimpleJNDIClientTest extends UnitTestCase connectorNames.add(liveTC.getName()); Map params = new HashMap(); - params.put("server-id", 1); + params.put(org.apache.activemq.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, 1); Configuration liveConf = createBasicConfig() .addAcceptorConfiguration(new TransportConfiguration(INVM_ACCEPTOR_FACTORY)) @@ -653,10 +446,10 @@ public class SimpleJNDIClientTest extends UnitTestCase .setName(bcGroupName) .setBroadcastPeriod(broadcastPeriod) .setConnectorInfos(connectorNames) - .setEndpointFactoryConfiguration(new UDPBroadcastGroupConfiguration() - .setGroupAddress(groupAddress) - .setGroupPort(groupPort) - .setLocalBindPort(localBindPort)); + .setEndpointFactory(new UDPBroadcastEndpointFactory() + .setGroupAddress(groupAddress) + .setGroupPort(groupPort) + .setLocalBindPort(localBindPort)); List bcConfigs1 = new ArrayList(); bcConfigs1.add(bcConfig1); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/connection/ConnectionFactorySerializationTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/connection/ConnectionFactorySerializationTest.java index 7b75c6a427..37b0dc3ce6 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/connection/ConnectionFactorySerializationTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/connection/ConnectionFactorySerializationTest.java @@ -16,22 +16,35 @@ */ package org.apache.activemq.tests.integration.jms.connection; +import java.beans.PropertyDescriptor; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Set; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.JGroupsFileBroadcastEndpointFactory; +import org.apache.activemq.api.core.JGroupsPropertiesBroadcastEndpointFactory; +import org.apache.activemq.api.core.TransportConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.jms.JMSFactoryType; +import org.apache.activemq.core.remoting.impl.netty.TransportConstants; import org.apache.activemq.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.jms.server.config.ConnectionFactoryConfiguration; +import org.apache.activemq.jms.server.config.impl.ConnectionFactoryConfigurationImpl; import org.apache.activemq.tests.util.JMSTestBase; +import org.apache.activemq.tests.util.RandomUtil; +import org.apache.commons.beanutils.BeanUtilsBean; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -53,57 +66,297 @@ public class ConnectionFactorySerializationTest extends JMSTestBase @Before public void setUp() throws Exception { - try - { - super.setUp(); - // Deploy a connection factory with discovery - List bindings = new ArrayList(); - bindings.add("MyConnectionFactory"); - final String groupAddress = getUDPDiscoveryAddress(); - final int port = getUDPDiscoveryPort(); - String localBindAddress = getLocalHost().getHostAddress(); - - UDPBroadcastGroupConfiguration config = new UDPBroadcastGroupConfiguration() - .setGroupAddress(groupAddress) - .setGroupPort(port) - .setLocalBindAddress(localBindAddress) - .setLocalBindPort(8580); - - DiscoveryGroupConfiguration dcConfig = new DiscoveryGroupConfiguration() - .setName("dg1") - .setRefreshTimeout(5000) - .setDiscoveryInitialWaitTimeout(5000) - .setBroadcastEndpointFactoryConfiguration(config); - - jmsServer.getActiveMQServer().getConfiguration().getDiscoveryGroupConfigurations().put(dcConfig.getName(), dcConfig); - - jmsServer.createConnectionFactory("MyConnectionFactory", - false, - JMSFactoryType.CF, - dcConfig.getName(), - "/MyConnectionFactory"); - } - catch (Exception e) - { - e.printStackTrace(); - } - + super.setUp(); } // Public -------------------------------------------------------- @Test - public void testNullLocalBindAddress() throws Exception + public void testConnectionFactoryUDP() throws Exception { + createDiscoveryFactoryUDP(); cf = (ActiveMQConnectionFactory) namingContext.lookup("/MyConnectionFactory"); // apparently looking up the connection factory with the org.apache.activemq.jms.tests.tools.container.InVMInitialContextFactory // is not enough to actually serialize it so we serialize it manually byte[] x = serialize(cf); ActiveMQConnectionFactory y = deserialize(x, ActiveMQConnectionFactory.class); - Assert.assertEquals(null, ((UDPBroadcastGroupConfiguration) y.getDiscoveryGroupConfiguration().getBroadcastEndpointFactoryConfiguration()).getLocalBindAddress()); + checkEquals(cf, y); + DiscoveryGroupConfiguration dgc = y.getDiscoveryGroupConfiguration(); + Assert.assertEquals(dgc.getName(), "dg1"); + Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5000); + Assert.assertEquals(dgc.getRefreshTimeout(), 5000); + Assert.assertTrue(dgc.getBroadcastEndpointFactory() instanceof UDPBroadcastEndpointFactory); + UDPBroadcastEndpointFactory befc = (UDPBroadcastEndpointFactory) dgc.getBroadcastEndpointFactory(); + Assert.assertEquals(-1, befc.getLocalBindPort()); + Assert.assertEquals(null, befc.getLocalBindAddress()); + Assert.assertEquals(1234, befc.getGroupPort()); + Assert.assertEquals("1.2.3.4", befc.getGroupAddress()); } + @Test + public void testConnectionFactoryJgroupsFile() throws Exception + { + createDiscoveryFactoryJGroupsFile(); + cf = (ActiveMQConnectionFactory) namingContext.lookup("/MyConnectionFactory"); + + // apparently looking up the connection factory with the org.apache.activemq.jms.tests.tools.container.InVMInitialContextFactory + // is not enough to actually serialize it so we serialize it manually + byte[] x = serialize(cf); + ActiveMQConnectionFactory y = deserialize(x, ActiveMQConnectionFactory.class); + checkEquals(cf, y); + DiscoveryGroupConfiguration dgc = y.getDiscoveryGroupConfiguration(); + Assert.assertEquals(dgc.getName(), "dg1"); + Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5000); + Assert.assertEquals(dgc.getRefreshTimeout(), 5000); + Assert.assertTrue(dgc.getBroadcastEndpointFactory() instanceof JGroupsFileBroadcastEndpointFactory); + JGroupsFileBroadcastEndpointFactory befc = (JGroupsFileBroadcastEndpointFactory) dgc.getBroadcastEndpointFactory(); + Assert.assertEquals("myChannel", befc.getChannelName()); + Assert.assertEquals("/META-INF/myfile.xml", befc.getFile()); + } + + @Test + public void testConnectionFactoryJgroupsProperties() throws Exception + { + createDiscoveryFactoryJGroupsProperties(); + cf = (ActiveMQConnectionFactory) namingContext.lookup("/MyConnectionFactory"); + + // apparently looking up the connection factory with the org.apache.activemq.jms.tests.tools.container.InVMInitialContextFactory + // is not enough to actually serialize it so we serialize it manually + byte[] x = serialize(cf); + ActiveMQConnectionFactory y = deserialize(x, ActiveMQConnectionFactory.class); + checkEquals(cf, y); + DiscoveryGroupConfiguration dgc = y.getDiscoveryGroupConfiguration(); + Assert.assertEquals(dgc.getName(), "dg1"); + Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5000); + Assert.assertEquals(dgc.getRefreshTimeout(), 5000); + Assert.assertTrue(dgc.getBroadcastEndpointFactory() instanceof JGroupsPropertiesBroadcastEndpointFactory); + JGroupsPropertiesBroadcastEndpointFactory befc = (JGroupsPropertiesBroadcastEndpointFactory) dgc.getBroadcastEndpointFactory(); + Assert.assertEquals("myChannel", befc.getChannelName()); + Assert.assertEquals("param=1,param2=2", befc.getProperties()); + } + + @Test + public void testConnectionFactoryStatic1() throws Exception + { + createStaticFactory(true); + cf = (ActiveMQConnectionFactory) namingContext.lookup("/MyConnectionFactory"); + + // apparently looking up the connection factory with the org.apache.activemq.jms.tests.tools.container.InVMInitialContextFactory + // is not enough to actually serialize it so we serialize it manually + byte[] x = serialize(cf); + ActiveMQConnectionFactory y = deserialize(x, ActiveMQConnectionFactory.class); + checkEquals(cf, y); + TransportConfiguration[] staticConnectors = y.getStaticConnectors(); + Assert.assertEquals(staticConnectors.length, 2); + TransportConfiguration tc0 = cf.getStaticConnectors()[0]; + TransportConfiguration y0 = y.getStaticConnectors()[0]; + Map ctParams = tc0.getParams(); + Map y0Params = y0.getParams(); + Assert.assertEquals(ctParams.size(), y0Params.size()); + for (String key : y0Params.keySet()) + { + Assert.assertEquals(ctParams.get(key), y0Params.get(key)); + } + } + + private void createDiscoveryFactoryUDP() throws Exception + { + // Deploy a connection factory with discovery + List bindings = new ArrayList(); + bindings.add("MyConnectionFactory"); + final String groupAddress = "1.2.3.4"; + final int port = 1234; + String localBindAddress = getLocalHost().getHostAddress(); + + UDPBroadcastEndpointFactory config = new UDPBroadcastEndpointFactory() + .setGroupAddress(groupAddress) + .setGroupPort(port) + .setLocalBindAddress(localBindAddress) + .setLocalBindPort(8580); + + DiscoveryGroupConfiguration dcConfig = new DiscoveryGroupConfiguration() + .setName("dg1") + .setRefreshTimeout(5000) + .setDiscoveryInitialWaitTimeout(5000) + .setBroadcastEndpointFactory(config); + + jmsServer.getActiveMQServer().getConfiguration().getDiscoveryGroupConfigurations().put(dcConfig.getName(), dcConfig); + + jmsServer.createConnectionFactory("MyConnectionFactory", + false, + JMSFactoryType.CF, + dcConfig.getName(), + "/MyConnectionFactory"); + } + + private void createDiscoveryFactoryJGroupsFile() throws Exception + { + // Deploy a connection factory with discovery + List bindings = new ArrayList(); + bindings.add("MyConnectionFactory"); + + JGroupsFileBroadcastEndpointFactory config = new JGroupsFileBroadcastEndpointFactory() + .setChannelName("myChannel") + .setFile("/META-INF/myfile.xml"); + + DiscoveryGroupConfiguration dcConfig = new DiscoveryGroupConfiguration() + .setName("dg1") + .setRefreshTimeout(5000) + .setDiscoveryInitialWaitTimeout(5000) + .setBroadcastEndpointFactory(config); + + jmsServer.getActiveMQServer().getConfiguration().getDiscoveryGroupConfigurations().put(dcConfig.getName(), dcConfig); + + jmsServer.createConnectionFactory("MyConnectionFactory", + false, + JMSFactoryType.CF, + dcConfig.getName(), + "/MyConnectionFactory"); + } + + private void createDiscoveryFactoryJGroupsProperties() throws Exception + { + // Deploy a connection factory with discovery + List bindings = new ArrayList(); + bindings.add("MyConnectionFactory"); + + JGroupsPropertiesBroadcastEndpointFactory config = new JGroupsPropertiesBroadcastEndpointFactory() + .setChannelName("myChannel") + .setProperties("param=1,param2=2"); + + DiscoveryGroupConfiguration dcConfig = new DiscoveryGroupConfiguration() + .setName("dg1") + .setRefreshTimeout(5000) + .setDiscoveryInitialWaitTimeout(5000) + .setBroadcastEndpointFactory(config); + + jmsServer.getActiveMQServer().getConfiguration().getDiscoveryGroupConfigurations().put(dcConfig.getName(), dcConfig); + + jmsServer.createConnectionFactory("MyConnectionFactory", + false, + JMSFactoryType.CF, + dcConfig.getName(), + "/MyConnectionFactory"); + } + + private void createStaticFactory(boolean b) throws Exception + { + HashMap params = new HashMap<>(); + Set allowableConnectorKeys = TransportConstants.ALLOWABLE_CONNECTOR_KEYS; + for (String allowableConnectorKey : allowableConnectorKeys) + { + String value = RandomUtil.randomString(); + params.put(allowableConnectorKey, value); + } + params.put("host", "localhost0"); + params.put("port", "1234"); + + TransportConfiguration main = new TransportConfiguration(NETTY_CONNECTOR_FACTORY, params); + + jmsServer.getActiveMQServer().getConfiguration().getConnectorConfigurations().put(main.getName(), main); + + HashMap params2 = new HashMap<>(); + for (String allowableConnectorKey : allowableConnectorKeys) + { + String value = RandomUtil.randomString(); + params2.put(allowableConnectorKey, value); + } + params2.put("host", "localhost1"); + params2.put("port", "5678"); + + TransportConfiguration main2 = new TransportConfiguration(NETTY_CONNECTOR_FACTORY, params2); + + jmsServer.getActiveMQServer().getConfiguration().getConnectorConfigurations().put(main2.getName(), main2); + + ArrayList connectorNames = new ArrayList(); + connectorNames.add(main.getName()); + connectorNames.add(main2.getName()); + ConnectionFactoryConfiguration configuration = new ConnectionFactoryConfigurationImpl() + .setName("MyConnectionFactory") + .setHA(b) + .setConnectorNames(connectorNames) + .setClientID("clientID") + .setClientFailureCheckPeriod(-1) + .setConnectionTTL(-2) + .setFactoryType(JMSFactoryType.CF) + .setCallTimeout(-3) + .setCallFailoverTimeout(-4) + .setCacheLargeMessagesClient(b) + .setMinLargeMessageSize(-5) + .setConsumerWindowSize(-6) + .setConsumerMaxRate(-7) + .setConfirmationWindowSize(-8) + .setProducerWindowSize(-9) + .setProducerMaxRate(-10) + .setBlockOnAcknowledge(b) + .setBlockOnDurableSend(b) + .setBlockOnNonDurableSend(b) + .setAutoGroup(b) + .setPreAcknowledge(b) + .setLoadBalancingPolicyClassName("foobar") + .setTransactionBatchSize(-11) + .setDupsOKBatchSize(-12) + .setUseGlobalPools(b) + .setScheduledThreadPoolMaxSize(-13) + .setThreadPoolMaxSize(-14) + .setRetryInterval(-15) + .setRetryIntervalMultiplier(-16) + .setMaxRetryInterval(-17) + .setReconnectAttempts(-18) + .setFailoverOnInitialConnection(b) + .setGroupID("groupID"); + + jmsServer.createConnectionFactory(false, configuration, "/MyConnectionFactory"); + } + + private void populate(StringBuilder sb, BeanUtilsBean bean, ActiveMQConnectionFactory factory) throws IllegalAccessException, InvocationTargetException + { + PropertyDescriptor[] descriptors = bean.getPropertyUtils().getPropertyDescriptors(factory); + for (PropertyDescriptor descriptor : descriptors) + { + if (descriptor.getWriteMethod() != null && descriptor.getReadMethod() != null) + { + if (descriptor.getPropertyType() == String.class) + { + String value = RandomUtil.randomString(); + bean.setProperty(factory, descriptor.getName(), value); + sb.append("&").append(descriptor.getName()).append("=").append(value); + } + else if (descriptor.getPropertyType() == int.class) + { + int value = RandomUtil.randomPositiveInt(); + bean.setProperty(factory, descriptor.getName(), value); + sb.append("&").append(descriptor.getName()).append("=").append(value); + } + else if (descriptor.getPropertyType() == long.class) + { + long value = RandomUtil.randomPositiveLong(); + bean.setProperty(factory, descriptor.getName(), value); + sb.append("&").append(descriptor.getName()).append("=").append(value); + } + else if (descriptor.getPropertyType() == double.class) + { + double value = RandomUtil.randomDouble(); + bean.setProperty(factory, descriptor.getName(), value); + sb.append("&").append(descriptor.getName()).append("=").append(value); + } + } + } + } + + private static void checkEquals(Object factory, Object factory2) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException + { + BeanUtilsBean bean = new BeanUtilsBean(); + PropertyDescriptor[] descriptors = bean.getPropertyUtils().getPropertyDescriptors(factory); + for (PropertyDescriptor descriptor : descriptors) + { + if (descriptor.getWriteMethod() != null && descriptor.getReadMethod() != null) + { + Assert.assertEquals(descriptor.getName() + " incorrect", bean.getProperty(factory, descriptor.getName()),bean.getProperty(factory2, descriptor.getName())); + } + } + } private static byte[] serialize(T obj) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/connection/ConnectionFactoryWithJGroupsSerializationTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/connection/ConnectionFactoryWithJGroupsSerializationTest.java index ab643ec753..6a033c0e24 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/connection/ConnectionFactoryWithJGroupsSerializationTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/connection/ConnectionFactoryWithJGroupsSerializationTest.java @@ -25,9 +25,10 @@ import java.io.Serializable; import javax.jms.Queue; -import org.apache.activemq.api.core.BroadcastEndpointFactoryConfiguration; +import org.apache.activemq.api.core.BroadcastEndpointFactory; +import org.apache.activemq.api.core.ChannelBroadcastEndpointFactory; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; -import org.apache.activemq.api.core.JGroupsBroadcastGroupConfiguration; +import org.apache.activemq.api.core.JGroupsFileBroadcastEndpointFactory; import org.apache.activemq.api.jms.JMSFactoryType; import org.apache.activemq.jms.client.ActiveMQConnectionFactory; import org.apache.activemq.tests.util.JMSTestBase; @@ -93,20 +94,22 @@ public class ConnectionFactoryWithJGroupsSerializationTest extends JMSTestBase String channelName1 = "channel1"; String channelName2 = "channel2"; - JGroupsBroadcastGroupConfiguration jgroupsBroadcastCfg1 = new JGroupsBroadcastGroupConfiguration(channel, channelName1); - JGroupsBroadcastGroupConfiguration jgroupsBroadcastCfg2 = new JGroupsBroadcastGroupConfiguration(jgroupsConfigString, channelName2); + BroadcastEndpointFactory jgroupsBroadcastCfg1 = new ChannelBroadcastEndpointFactory(channel, channelName1); + BroadcastEndpointFactory jgroupsBroadcastCfg2 = new JGroupsFileBroadcastEndpointFactory() + .setChannelName(channelName2) + .setFile(jgroupsConfigString); DiscoveryGroupConfiguration dcConfig1 = new DiscoveryGroupConfiguration() .setName("dg1") .setRefreshTimeout(5000) .setDiscoveryInitialWaitTimeout(5000) - .setBroadcastEndpointFactoryConfiguration(jgroupsBroadcastCfg1); + .setBroadcastEndpointFactory(jgroupsBroadcastCfg1); DiscoveryGroupConfiguration dcConfig2 = new DiscoveryGroupConfiguration() .setName("dg2") .setRefreshTimeout(5000) .setDiscoveryInitialWaitTimeout(5000) - .setBroadcastEndpointFactoryConfiguration(jgroupsBroadcastCfg2); + .setBroadcastEndpointFactory(jgroupsBroadcastCfg2); jmsServer.getActiveMQServer().getConfiguration().getDiscoveryGroupConfigurations().put(dcConfig1.getName(), dcConfig1); jmsServer.getActiveMQServer().getConfiguration().getDiscoveryGroupConfigurations().put(dcConfig2.getName(), dcConfig2); @@ -160,8 +163,8 @@ public class ConnectionFactoryWithJGroupsSerializationTest extends JMSTestBase byte[] x = serialize(jmsCf2); ActiveMQConnectionFactory jmsCf2Copy = deserialize(x, ActiveMQConnectionFactory.class); assertNotNull(jmsCf2Copy); - BroadcastEndpointFactoryConfiguration broadcastEndpoint = jmsCf2Copy.getDiscoveryGroupConfiguration().getBroadcastEndpointFactoryConfiguration(); - assertTrue(broadcastEndpoint instanceof JGroupsBroadcastGroupConfiguration); + BroadcastEndpointFactory broadcastEndpoint = jmsCf2Copy.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory(); + assertTrue(broadcastEndpoint instanceof JGroupsFileBroadcastEndpointFactory); } @Override diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/server/JMSServerDeployerTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/server/JMSServerDeployerTest.java index c3b3de3602..2ebaf0e29d 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/server/JMSServerDeployerTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/server/JMSServerDeployerTest.java @@ -22,7 +22,7 @@ import javax.naming.Context; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.core.config.Configuration; import org.apache.activemq.core.registry.JndiBindingRegistry; import org.apache.activemq.core.remoting.impl.netty.NettyConnectorFactory; @@ -126,10 +126,10 @@ public class JMSServerDeployerTest extends ServiceTestBase .setName("mygroup") .setRefreshTimeout(5432) .setDiscoveryInitialWaitTimeout(5432) - .setBroadcastEndpointFactoryConfiguration(new UDPBroadcastGroupConfiguration() - .setGroupAddress("243.7.7.7") - .setGroupPort(12345) - .setLocalBindAddress("172.16.8.10")); + .setBroadcastEndpointFactory(new UDPBroadcastEndpointFactory() + .setGroupAddress("243.7.7.7") + .setGroupPort(12345) + .setLocalBindAddress("172.16.8.10")); config = createBasicConfig() .addConnectorConfiguration("netty", new TransportConfiguration(NettyConnectorFactory.class.getName())) diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/ActiveMQServerControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/ActiveMQServerControlTest.java index 3016d055fd..806a3fa3be 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/ActiveMQServerControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/ActiveMQServerControlTest.java @@ -42,6 +42,7 @@ import org.apache.activemq.core.config.Configuration; import org.apache.activemq.core.messagecounter.impl.MessageCounterManagerImpl; import org.apache.activemq.core.remoting.impl.invm.InVMAcceptorFactory; import org.apache.activemq.core.remoting.impl.invm.InVMConnectorFactory; +import org.apache.activemq.core.remoting.impl.invm.TransportConstants; import org.apache.activemq.core.server.ActiveMQServer; import org.apache.activemq.core.server.ActiveMQServers; import org.apache.activemq.core.settings.impl.SlowConsumerPolicy; @@ -1019,7 +1020,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase conf.setSecurityEnabled(false); conf.getAcceptorConfigurations().clear(); HashMap params = new HashMap(); - params.put("server-id", "2"); + params.put(TransportConstants.SERVER_ID_PROP_NAME, "2"); conf.getAcceptorConfigurations().add(new TransportConfiguration(InVMAcceptorFactory.class.getName(), params)); ActiveMQServer server2 = ActiveMQServers.newActiveMQServer(conf, null, true); this.conf.getConnectorConfigurations().clear(); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/BroadcastGroupControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/BroadcastGroupControlTest.java index 3462601ad7..ccd41b8c80 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/BroadcastGroupControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/BroadcastGroupControlTest.java @@ -25,7 +25,7 @@ import org.junit.Assert; import org.apache.activemq.api.core.BroadcastGroupConfiguration; import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.core.management.BroadcastGroupControl; import org.apache.activemq.core.config.Configuration; import org.apache.activemq.core.server.ActiveMQServer; @@ -50,10 +50,10 @@ public class BroadcastGroupControlTest extends ManagementTestBase .setName(RandomUtil.randomString()) .setBroadcastPeriod(RandomUtil.randomPositiveInt()) .setConnectorInfos(connectorInfos) - .setEndpointFactoryConfiguration(new UDPBroadcastGroupConfiguration() - .setGroupAddress("231.7.7.7") - .setGroupPort(1199) - .setLocalBindPort(1198)); + .setEndpointFactory(new UDPBroadcastEndpointFactory() + .setGroupAddress("231.7.7.7") + .setGroupPort(1199) + .setLocalBindPort(1198)); } public static Pair randomPair() @@ -82,7 +82,7 @@ public class BroadcastGroupControlTest extends ManagementTestBase BroadcastGroupControl broadcastGroupControl = createManagementControl(broadcastGroupConfig.getName()); - UDPBroadcastGroupConfiguration udpCfg = (UDPBroadcastGroupConfiguration) broadcastGroupConfig.getEndpointFactoryConfiguration(); + UDPBroadcastEndpointFactory udpCfg = (UDPBroadcastEndpointFactory) broadcastGroupConfig.getEndpointFactory(); Assert.assertEquals(broadcastGroupConfig.getName(), broadcastGroupControl.getName()); Assert.assertEquals(udpCfg.getGroupAddress(), broadcastGroupControl.getGroupAddress()); Assert.assertEquals(udpCfg.getGroupPort(), broadcastGroupControl.getGroupPort()); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/ClusterConnectionControl2Test.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/ClusterConnectionControl2Test.java index 93f6e63298..8c4341c8e3 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/ClusterConnectionControl2Test.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/ClusterConnectionControl2Test.java @@ -33,7 +33,7 @@ import org.junit.Assert; import org.apache.activemq.api.core.BroadcastGroupConfiguration; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.core.management.ClusterConnectionControl; import org.apache.activemq.core.config.ClusterConnectionConfiguration; import org.apache.activemq.core.config.Configuration; @@ -133,17 +133,17 @@ public class ClusterConnectionControl2Test extends ManagementTestBase .setName(discoveryName) .setBroadcastPeriod(250) .setConnectorInfos(connectorInfos) - .setEndpointFactoryConfiguration(new UDPBroadcastGroupConfiguration() - .setGroupAddress(groupAddress) - .setGroupPort(groupPort)); + .setEndpointFactory(new UDPBroadcastEndpointFactory() + .setGroupAddress(groupAddress) + .setGroupPort(groupPort)); DiscoveryGroupConfiguration discoveryGroupConfig = new DiscoveryGroupConfiguration() .setName(discoveryName) .setRefreshTimeout(0) .setDiscoveryInitialWaitTimeout(0) - .setBroadcastEndpointFactoryConfiguration(new UDPBroadcastGroupConfiguration() - .setGroupAddress(groupAddress) - .setGroupPort(groupPort)); + .setBroadcastEndpointFactory(new UDPBroadcastEndpointFactory() + .setGroupAddress(groupAddress) + .setGroupPort(groupPort)); clusterConnectionConfig_0 = new ClusterConnectionConfiguration() .setName(clusterName) diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/ClusterConnectionControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/ClusterConnectionControlTest.java index c7876789dd..041cd3e611 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/ClusterConnectionControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/ClusterConnectionControlTest.java @@ -31,7 +31,7 @@ import org.junit.Assert; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.api.core.SimpleString; import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.core.management.ClusterConnectionControl; import org.apache.activemq.api.core.management.CoreNotificationType; import org.apache.activemq.api.core.management.ObjectNameBuilder; @@ -236,9 +236,9 @@ public class ClusterConnectionControlTest extends ManagementTestBase .setName(discoveryGroupName) .setRefreshTimeout(500) .setDiscoveryInitialWaitTimeout(0) - .setBroadcastEndpointFactoryConfiguration(new UDPBroadcastGroupConfiguration() - .setGroupAddress("230.1.2.3") - .setGroupPort(6745)); + .setBroadcastEndpointFactory(new UDPBroadcastEndpointFactory() + .setGroupAddress("230.1.2.3") + .setGroupPort(6745)); Configuration conf_1 = createBasicConfig() .addAcceptorConfiguration(acceptorConfig) diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/ra/ActiveMQRAClusteredTestBase.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/ra/ActiveMQRAClusteredTestBase.java index b33e43d4e2..aeccc02073 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/ra/ActiveMQRAClusteredTestBase.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/ra/ActiveMQRAClusteredTestBase.java @@ -21,6 +21,7 @@ import java.util.HashMap; import org.apache.activemq.api.core.TransportConfiguration; import org.apache.activemq.core.config.Configuration; import org.apache.activemq.core.config.impl.ConfigurationImpl; +import org.apache.activemq.core.remoting.impl.invm.TransportConstants; import org.apache.activemq.core.server.ActiveMQServer; import org.apache.activemq.core.server.ActiveMQServers; import org.apache.activemq.jms.server.impl.JMSServerManagerImpl; @@ -42,7 +43,7 @@ public class ActiveMQRAClusteredTestBase extends ActiveMQRATestBase primaryConnector = new TransportConfiguration(INVM_CONNECTOR_FACTORY); HashMap params = new HashMap(); - params.put("server-id", "1"); + params.put(TransportConstants.SERVER_ID_PROP_NAME, "1"); secondaryConnector = new TransportConfiguration(INVM_CONNECTOR_FACTORY, params); Configuration conf = createSecondaryDefaultConfig(true, true); @@ -77,7 +78,7 @@ public class ActiveMQRAClusteredTestBase extends ActiveMQRATestBase if (secondary) { - invmMap.put("server-id", "1"); + invmMap.put(TransportConstants.SERVER_ID_PROP_NAME, "1"); nettyMap.put("port", "5545"); primaryConnectorName = "invm"; secondaryConnectorName = "invm2"; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/ra/ResourceAdapterTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/ra/ResourceAdapterTest.java index 74f2ef114c..1b33cc6bc3 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/ra/ResourceAdapterTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/ra/ResourceAdapterTest.java @@ -27,7 +27,7 @@ import java.util.Set; import java.util.concurrent.CountDownLatch; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.core.client.ClientSession; import org.apache.activemq.api.core.client.ClientSessionFactory; import org.apache.activemq.api.core.client.ServerLocator; @@ -303,7 +303,7 @@ public class ResourceAdapterTest extends ActiveMQRATestBase ActiveMQConnectionFactory factory = adapter.getDefaultActiveMQConnectionFactory(); long initWait = factory.getDiscoveryGroupConfiguration().getDiscoveryInitialWaitTimeout(); long refresh = factory.getDiscoveryGroupConfiguration().getRefreshTimeout(); - int port = ((UDPBroadcastGroupConfiguration) factory.getDiscoveryGroupConfiguration().getBroadcastEndpointFactoryConfiguration()).getGroupPort(); + int port = ((UDPBroadcastEndpointFactory) factory.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory()).getGroupPort(); // defaults assertEquals(10000L, refresh); @@ -445,7 +445,7 @@ public class ResourceAdapterTest extends ActiveMQRATestBase spec.setDestination(MDBQUEUE); ActiveMQConnectionFactory fac = qResourceAdapter.createActiveMQConnectionFactory(spec); DiscoveryGroupConfiguration dc = fac.getServerLocator().getDiscoveryGroupConfiguration(); - UDPBroadcastGroupConfiguration udpDg = (UDPBroadcastGroupConfiguration) dc.getBroadcastEndpointFactoryConfiguration(); + UDPBroadcastEndpointFactory udpDg = (UDPBroadcastEndpointFactory) dc.getBroadcastEndpointFactory(); assertEquals(udpDg.getGroupAddress(), "231.6.6.6"); assertEquals(udpDg.getGroupPort(), 1234); assertEquals(dc.getRefreshTimeout(), 1L); @@ -475,7 +475,7 @@ public class ResourceAdapterTest extends ActiveMQRATestBase spec.setDiscoveryRefreshTimeout(1L); ActiveMQConnectionFactory fac = qResourceAdapter.createActiveMQConnectionFactory(spec); DiscoveryGroupConfiguration dc = fac.getServerLocator().getDiscoveryGroupConfiguration(); - UDPBroadcastGroupConfiguration udpDg = (UDPBroadcastGroupConfiguration) dc.getBroadcastEndpointFactoryConfiguration(); + UDPBroadcastEndpointFactory udpDg = (UDPBroadcastEndpointFactory) dc.getBroadcastEndpointFactory(); assertEquals(udpDg.getGroupAddress(), "231.6.6.6"); assertEquals(udpDg.getGroupPort(), 1234); assertEquals(dc.getRefreshTimeout(), 1L); diff --git a/tests/jms-tests/src/test/resources/jndi.properties b/tests/jms-tests/src/test/resources/jndi.properties index 2bc4d9ccd9..ee3ad0e40b 100644 --- a/tests/jms-tests/src/test/resources/jndi.properties +++ b/tests/jms-tests/src/test/resources/jndi.properties @@ -13,4 +13,5 @@ # See the License for the specific language governing permissions and # limitations under the License. # -java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory \ No newline at end of file +java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory +connectionFactory.ConnectionFactory=vm://0 \ No newline at end of file diff --git a/tests/joram-tests/src/test/java/org/objectweb/jtests/jms/framework/PTPTestCase.java b/tests/joram-tests/src/test/java/org/objectweb/jtests/jms/framework/PTPTestCase.java index 7d72a3f0b8..d49d55e7b4 100644 --- a/tests/joram-tests/src/test/java/org/objectweb/jtests/jms/framework/PTPTestCase.java +++ b/tests/joram-tests/src/test/java/org/objectweb/jtests/jms/framework/PTPTestCase.java @@ -122,8 +122,7 @@ public abstract class PTPTestCase extends JMSTestCase Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getCanonicalName()); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, PTPTestCase.QCF_NAME); - props.put(Context.PROVIDER_URL, "tcp://127.0.0.1:5445"); + props.put("connectionFactory." + PTPTestCase.QCF_NAME, "tcp://127.0.0.1:5445?type=QUEUE_CF"); props.put("queue." + PTPTestCase.QUEUE_NAME, PTPTestCase.QUEUE_NAME); Context ctx = new InitialContext(props); diff --git a/tests/joram-tests/src/test/java/org/objectweb/jtests/jms/framework/PubSubTestCase.java b/tests/joram-tests/src/test/java/org/objectweb/jtests/jms/framework/PubSubTestCase.java index fa0282be49..8f6666b909 100644 --- a/tests/joram-tests/src/test/java/org/objectweb/jtests/jms/framework/PubSubTestCase.java +++ b/tests/joram-tests/src/test/java/org/objectweb/jtests/jms/framework/PubSubTestCase.java @@ -122,8 +122,7 @@ public abstract class PubSubTestCase extends JMSTestCase Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getCanonicalName()); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, PubSubTestCase.TCF_NAME); - props.put(Context.PROVIDER_URL, "tcp://127.0.0.1:5445"); + props.put("connectionFactory." + PubSubTestCase.TCF_NAME, "tcp://127.0.0.1:5445?type=TOPIC_CF"); props.put("topic." + PubSubTestCase.TOPIC_NAME, PubSubTestCase.TOPIC_NAME); Context ctx = new InitialContext(props); diff --git a/tests/joram-tests/src/test/java/org/objectweb/jtests/jms/framework/UnifiedTestCase.java b/tests/joram-tests/src/test/java/org/objectweb/jtests/jms/framework/UnifiedTestCase.java index 3264bd5c6b..70d4b5b9a8 100644 --- a/tests/joram-tests/src/test/java/org/objectweb/jtests/jms/framework/UnifiedTestCase.java +++ b/tests/joram-tests/src/test/java/org/objectweb/jtests/jms/framework/UnifiedTestCase.java @@ -171,8 +171,9 @@ public abstract class UnifiedTestCase extends JMSTestCase Hashtable props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getCanonicalName()); - props.put(ActiveMQInitialContextFactory.CONNECTION_FACTORY_NAMES, UnifiedTestCase.CF_NAME + ", " + UnifiedTestCase.QCF_NAME + ", " + UnifiedTestCase.TCF_NAME); - props.put(Context.PROVIDER_URL, "tcp://127.0.0.1:5445"); + props.put("connectionFactory." + UnifiedTestCase.CF_NAME, "tcp://127.0.0.1:5445"); + props.put("connectionFactory." + UnifiedTestCase.QCF_NAME, "tcp://127.0.0.1:5445?type=QUEUE_CF"); + props.put("connectionFactory." + UnifiedTestCase.TCF_NAME, "tcp://127.0.0.1:5445?type=TOPIC_CF"); props.put("queue." + UnifiedTestCase.DESTINATION_NAME, UnifiedTestCase.DESTINATION_NAME); props.put("queue." + UnifiedTestCase.QUEUE_NAME, UnifiedTestCase.QUEUE_NAME); props.put("topic." + UnifiedTestCase.TOPIC_NAME, UnifiedTestCase.TOPIC_NAME); diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/ra/ResourceAdapterTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/ra/ResourceAdapterTest.java index 3d524e89a2..3d1a720e58 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/ra/ResourceAdapterTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/ra/ResourceAdapterTest.java @@ -23,7 +23,7 @@ import java.util.Map; import org.apache.activemq.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.api.core.TransportConfiguration; -import org.apache.activemq.api.core.UDPBroadcastGroupConfiguration; +import org.apache.activemq.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.api.core.client.ClientSession; import org.apache.activemq.api.core.client.ClientSessionFactory; import org.apache.activemq.api.core.client.ActiveMQClient; @@ -279,7 +279,7 @@ public class ResourceAdapterTest extends ServiceTestBase ActiveMQConnectionFactory defaultFactory = ra.getDefaultActiveMQConnectionFactory(); Assert.assertNotSame(factory, defaultFactory); DiscoveryGroupConfiguration dc = factory.getServerLocator().getDiscoveryGroupConfiguration(); - UDPBroadcastGroupConfiguration udpDg = (UDPBroadcastGroupConfiguration) dc.getBroadcastEndpointFactoryConfiguration(); + UDPBroadcastEndpointFactory udpDg = (UDPBroadcastEndpointFactory) dc.getBroadcastEndpointFactory(); Assert.assertEquals(udpDg.getLocalBindAddress(), "newAddress"); Assert.assertEquals(udpDg.getGroupAddress(), "myhost"); Assert.assertEquals(udpDg.getGroupPort(), 5678);