DNSTask.java
Go to the documentation of this file.
00001 // Licensed under Apache License version 2.0
00002 package javax.jmdns.impl.tasks;
00003 
00004 import java.io.IOException;
00005 import java.util.Timer;
00006 import java.util.TimerTask;
00007 
00008 import javax.jmdns.impl.DNSIncoming;
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.constants.DNSConstants;
00014 
00020 public abstract class DNSTask extends TimerTask {
00021 
00025     private final JmDNSImpl _jmDNSImpl;
00026 
00030     protected DNSTask(JmDNSImpl jmDNSImpl) {
00031         super();
00032         this._jmDNSImpl = jmDNSImpl;
00033     }
00034 
00040     public JmDNSImpl getDns() {
00041         return _jmDNSImpl;
00042     }
00043 
00050     public abstract void start(Timer timer);
00051 
00057     public abstract String getName();
00058 
00059     /*
00060      * (non-Javadoc)
00061      * @see java.lang.Object#toString()
00062      */
00063     @Override
00064     public String toString() {
00065         return this.getName();
00066     }
00067 
00078     public DNSOutgoing addQuestion(DNSOutgoing out, DNSQuestion rec) throws IOException {
00079         DNSOutgoing newOut = out;
00080         try {
00081             newOut.addQuestion(rec);
00082         } catch (final IOException e) {
00083             int flags = newOut.getFlags();
00084             boolean multicast = newOut.isMulticast();
00085             int maxUDPPayload = newOut.getMaxUDPPayload();
00086             int id = newOut.getId();
00087 
00088             newOut.setFlags(flags | DNSConstants.FLAGS_TC);
00089             newOut.setId(id);
00090             this._jmDNSImpl.send(newOut);
00091 
00092             newOut = new DNSOutgoing(flags, multicast, maxUDPPayload);
00093             newOut.addQuestion(rec);
00094         }
00095         return newOut;
00096     }
00097 
00110     public DNSOutgoing addAnswer(DNSOutgoing out, DNSIncoming in, DNSRecord rec) throws IOException {
00111         DNSOutgoing newOut = out;
00112         try {
00113             newOut.addAnswer(in, rec);
00114         } catch (final IOException e) {
00115             int flags = newOut.getFlags();
00116             boolean multicast = newOut.isMulticast();
00117             int maxUDPPayload = newOut.getMaxUDPPayload();
00118             int id = newOut.getId();
00119 
00120             newOut.setFlags(flags | DNSConstants.FLAGS_TC);
00121             newOut.setId(id);
00122             this._jmDNSImpl.send(newOut);
00123 
00124             newOut = new DNSOutgoing(flags, multicast, maxUDPPayload);
00125             newOut.addAnswer(in, rec);
00126         }
00127         return newOut;
00128     }
00129 
00141     public DNSOutgoing addAnswer(DNSOutgoing out, DNSRecord rec, long now) throws IOException {
00142         DNSOutgoing newOut = out;
00143         try {
00144             newOut.addAnswer(rec, now);
00145         } catch (final IOException e) {
00146             int flags = newOut.getFlags();
00147             boolean multicast = newOut.isMulticast();
00148             int maxUDPPayload = newOut.getMaxUDPPayload();
00149             int id = newOut.getId();
00150 
00151             newOut.setFlags(flags | DNSConstants.FLAGS_TC);
00152             newOut.setId(id);
00153             this._jmDNSImpl.send(newOut);
00154 
00155             newOut = new DNSOutgoing(flags, multicast, maxUDPPayload);
00156             newOut.addAnswer(rec, now);
00157         }
00158         return newOut;
00159     }
00160 
00171     public DNSOutgoing addAuthoritativeAnswer(DNSOutgoing out, DNSRecord rec) throws IOException {
00172         DNSOutgoing newOut = out;
00173         try {
00174             newOut.addAuthorativeAnswer(rec);
00175         } catch (final IOException e) {
00176             int flags = newOut.getFlags();
00177             boolean multicast = newOut.isMulticast();
00178             int maxUDPPayload = newOut.getMaxUDPPayload();
00179             int id = newOut.getId();
00180 
00181             newOut.setFlags(flags | DNSConstants.FLAGS_TC);
00182             newOut.setId(id);
00183             this._jmDNSImpl.send(newOut);
00184 
00185             newOut = new DNSOutgoing(flags, multicast, maxUDPPayload);
00186             newOut.addAuthorativeAnswer(rec);
00187         }
00188         return newOut;
00189     }
00190 
00203     public DNSOutgoing addAdditionalAnswer(DNSOutgoing out, DNSIncoming in, DNSRecord rec) throws IOException {
00204         DNSOutgoing newOut = out;
00205         try {
00206             newOut.addAdditionalAnswer(in, rec);
00207         } catch (final IOException e) {
00208             int flags = newOut.getFlags();
00209             boolean multicast = newOut.isMulticast();
00210             int maxUDPPayload = newOut.getMaxUDPPayload();
00211             int id = newOut.getId();
00212 
00213             newOut.setFlags(flags | DNSConstants.FLAGS_TC);
00214             newOut.setId(id);
00215             this._jmDNSImpl.send(newOut);
00216 
00217             newOut = new DNSOutgoing(flags, multicast, maxUDPPayload);
00218             newOut.addAdditionalAnswer(in, rec);
00219         }
00220         return newOut;
00221     }
00222 
00223 }


zeroconf_jmdns_suite
Author(s): Daniel Stonier
autogenerated on Thu Aug 27 2015 15:50:27