mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 05:52:26 +00:00
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@31436 71c3de6d-444a-0410-be80-ed276b4c234a
56 lines
1.6 KiB
Java
56 lines
1.6 KiB
Java
package hudson;
|
|
|
|
import hudson.model.Hudson;
|
|
|
|
import javax.jmdns.JmDNS;
|
|
import javax.jmdns.ServiceInfo;
|
|
import java.io.Closeable;
|
|
import java.io.IOException;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
|
|
/**
|
|
* Registers a DNS multi-cast service-discovery support.
|
|
*
|
|
* @author Kohsuke Kawaguchi
|
|
*/
|
|
public class DNSMultiCast implements Closeable {
|
|
private JmDNS jmdns;
|
|
|
|
public DNSMultiCast(Hudson hudson) {
|
|
try {
|
|
this.jmdns = JmDNS.create();
|
|
|
|
Map<String,String> props = new HashMap<String, String>();
|
|
String rootURL = hudson.getRootUrl();
|
|
if (rootURL!=null)
|
|
props.put("url", rootURL);
|
|
try {
|
|
props.put("version",String.valueOf(Hudson.getVersion()));
|
|
} catch (IllegalArgumentException e) {
|
|
// failed to parse the version number
|
|
}
|
|
|
|
TcpSlaveAgentListener tal = hudson.getTcpSlaveAgentListener();
|
|
if (tal!=null)
|
|
props.put("slave-port",String.valueOf(tal.getPort()));
|
|
|
|
jmdns.registerService(ServiceInfo.create("_hudson._tcp.local.","hudson",
|
|
80,0,0,props));
|
|
} catch (IOException e) {
|
|
LOGGER.log(Level.WARNING,"Failed to advertise the service to DNS multi-cast",e);
|
|
}
|
|
}
|
|
|
|
public void close() {
|
|
if (jmdns!=null) {
|
|
jmdns.close();
|
|
jmdns = null;
|
|
}
|
|
}
|
|
|
|
private static final Logger LOGGER = Logger.getLogger(DNSMultiCast.class.getName());
|
|
}
|