ServiceInfoResolver.java
Go to the documentation of this file.
00001 // Copyright 2003-2005 Arthur van Hoff, Rick Blair
00002 // Licensed under Apache License version 2.0
00003 // Original license LGPL
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      * (non-Javadoc)
00035      * @see javax.jmdns.impl.tasks.DNSTask#getName()
00036      */
00037     @Override
00038     public String getName() {
00039         return "ServiceInfoResolver(" + (this.getDns() != null ? this.getDns().getName() : "") + ")";
00040     }
00041 
00042     /*
00043      * (non-Javadoc)
00044      * @see java.util.TimerTask#cancel()
00045      */
00046     @Override
00047     public boolean cancel() {
00048         // We should not forget to remove the listener
00049         boolean result = super.cancel();
00050         if (!_info.isPersistent()) {
00051             this.getDns().removeListener(_info);
00052         }
00053         return result;
00054     }
00055 
00056     /*
00057      * (non-Javadoc)
00058      * @see javax.jmdns.impl.tasks.Resolver#addAnswers(javax.jmdns.impl.DNSOutgoing)
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      * (non-Javadoc)
00077      * @see javax.jmdns.impl.tasks.Resolver#addQuestions(javax.jmdns.impl.DNSOutgoing)
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      * (non-Javadoc)
00095      * @see javax.jmdns.impl.tasks.Resolver#description()
00096      */
00097     @Override
00098     protected String description() {
00099         return "querying service info: " + (_info != null ? _info.getQualifiedName() : "null");
00100     }
00101 
00102 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


zeroconf_jmdns
Author(s): Daniel Stonier
autogenerated on Tue Nov 6 2012 14:18:57