Clover Coverage Report - JmDNS 3.4.1
Coverage timestamp: Thu Aug 25 2011 13:06:33 CEST
../../../../../img/srcFileCovDistChart7.png 18% of files have more coverage
12   77   6   2.4
2   39   0.5   5
5     1.2  
1    
 
  ServiceResolver       Line # 23 12 0% 6 6 68.4% 0.68421054
 
  (17)
 
1    // Copyright 2003-2005 Arthur van Hoff, Rick Blair
2    // Licensed under Apache License version 2.0
3    // Original license LGPL
4   
5    package javax.jmdns.impl.tasks.resolver;
6   
7    import java.io.IOException;
8   
9    import javax.jmdns.ServiceInfo;
10    import javax.jmdns.impl.DNSOutgoing;
11    import javax.jmdns.impl.DNSQuestion;
12    import javax.jmdns.impl.DNSRecord;
13    import javax.jmdns.impl.JmDNSImpl;
14    import javax.jmdns.impl.constants.DNSConstants;
15    import javax.jmdns.impl.constants.DNSRecordClass;
16    import javax.jmdns.impl.constants.DNSRecordType;
17   
18    /**
19    * The ServiceResolver queries three times consecutively for services of a given type, and then removes itself from the timer.
20    * <p/>
21    * The ServiceResolver will run only if JmDNS is in state ANNOUNCED. REMIND: Prevent having multiple service resolvers for the same type in the timer queue.
22    */
 
23    public class ServiceResolver extends DNSResolverTask {
24   
25    private final String _type;
26   
 
27  28 toggle public ServiceResolver(JmDNSImpl jmDNSImpl, String type) {
28  28 super(jmDNSImpl);
29  28 this._type = type;
30    }
31   
32    /*
33    * (non-Javadoc)
34    * @see javax.jmdns.impl.tasks.DNSTask#getName()
35    */
 
36  0 toggle @Override
37    public String getName() {
38  0 return "ServiceResolver(" + (this.getDns() != null ? this.getDns().getName() : "") + ")";
39    }
40   
41    /*
42    * (non-Javadoc)
43    * @see javax.jmdns.impl.tasks.Resolver#addAnswers(javax.jmdns.impl.DNSOutgoing)
44    */
 
45  33 toggle @Override
46    protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException {
47  33 DNSOutgoing newOut = out;
48  33 long now = System.currentTimeMillis();
49  33 for (ServiceInfo info : this.getDns().getServices().values()) {
50  18 newOut = this.addAnswer(newOut, new DNSRecord.Pointer(info.getType(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getQualifiedName()), now);
51    // newOut = this.addAnswer(newOut, new DNSRecord.Service(info.getQualifiedName(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getPriority(), info.getWeight(), info.getPort(),
52    // this.getDns().getLocalHost().getName()), now);
53    }
54  33 return newOut;
55    }
56   
57    /*
58    * (non-Javadoc)
59    * @see javax.jmdns.impl.tasks.Resolver#addQuestions(javax.jmdns.impl.DNSOutgoing)
60    */
 
61  81 toggle @Override
62    protected DNSOutgoing addQuestions(DNSOutgoing out) throws IOException {
63  81 DNSOutgoing newOut = out;
64  81 newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_type, DNSRecordType.TYPE_PTR, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
65    // newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_type, DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
66  81 return newOut;
67    }
68   
69    /*
70    * (non-Javadoc)
71    * @see javax.jmdns.impl.tasks.Resolver#description()
72    */
 
73  0 toggle @Override
74    protected String description() {
75  0 return "querying service";
76    }
77    }