|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ServiceInfoResolver | Line # 22 | 27 | 0% | 13 | 25 | 46.8% |
0.4680851
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (17) | |||
| Result | |||
|
0.4680851
|
javax.jmdns.test.JmDNSTest.testWaitAndQueryForServiceOnOtherRegistry
javax.jmdns.test.JmDNSTest.testWaitAndQueryForServiceOnOtherRegistry
|
1 PASS | |
|
0.44680852
|
javax.jmdns.test.JmDNSTest.testRegisterAndListServiceOnOtherRegistry
javax.jmdns.test.JmDNSTest.testRegisterAndListServiceOnOtherRegistry
|
1 PASS | |
|
0.42553192
|
javax.jmdns.test.JmDNSTest.testUnregisterService
javax.jmdns.test.JmDNSTest.testUnregisterService
|
1 PASS | |
|
0.42553192
|
javax.jmdns.test.TextUpdateTest.testSubtype
javax.jmdns.test.TextUpdateTest.testSubtype
|
1 PASS | |
|
0.42553192
|
javax.jmdns.test.TextUpdateTest.testListenForTextUpdateOnOtherRegistry
javax.jmdns.test.TextUpdateTest.testListenForTextUpdateOnOtherRegistry
|
1 PASS | |
|
0.42553192
|
javax.jmdns.test.TextUpdateTest.testRegisterCaseSensitiveField
javax.jmdns.test.TextUpdateTest.testRegisterCaseSensitiveField
|
1 PASS | |
|
0.42553192
|
javax.jmdns.test.JmDNSTest.testUnregisterAndReregisterService
javax.jmdns.test.JmDNSTest.testUnregisterAndReregisterService
|
1 PASS | |
|
0.42553192
|
javax.jmdns.test.JmDNSTest.testListMyServiceWithToLowerCase
javax.jmdns.test.JmDNSTest.testListMyServiceWithToLowerCase
|
1 PASS | |
|
0.42553192
|
javax.jmdns.test.JmDNSTest.testListMyService
javax.jmdns.test.JmDNSTest.testListMyService
|
1 PASS | |
|
0.42553192
|
javax.jmdns.test.TextUpdateTest.testRenewExpiringRequests
javax.jmdns.test.TextUpdateTest.testRenewExpiringRequests
|
1 PASS | |
|
0.42553192
|
javax.jmdns.test.TextUpdateTest.testRegisterEmptyTXTField
javax.jmdns.test.TextUpdateTest.testRegisterEmptyTXTField
|
1 PASS | |
|
0.42553192
|
javax.jmdns.test.JmDNSTest.testListMyServiceWithoutLowerCase
javax.jmdns.test.JmDNSTest.testListMyServiceWithoutLowerCase
|
1 PASS | |
|
0.42553192
|
javax.jmdns.test.JmDNSTest.testListenForMyServiceAndList
javax.jmdns.test.JmDNSTest.testListenForMyServiceAndList
|
1 PASS | |
|
0.42553192
|
javax.jmdns.test.JmDNSTest.testListMyServiceIPV6
javax.jmdns.test.JmDNSTest.testListMyServiceIPV6
|
1 PASS | |
|
0.42553192
|
javax.jmdns.test.JmDNSTest.testListenForMyService
javax.jmdns.test.JmDNSTest.testListenForMyService
|
1 PASS | |
|
0.42553192
|
javax.jmdns.test.JmDNSTest.testListenForServiceOnOtherRegistry
javax.jmdns.test.JmDNSTest.testListenForServiceOnOtherRegistry
|
1 PASS | |
|
0.10638298
|
javax.jmdns.test.JmDNSTest.testQueryMyService
javax.jmdns.test.JmDNSTest.testQueryMyService
|
1 PASS | |
| 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 |
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 |
@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 |
@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 |
@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 |
@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 |
@Override |
| 98 | protected String description() { | |
| 99 | 0 | return "querying service info: " + (_info != null ? _info.getQualifiedName() : "null"); |
| 100 | } | |
| 101 | ||
| 102 | } | |
|
||||||||||||