make the agent more resilient to ordering; whether a service is registered before starting or started first etc. We seem to have both in our code base

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@357017 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2005-12-15 14:13:14 +00:00
parent 639265de9f
commit db0855c342
1 changed files with 7 additions and 8 deletions

View File

@ -75,9 +75,8 @@ public class RendezvousDiscoveryAgent implements DiscoveryAgent, ServiceListener
type += "."; type += ".";
} }
try { try {
if (jmdns == null) { // force lazy construction
jmdns = createJmDNS(); getJmdns();
}
if (listener!=null) { if (listener!=null) {
log.info("Discovering service of type: " +type); log.info("Discovering service of type: " +type);
jmdns.addServiceListener(type, this); jmdns.addServiceListener(type, this);
@ -111,12 +110,9 @@ public class RendezvousDiscoveryAgent implements DiscoveryAgent, ServiceListener
} }
public void registerService(String name) throws IOException { public void registerService(String name) throws IOException {
if (jmdns == null) {
throw new IllegalStateException("Not started.");
}
ServiceInfo si = createServiceInfo(name, new HashMap()); ServiceInfo si = createServiceInfo(name, new HashMap());
serviceInfos.add(si); serviceInfos.add(si);
jmdns.registerService(si); getJmdns().registerService(si);
} }
@ -166,7 +162,10 @@ public class RendezvousDiscoveryAgent implements DiscoveryAgent, ServiceListener
this.weight = weight; this.weight = weight;
} }
public JmDNS getJmdns() { public JmDNS getJmdns() throws IOException {
if (jmdns == null) {
jmdns = createJmDNS();
}
return jmdns; return jmdns;
} }