コード例 #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();
   }
 }
コード例 #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();
   }
 }
コード例 #3
0
ファイル: Prober.java プロジェクト: jimlowder/android-munich
  public void run() {
    synchronized (this.jmDNSImpl.getIoLock()) {
      DNSOutgoing out = null;
      try {
        // send probes for JmDNS itself
        if (this.jmDNSImpl.getState() == taskState && this.jmDNSImpl.getTask() == this) {
          if (out == null) {
            out = new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY);
          }
          out.addQuestion(
              new DNSQuestion(
                  this.jmDNSImpl.getLocalHost().getName(),
                  DNSConstants.TYPE_ANY,
                  DNSConstants.CLASS_IN));

          this.jmDNSImpl.getLocalHost().addAddressRecords(out, true);
          this.jmDNSImpl.advanceState();
        }
        // send probes for services
        // Defensively copy the services into a local list,
        // to prevent race conditions with methods registerService
        // and unregisterService.
        List list;
        synchronized (this.jmDNSImpl) {
          list = new LinkedList(this.jmDNSImpl.getServices().values());
        }
        for (Iterator i = list.iterator(); i.hasNext(); ) {
          ServiceInfoImpl info = (ServiceInfoImpl) i.next();

          synchronized (info) {
            if (info.getState() == taskState && info.getTask() == this) {
              info.advanceState();
              if (out == null) {
                out = new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY);
                out.addQuestion(
                    new DNSQuestion(
                        info.getQualifiedName(), DNSConstants.TYPE_ANY, DNSConstants.CLASS_IN));
              }
              // the "unique" flag should be not set here because these
              // answers haven't been proven unique yet
              // this means the record will not exactly match the
              // announcement record
              out.addAuthorativeAnswer(
                  new DNSRecord.Service(
                      info.getQualifiedName(),
                      DNSConstants.TYPE_SRV,
                      DNSConstants.CLASS_IN,
                      DNSConstants.DNS_TTL,
                      info.getPriority(),
                      info.getWeight(),
                      info.getPort(),
                      this.jmDNSImpl.getLocalHost().getName()));
            }
          }
        }
        if (out != null) {
          this.jmDNSImpl.send(out);
        } else {
          // If we have nothing to send, another timer taskState ahead
          // of us has done the job for us. We can cancel.
          cancel();
          return;
        }
      } catch (Throwable e) {
        this.jmDNSImpl.recover();
      }

      taskState = taskState.advance();
      if (!taskState.isProbing()) {
        cancel();

        this.jmDNSImpl.startAnnouncer();
      }
    }
  }