public DNSMultiCast(Jenkins hudson) { if (disabled) return; // escape hatch 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(Jenkins.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())); props.put("server-id", Util.getDigestOf(hudson.getSecretKey())); URL jenkins_url = new URL(rootURL); int jenkins_port = jenkins_url.getPort(); if (jenkins_port == -1) { jenkins_port = 80; } if (jenkins_url.getPath().length() > 0) { props.put("path", jenkins_url.getPath()); } jmdns.registerService( ServiceInfo.create( "_hudson._tcp.local.", "hudson", jenkins_port, 0, 0, props)); // for backward compatibility jmdns.registerService( ServiceInfo.create("_jenkins._tcp.local.", "jenkins", jenkins_port, 0, 0, props)); // Make Jenkins appear in Safari's Bonjour bookmarks jmdns.registerService( ServiceInfo.create("_http._tcp.local.", "Jenkins", jenkins_port, 0, 0, props)); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to advertise the service to DNS multi-cast", e); } }