コード例 #1
0
 /** Stop advertising the service. */
 public void stop() {
   log.debug("Stopping ZeroConfService {}", this.key());
   if (ZeroConfService.services().containsKey(this.key())) {
     ZeroConfService.netServices()
         .values()
         .stream()
         .forEach(
             (netService) -> {
               try {
                 try {
                   log.debug("Unregistering {} from {}", this.key(), netService.getInetAddress());
                   netService.unregisterService(
                       this.serviceInfos.get(netService.getInetAddress()));
                   this.serviceInfos.remove(netService.getInetAddress());
                   this.listeners
                       .stream()
                       .forEach(
                           (listener) -> {
                             listener.serviceUnpublished(
                                 new ZeroConfServiceEvent(this, netService));
                           });
                 } catch (NullPointerException ex) {
                   log.debug(
                       "{} already unregistered from {}", this.key(), netService.getInetAddress());
                 }
               } catch (IOException ex) {
                 log.error(
                     "Unable to stop ZeroConfService {}. {}",
                     this.key(),
                     ex.getLocalizedMessage());
               }
             });
     ZeroConfService.services().remove(key());
   }
 }
コード例 #2
0
 /**
  * Create a ZeroConfService. The property <i>version</i> is added or replaced with the current
  * JMRI version as its value. The property <i>jmri</i> is added or replaced with the JMRI
  * major.minor.test version string as its value.
  *
  * <p>If a service with the same key as the new service is already published, the original service
  * is returned unmodified.
  *
  * @param type The service protocol
  * @param name The name of the JMRI server listed on client devices
  * @param port The port the service runs over
  * @param weight Default value is 0
  * @param priority Default value is 0
  * @param properties Additional information to be listed in service advertisement
  * @return An unpublished ZeroConfService
  */
 public static ZeroConfService create(
     String type,
     String name,
     int port,
     int weight,
     int priority,
     HashMap<String, String> properties) {
   ZeroConfService s;
   if (ZeroConfService.services().containsKey(ZeroConfService.key(type, name))) {
     s = ZeroConfService.services().get(ZeroConfService.key(type, name));
     log.debug("Using existing ZeroConfService {}", s.key());
   } else {
     properties.put("version", jmri.Version.name());
     // use the major.minor.test version string for jmri since we have potentially
     // tight space constraints in terms of the number of bytes that properties
     // can use, and there are some unconstrained properties that we would like to use.
     properties.put("jmri", jmri.Version.getCanonicalVersion());
     properties.put("node", NodeIdentity.identity());
     s = new ZeroConfService(ServiceInfo.create(type, name, port, weight, priority, properties));
     log.debug("Creating new ZeroConfService {} with properties {}", s.key(), properties);
   }
   return s;
 }
コード例 #3
0
 private static void stopAll(final boolean close) {
   log.debug("Stopping all ZeroConfServices");
   ZeroConfService.netServices()
       .values()
       .stream()
       .forEach(
           (netService) -> {
             new Thread() {
               @Override
               public void run() {
                 netService.unregisterAllServices();
                 if (close) {
                   try {
                     netService.close();
                   } catch (IOException ex) {
                     log.debug("jmdns.close() returned IOException: {}", ex.getMessage());
                   }
                 }
               }
             }.start();
           });
   ZeroConfService.services().clear();
 }
コード例 #4
0
 /**
  * A list of published ZeroConfServices
  *
  * @return Collection of ZeroConfServices
  */
 public static Collection<ZeroConfService> allServices() {
   return ZeroConfService.services().values();
 }
コード例 #5
0
 /**
  * Get the state of the service.
  *
  * @return True if the service is being advertised, and false otherwise.
  */
 public Boolean isPublished() {
   return ZeroConfService.services().containsKey(key());
 }