コード例 #1
0
 @Override
 public void inetAddressAdded(NetworkTopologyEvent nte) {
   if (nte.getInetAddress() instanceof Inet6Address
       && !ProfileUtils.getPreferences(
               ProfileManager.getDefault().getActiveProfile(), ZeroConfService.class, false)
           .getBoolean(ZeroConfService.IPv6, true)) {
     log.debug("Ignoring IPv6 address {}", nte.getInetAddress().getHostAddress());
     return;
   }
   if (nte.getInetAddress() instanceof Inet4Address
       && !ProfileUtils.getPreferences(
               ProfileManager.getDefault().getActiveProfile(), ZeroConfService.class, false)
           .getBoolean(ZeroConfService.IPv4, true)) {
     log.debug("Ignoring IPv4 address {}", nte.getInetAddress().getHostAddress());
     return;
   }
   if (!ZeroConfService.netServices.containsKey(nte.getInetAddress())) {
     log.debug("Adding address {}", nte.getInetAddress().getHostAddress());
     ZeroConfService.netServices.put(nte.getInetAddress(), nte.getDNS());
     ZeroConfService.allServices()
         .stream()
         .forEach(
             (service) -> {
               try {
                 if (!service.serviceInfos.containsKey(nte.getDNS().getInetAddress())) {
                   log.debug(
                       "Publishing zeroConf service for '{}' on {}",
                       service.key(),
                       nte.getInetAddress().getHostAddress());
                   nte.getDNS().registerService(service.addServiceInfo(nte.getDNS()));
                   service
                       .listeners
                       .stream()
                       .forEach(
                           (listener) -> {
                             listener.servicePublished(
                                 new ZeroConfServiceEvent(service, nte.getDNS()));
                           });
                 }
               } catch (IOException ex) {
                 log.error(ex.getLocalizedMessage(), ex);
               }
             });
   } else {
     log.debug("Address {} already known.", nte.getInetAddress().getHostAddress());
   }
 }
コード例 #2
0
 @Override
 public void inetAddressRemoved(NetworkTopologyEvent nte) {
   log.debug("Removing address {}", nte.getInetAddress().toString());
   ZeroConfService.netServices.remove(nte.getInetAddress());
   nte.getDNS().unregisterAllServices();
   ZeroConfService.allServices()
       .stream()
       .map(
           (service) -> {
             service.serviceInfos.remove(nte.getInetAddress());
             return service;
           })
       .forEach(
           (service) -> {
             service
                 .listeners
                 .stream()
                 .forEach(
                     (listener) -> {
                       listener.servicePublished(
                           new ZeroConfServiceEvent(service, nte.getDNS()));
                     });
           });
 }