@Override public void init() { if(log.isDebugEnabled()) { log.debug("Initialize responder by browsing DNSSD"); } super.init(); try { for(String protocol : this.getServiceTypes()) { if(log.isInfoEnabled()) { log.info(String.format("Adding service listener for %s", protocol)); } browsers.put(protocol, DNSSD.browse(protocol, this)); } } catch(DNSSDException e) { log.error(String.format("Failure initializing Bonjour discovery: %s", e.getMessage()), e); this.quit(); } }
@Override public void quit() { for(String protocol : this.getServiceTypes()) { if(log.isInfoEnabled()) { log.info(String.format("Removing service listener for %s", protocol)); } final DNSSDService service = browsers.get(protocol); if(null == service) { continue; } service.stop(); } super.quit(); }
@Override public void serviceLost(final DNSSDService browser, final int flags, final int ifIndex, final String serviceName, final String regType, final String domain) { if(log.isDebugEnabled()) { log.debug(String.format("Service lost for %s", serviceName)); } final ActionOperationBatcher autorelease = ActionOperationBatcherFactory.get(); try { final String identifier = DNSSD.constructFullName(serviceName, regType, domain); this.remove(identifier); } catch(DNSSDException e) { log.error(String.format("Failure removing service %s: %s", serviceName, e.getMessage()), e); } finally { autorelease.operate(); } }
path = txtRecord.getValueAsString("path"); this.add(fullname, hostname, port, user, password, path);