new method to create ServerLocator

This commit is contained in:
Clebert Suconic 2015-08-05 09:22:41 -04:00
parent 896813fc1c
commit ee84d7efdf
2 changed files with 30 additions and 2 deletions

View File

@ -19,6 +19,7 @@ package org.apache.activemq.artemis.core.client.impl;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.net.URI;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
@ -48,6 +49,7 @@ import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.api.core.client.ActiveMQClient; import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory; import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
import org.apache.activemq.artemis.api.core.client.ClusterTopologyListener; import org.apache.activemq.artemis.api.core.client.ClusterTopologyListener;
import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.api.core.client.TopologyMember; import org.apache.activemq.artemis.api.core.client.TopologyMember;
import org.apache.activemq.artemis.api.core.client.loadbalance.ConnectionLoadBalancingPolicy; import org.apache.activemq.artemis.api.core.client.loadbalance.ConnectionLoadBalancingPolicy;
import org.apache.activemq.artemis.core.client.ActiveMQClientLogger; import org.apache.activemq.artemis.core.client.ActiveMQClientLogger;
@ -60,6 +62,7 @@ import org.apache.activemq.artemis.core.remoting.FailureListener;
import org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManager; import org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManagerFactory; import org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManagerFactory;
import org.apache.activemq.artemis.spi.core.remoting.Connector; import org.apache.activemq.artemis.spi.core.remoting.Connector;
import org.apache.activemq.artemis.uri.ServerLocatorParser;
import org.apache.activemq.artemis.utils.ActiveMQThreadFactory; import org.apache.activemq.artemis.utils.ActiveMQThreadFactory;
import org.apache.activemq.artemis.utils.ClassloadingUtil; import org.apache.activemq.artemis.utils.ClassloadingUtil;
import org.apache.activemq.artemis.utils.UUIDGenerator; import org.apache.activemq.artemis.utils.UUIDGenerator;
@ -471,6 +474,31 @@ public final class ServerLocatorImpl implements ServerLocatorInternal, Discovery
clusterConnection = false; clusterConnection = false;
} }
public static ServerLocator newLocator(String uri)
{
try
{
return newLocator(new URI(uri));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
public static ServerLocator newLocator(URI uri)
{
try
{
ServerLocatorParser parser = new ServerLocatorParser();
return parser.newObject(uri, null);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
/** /**
* Create a ServerLocatorImpl using UDP discovery to lookup cluster * Create a ServerLocatorImpl using UDP discovery to lookup cluster
*/ */

View File

@ -47,6 +47,7 @@ import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory; import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
import org.apache.activemq.artemis.api.core.client.ServerLocator; import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.api.jms.JMSFactoryType; import org.apache.activemq.artemis.api.jms.JMSFactoryType;
import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl;
import org.apache.activemq.artemis.jms.referenceable.ConnectionFactoryObjectFactory; import org.apache.activemq.artemis.jms.referenceable.ConnectionFactoryObjectFactory;
import org.apache.activemq.artemis.jms.referenceable.SerializableObjectRefAddr; import org.apache.activemq.artemis.jms.referenceable.SerializableObjectRefAddr;
import org.apache.activemq.artemis.uri.ConnectionFactoryParser; import org.apache.activemq.artemis.uri.ConnectionFactoryParser;
@ -162,11 +163,10 @@ public class ActiveMQConnectionFactory implements Externalizable, Referenceable,
public ActiveMQConnectionFactory(String url) public ActiveMQConnectionFactory(String url)
{ {
ConnectionFactoryParser cfParser = new ConnectionFactoryParser(); ConnectionFactoryParser cfParser = new ConnectionFactoryParser();
ServerLocatorParser locatorParser = new ServerLocatorParser();
try try
{ {
URI uri = new URI(url); URI uri = new URI(url);
serverLocator = locatorParser.newObject(uri, null); serverLocator = ServerLocatorImpl.newLocator(uri);
cfParser.populateObject(uri, this); cfParser.populateObject(uri, this);
} }
catch (Exception e) catch (Exception e)