Clover Coverage Report - JmDNS 3.4.1
Coverage timestamp: Thu Aug 25 2011 13:06:33 CEST
../../../../../img/srcFileCovDistChart5.png 47% of files have more coverage
27   102   13   4.5
14   60   0.48   6
6     2.17  
1    
 
  ServiceInfoResolver       Line # 22 27 0% 13 25 46.8% 0.4680851
 
  (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.impl.DNSOutgoing;
10    import javax.jmdns.impl.DNSQuestion;
11    import javax.jmdns.impl.DNSRecord;
12    import javax.jmdns.impl.JmDNSImpl;
13    import javax.jmdns.impl.ServiceInfoImpl;
14    import javax.jmdns.impl.constants.DNSRecordClass;
15    import javax.jmdns.impl.constants.DNSRecordType;
16   
17    /**
18    * The ServiceInfoResolver queries up to three times consecutively for a service info, and then removes itself from the timer.
19    * <p/>
20    * The ServiceInfoResolver will run only if JmDNS is in state ANNOUNCED. REMIND: Prevent having multiple service resolvers for the same info in the timer queue.
21    */
 
22    public class ServiceInfoResolver extends DNSResolverTask {
23   
24    private final ServiceInfoImpl _info;
25   
 
26  21 toggle public ServiceInfoResolver(JmDNSImpl jmDNSImpl, ServiceInfoImpl info) {
27  21 super(jmDNSImpl);
28  21 this._info = info;
29  21 info.setDns(this.getDns());
30  21 this.getDns().addListener(info, DNSQuestion.newQuestion(info.getQualifiedName(), DNSRecordType.TYPE_ANY, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
31    }
32   
33    /*
34    * (non-Javadoc)
35    * @see javax.jmdns.impl.tasks.DNSTask#getName()
36    */
 
37  0 toggle @Override
38    public String getName() {
39  0 return "ServiceInfoResolver(" + (this.getDns() != null ? this.getDns().getName() : "") + ")";
40    }
41   
42    /*
43    * (non-Javadoc)
44    * @see java.util.TimerTask#cancel()
45    */
 
46  18 toggle @Override
47    public boolean cancel() {
48    // We should not forget to remove the listener
49  18 boolean result = super.cancel();
50  18 if (!_info.isPersistent()) {
51  2 this.getDns().removeListener(_info);
52    }
53  18 return result;
54    }
55   
56    /*
57    * (non-Javadoc)
58    * @see javax.jmdns.impl.tasks.Resolver#addAnswers(javax.jmdns.impl.DNSOutgoing)
59    */
 
60  54 toggle @Override
61    protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException {
62  54 DNSOutgoing newOut = out;
63  54 if (!_info.hasData()) {
64  0 long now = System.currentTimeMillis();
65  0 newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getQualifiedName(), DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN), now);
66  0 newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getQualifiedName(), DNSRecordType.TYPE_TXT, DNSRecordClass.CLASS_IN), now);
67  0 if (_info.getServer().length() > 0) {
68  0 newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getServer(), DNSRecordType.TYPE_A, DNSRecordClass.CLASS_IN), now);
69  0 newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getServer(), DNSRecordType.TYPE_AAAA, DNSRecordClass.CLASS_IN), now);
70    }
71    }
72  54 return newOut;
73    }
74   
75    /*
76    * (non-Javadoc)
77    * @see javax.jmdns.impl.tasks.Resolver#addQuestions(javax.jmdns.impl.DNSOutgoing)
78    */
 
79  54 toggle @Override
80    protected DNSOutgoing addQuestions(DNSOutgoing out) throws IOException {
81  54 DNSOutgoing newOut = out;
82  54 if (!_info.hasData()) {
83  0 newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getQualifiedName(), DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
84  0 newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getQualifiedName(), DNSRecordType.TYPE_TXT, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
85  0 if (_info.getServer().length() > 0) {
86  0 newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getServer(), DNSRecordType.TYPE_A, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
87  0 newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getServer(), DNSRecordType.TYPE_AAAA, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
88    }
89    }
90  54 return newOut;
91    }
92   
93    /*
94    * (non-Javadoc)
95    * @see javax.jmdns.impl.tasks.Resolver#description()
96    */
 
97  0 toggle @Override
98    protected String description() {
99  0 return "querying service info: " + (_info != null ? _info.getQualifiedName() : "null");
100    }
101   
102    }