mirror of https://github.com/apache/activemq.git
Apply patch for https://issues.apache.org/activemq/browse/AMQ-1489
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@692340 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a881781aaf
commit
78aac70bff
|
@ -49,6 +49,11 @@ import org.apache.commons.logging.LogFactory;
|
|||
public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable {
|
||||
|
||||
public static final String DEFAULT_DISCOVERY_URI_STRING = "multicast://239.255.2.3:6155";
|
||||
public static final String DEFAULT_HOST_STR = "default";
|
||||
public static final String DEFAULT_HOST_IP = "239.255.2.3";
|
||||
public static final int DEFAULT_PORT = 6155;
|
||||
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(MulticastDiscoveryAgent.class);
|
||||
private static final String TYPE_SUFFIX = "ActiveMQ-4.";
|
||||
private static final String ALIVE = "alive.";
|
||||
|
@ -257,7 +262,9 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable {
|
|||
* @throws Exception
|
||||
*/
|
||||
public void start() throws Exception {
|
||||
if (started.compareAndSet(false, true)) {
|
||||
|
||||
if (started.compareAndSet(false, true)) {
|
||||
|
||||
if (group == null || group.length() == 0) {
|
||||
throw new IOException("You must specify a group to discover");
|
||||
}
|
||||
|
@ -266,12 +273,33 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable {
|
|||
LOG.warn("The type '" + type + "' should end with '.' to be a valid Discovery type");
|
||||
type += ".";
|
||||
}
|
||||
|
||||
if (discoveryURI == null) {
|
||||
discoveryURI = new URI(DEFAULT_DISCOVERY_URI_STRING);
|
||||
}
|
||||
this.inetAddress = InetAddress.getByName(discoveryURI.getHost());
|
||||
this.sockAddress = new InetSocketAddress(this.inetAddress, discoveryURI.getPort());
|
||||
mcast = new MulticastSocket(discoveryURI.getPort());
|
||||
|
||||
if (LOG.isTraceEnabled())
|
||||
LOG.trace("start - discoveryURI = " + discoveryURI);
|
||||
|
||||
String myHost = discoveryURI.getHost();
|
||||
int myPort = discoveryURI.getPort();
|
||||
|
||||
if( DEFAULT_HOST_STR.equals(myHost) )
|
||||
myHost = DEFAULT_HOST_IP;
|
||||
|
||||
if(myPort < 0 )
|
||||
myPort = DEFAULT_PORT;
|
||||
|
||||
if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("start - myHost = " + myHost);
|
||||
LOG.trace("start - myPort = " + myPort);
|
||||
LOG.trace("start - myHost = " + myHost);
|
||||
LOG.trace("start - group = " + group );
|
||||
}
|
||||
|
||||
this.inetAddress = InetAddress.getByName(myHost);
|
||||
this.sockAddress = new InetSocketAddress(this.inetAddress, myPort);
|
||||
mcast = new MulticastSocket(myPort);
|
||||
mcast.setLoopbackMode(loopBackMode);
|
||||
mcast.setTimeToLive(getTimeToLive());
|
||||
mcast.joinGroup(inetAddress);
|
||||
|
|
|
@ -25,25 +25,31 @@ import org.apache.activemq.transport.discovery.DiscoveryAgentFactory;
|
|||
import org.apache.activemq.util.IOExceptionSupport;
|
||||
import org.apache.activemq.util.IntrospectionSupport;
|
||||
import org.apache.activemq.util.URISupport;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class MulticastDiscoveryAgentFactory extends DiscoveryAgentFactory {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(MulticastDiscoveryAgentFactory.class);
|
||||
|
||||
//See AMQ-1489. There's something wrong here but it is difficult to tell what.
|
||||
//It looks like to actually set the discovery URI you have to use something like
|
||||
//<transportConnector uri="..." discoveryUri="multicast://239.3.7.0:37000?discoveryURI=multicast://239.3.7.0:37000" />
|
||||
// or
|
||||
//<networkConnector name="..." uri="multicast://239.3.7.0:37000?discoveryURI=multicast://239.3.7.0:37000">
|
||||
|
||||
protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException {
|
||||
try {
|
||||
|
||||
if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("doCreateDiscoveryAgent: uri = " + uri.toString());
|
||||
}
|
||||
|
||||
Map options = URISupport.parseParamters(uri);
|
||||
MulticastDiscoveryAgent rc = new MulticastDiscoveryAgent();
|
||||
rc.setGroup(uri.getHost());
|
||||
|
||||
// allow the discoveryURI to be set via a query argument on the URI
|
||||
// ?discoveryURI=someURI
|
||||
IntrospectionSupport.setProperties(rc, options);
|
||||
return rc;
|
||||
MulticastDiscoveryAgent mda = new MulticastDiscoveryAgent();
|
||||
|
||||
mda.setDiscoveryURI(uri);
|
||||
|
||||
// allow MDA's params to be set via query arguments
|
||||
// (e.g., multicast://default?group=foo
|
||||
Map options = URISupport.parseParamters(uri);
|
||||
IntrospectionSupport.setProperties(mda, options);
|
||||
|
||||
return mda;
|
||||
|
||||
} catch (Throwable e) {
|
||||
throw IOExceptionSupport.create("Could not create discovery agent: " + uri, e);
|
||||
|
|
Loading…
Reference in New Issue