blob: 8382e54dcf63e18c01cf6d73aff4246d248026f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// Copyright 2003-2005 Arthur van Hoff, Rick Blair
// Licensed under Apache License version 2.0
// Original license LGPL
package javax.jmdns.impl.tasks.resolver;
import java.io.IOException;
import javax.jmdns.impl.DNSOutgoing;
import javax.jmdns.impl.DNSQuestion;
import javax.jmdns.impl.DNSRecord;
import javax.jmdns.impl.JmDNSImpl;
import javax.jmdns.impl.JmDNSImpl.ServiceTypeEntry;
import javax.jmdns.impl.constants.DNSConstants;
import javax.jmdns.impl.constants.DNSRecordClass;
import javax.jmdns.impl.constants.DNSRecordType;
/**
* Helper class to resolve service types.
* <p/>
* The TypeResolver queries three times consecutively for service types, and then removes itself from the timer.
* <p/>
* The TypeResolver will run only if JmDNS is in state ANNOUNCED.
*/
public class TypeResolver extends DNSResolverTask {
/**
* @param jmDNSImpl
*/
public TypeResolver(JmDNSImpl jmDNSImpl) {
super(jmDNSImpl);
}
/*
* (non-Javadoc)
* @see javax.jmdns.impl.tasks.DNSTask#getName()
*/
@Override
public String getName() {
return "TypeResolver(" + (this.getDns() != null ? this.getDns().getName() : "") + ")";
}
/*
* (non-Javadoc)
* @see javax.jmdns.impl.tasks.Resolver#addAnswers(javax.jmdns.impl.DNSOutgoing)
*/
@Override
protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException {
DNSOutgoing newOut = out;
long now = System.currentTimeMillis();
for (String type : this.getDns().getServiceTypes().keySet()) {
ServiceTypeEntry typeEntry = this.getDns().getServiceTypes().get(type);
newOut = this.addAnswer(newOut, new DNSRecord.Pointer("_services._dns-sd._udp.local.", DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, typeEntry.getType()), now);
}
return newOut;
}
/*
* (non-Javadoc)
* @see javax.jmdns.impl.tasks.Resolver#addQuestions(javax.jmdns.impl.DNSOutgoing)
*/
@Override
protected DNSOutgoing addQuestions(DNSOutgoing out) throws IOException {
return this.addQuestion(out, DNSQuestion.newQuestion("_services._dns-sd._udp.local.", DNSRecordType.TYPE_PTR, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
}
/*
* (non-Javadoc)
* @see javax.jmdns.impl.tasks.Resolver#description()
*/
@Override
protected String description() {
return "querying type";
}
}
|