1
2
3
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
20
21
22
23 public class ServiceResolver extends DNSResolverTask {
24
25 private final String _type;
26
27 public ServiceResolver(JmDNSImpl jmDNSImpl, String type) {
28 super(jmDNSImpl);
29 this._type = type;
30 }
31
32
33
34
35
36 @Override
37 public String getName() {
38 return "ServiceResolver(" + (this.getDns() != null ? this.getDns().getName() : "") + ")";
39 }
40
41
42
43
44
45 @Override
46 protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException {
47 DNSOutgoing newOut = out;
48 long now = System.currentTimeMillis();
49 for (ServiceInfo info : this.getDns().getServices().values()) {
50 newOut = this.addAnswer(newOut, new DNSRecord.Pointer(info.getType(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getQualifiedName()), now);
51
52
53 }
54 return newOut;
55 }
56
57
58
59
60
61 @Override
62 protected DNSOutgoing addQuestions(DNSOutgoing out) throws IOException {
63 DNSOutgoing newOut = out;
64 newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_type, DNSRecordType.TYPE_PTR, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
65
66 return newOut;
67 }
68
69
70
71
72
73 @Override
74 protected String description() {
75 return "querying service";
76 }
77 }