Go to the documentation of this file.00001
00002
00003
00004
00005 package javax.jmdns.impl.tasks.resolver;
00006
00007 import java.io.IOException;
00008
00009 import javax.jmdns.impl.DNSOutgoing;
00010 import javax.jmdns.impl.DNSQuestion;
00011 import javax.jmdns.impl.DNSRecord;
00012 import javax.jmdns.impl.JmDNSImpl;
00013 import javax.jmdns.impl.ServiceInfoImpl;
00014 import javax.jmdns.impl.constants.DNSRecordClass;
00015 import javax.jmdns.impl.constants.DNSRecordType;
00016
00022 public class ServiceInfoResolver extends DNSResolverTask {
00023
00024 private final ServiceInfoImpl _info;
00025
00026 public ServiceInfoResolver(JmDNSImpl jmDNSImpl, ServiceInfoImpl info) {
00027 super(jmDNSImpl);
00028 this._info = info;
00029 info.setDns(this.getDns());
00030 this.getDns().addListener(info, DNSQuestion.newQuestion(info.getQualifiedName(), DNSRecordType.TYPE_ANY, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
00031 }
00032
00033
00034
00035
00036
00037 @Override
00038 public String getName() {
00039 return "ServiceInfoResolver(" + (this.getDns() != null ? this.getDns().getName() : "") + ")";
00040 }
00041
00042
00043
00044
00045
00046 @Override
00047 public boolean cancel() {
00048
00049 boolean result = super.cancel();
00050 if (!_info.isPersistent()) {
00051 this.getDns().removeListener(_info);
00052 }
00053 return result;
00054 }
00055
00056
00057
00058
00059
00060 @Override
00061 protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException {
00062 DNSOutgoing newOut = out;
00063 if (!_info.hasData()) {
00064 long now = System.currentTimeMillis();
00065 newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getQualifiedName(), DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN), now);
00066 newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getQualifiedName(), DNSRecordType.TYPE_TXT, DNSRecordClass.CLASS_IN), now);
00067 if (_info.getServer().length() > 0) {
00068 newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getServer(), DNSRecordType.TYPE_A, DNSRecordClass.CLASS_IN), now);
00069 newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getServer(), DNSRecordType.TYPE_AAAA, DNSRecordClass.CLASS_IN), now);
00070 }
00071 }
00072 return newOut;
00073 }
00074
00075
00076
00077
00078
00079 @Override
00080 protected DNSOutgoing addQuestions(DNSOutgoing out) throws IOException {
00081 DNSOutgoing newOut = out;
00082 if (!_info.hasData()) {
00083 newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getQualifiedName(), DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
00084 newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getQualifiedName(), DNSRecordType.TYPE_TXT, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
00085 if (_info.getServer().length() > 0) {
00086 newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getServer(), DNSRecordType.TYPE_A, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
00087 newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getServer(), DNSRecordType.TYPE_AAAA, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
00088 }
00089 }
00090 return newOut;
00091 }
00092
00093
00094
00095
00096
00097 @Override
00098 protected String description() {
00099 return "querying service info: " + (_info != null ? _info.getQualifiedName() : "null");
00100 }
00101
00102 }