Exemplo n.º 1
0
 public void run() {
   try {
     if (this.jmDNSImpl.getState() == DNSState.ANNOUNCED) {
       if (count++ < 3) {
         logger.finer("run() JmDNS querying service");
         long now = System.currentTimeMillis();
         DNSOutgoing out = new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY);
         out.addQuestion(new DNSQuestion(type, DNSConstants.TYPE_PTR, DNSConstants.CLASS_IN));
         for (Iterator s = this.jmDNSImpl.getServices().values().iterator(); s.hasNext(); ) {
           final ServiceInfoImpl info = (ServiceInfoImpl) s.next();
           try {
             out.addAnswer(
                 new DNSRecord.Pointer(
                     info.getType(),
                     DNSConstants.TYPE_PTR,
                     DNSConstants.CLASS_IN,
                     DNSConstants.DNS_TTL,
                     info.getQualifiedName()),
                 now);
           } catch (IOException ee) {
             break;
           }
         }
         this.jmDNSImpl.send(out);
       } else {
         // After three queries, we can quit.
         this.cancel();
       }
     } else {
       if (this.jmDNSImpl.getState() == DNSState.CANCELED) {
         this.cancel();
       }
     }
   } catch (Throwable e) {
     logger.log(Level.WARNING, "run() exception ", e);
     this.jmDNSImpl.recover();
   }
 }
Exemplo n.º 2
0
 @Override
 public void run() {
   try {
     if (this._jmDNSImpl.getState() == DNSState.ANNOUNCED) {
       if (_count++ < 3 && !_info.hasData()) {
         long now = System.currentTimeMillis();
         DNSOutgoing out = new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY);
         out.addQuestion(
             DNSQuestion.newQuestion(
                 _info.getQualifiedName(),
                 DNSRecordType.TYPE_SRV,
                 DNSRecordClass.CLASS_IN,
                 DNSRecordClass.NOT_UNIQUE));
         out.addQuestion(
             DNSQuestion.newQuestion(
                 _info.getQualifiedName(),
                 DNSRecordType.TYPE_TXT,
                 DNSRecordClass.CLASS_IN,
                 DNSRecordClass.NOT_UNIQUE));
         if (_info.getServer() != null) {
           out.addQuestion(
               DNSQuestion.newQuestion(
                   _info.getServer(),
                   DNSRecordType.TYPE_A,
                   DNSRecordClass.CLASS_IN,
                   DNSRecordClass.NOT_UNIQUE));
           out.addQuestion(
               DNSQuestion.newQuestion(
                   _info.getServer(),
                   DNSRecordType.TYPE_AAAA,
                   DNSRecordClass.CLASS_IN,
                   DNSRecordClass.NOT_UNIQUE));
         }
         out.addAnswer(
             (DNSRecord)
                 this._jmDNSImpl
                     .getCache()
                     .getDNSEntry(
                         _info.getQualifiedName(),
                         DNSRecordType.TYPE_SRV,
                         DNSRecordClass.CLASS_IN),
             now);
         out.addAnswer(
             (DNSRecord)
                 this._jmDNSImpl
                     .getCache()
                     .getDNSEntry(
                         _info.getQualifiedName(),
                         DNSRecordType.TYPE_TXT,
                         DNSRecordClass.CLASS_IN),
             now);
         if (_info.getServer() != null) {
           out.addAnswer(
               (DNSRecord)
                   this._jmDNSImpl
                       .getCache()
                       .getDNSEntry(
                           _info.getServer(), DNSRecordType.TYPE_A, DNSRecordClass.CLASS_IN),
               now);
           out.addAnswer(
               (DNSRecord)
                   this._jmDNSImpl
                       .getCache()
                       .getDNSEntry(
                           _info.getServer(), DNSRecordType.TYPE_AAAA, DNSRecordClass.CLASS_IN),
               now);
         }
         this._jmDNSImpl.send(out);
       } else {
         // After three queries, we can quit.
         this.cancel();
         this._jmDNSImpl.removeListener(_info);
       }
     } else {
       if (this._jmDNSImpl.getState() == DNSState.CANCELED) {
         this.cancel();
         this._jmDNSImpl.removeListener(_info);
       }
     }
   } catch (Throwable e) {
     logger.log(Level.WARNING, "run() exception ", e);
     this._jmDNSImpl.recover();
   }
 }