Announcer.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.state;
00006 
00007 import java.io.IOException;
00008 import java.util.Timer;
00009 import java.util.logging.Logger;
00010 
00011 import javax.jmdns.impl.DNSOutgoing;
00012 import javax.jmdns.impl.DNSRecord;
00013 import javax.jmdns.impl.JmDNSImpl;
00014 import javax.jmdns.impl.ServiceInfoImpl;
00015 import javax.jmdns.impl.constants.DNSConstants;
00016 import javax.jmdns.impl.constants.DNSRecordClass;
00017 import javax.jmdns.impl.constants.DNSState;
00018 
00024 public class Announcer extends DNSStateTask {
00025     static Logger logger = Logger.getLogger(Announcer.class.getName());
00026 
00027     public Announcer(JmDNSImpl jmDNSImpl) {
00028         super(jmDNSImpl, defaultTTL());
00029 
00030         this.setTaskState(DNSState.ANNOUNCING_1);
00031         this.associate(DNSState.ANNOUNCING_1);
00032     }
00033 
00034     /*
00035      * (non-Javadoc)
00036      * @see javax.jmdns.impl.tasks.DNSTask#getName()
00037      */
00038     @Override
00039     public String getName() {
00040         return "Announcer(" + (this.getDns() != null ? this.getDns().getName() : "") + ")";
00041     }
00042 
00043     /*
00044      * (non-Javadoc)
00045      * @see java.lang.Object#toString()
00046      */
00047     @Override
00048     public String toString() {
00049         return super.toString() + " state: " + this.getTaskState();
00050     }
00051 
00052     /*
00053      * (non-Javadoc)
00054      * @see javax.jmdns.impl.tasks.DNSTask#start(java.util.Timer)
00055      */
00056     @Override
00057     public void start(Timer timer) {
00058         if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) {
00059             timer.schedule(this, DNSConstants.ANNOUNCE_WAIT_INTERVAL, DNSConstants.ANNOUNCE_WAIT_INTERVAL);
00060         }
00061     }
00062 
00063     @Override
00064     public boolean cancel() {
00065         this.removeAssociation();
00066 
00067         return super.cancel();
00068     }
00069 
00070     /*
00071      * (non-Javadoc)
00072      * @see javax.jmdns.impl.tasks.state.DNSStateTask#getTaskDescription()
00073      */
00074     @Override
00075     public String getTaskDescription() {
00076         return "announcing";
00077     }
00078 
00079     /*
00080      * (non-Javadoc)
00081      * @see javax.jmdns.impl.tasks.state.DNSStateTask#checkRunCondition()
00082      */
00083     @Override
00084     protected boolean checkRunCondition() {
00085         return !this.getDns().isCanceling() && !this.getDns().isCanceled();
00086     }
00087 
00088     /*
00089      * (non-Javadoc)
00090      * @see javax.jmdns.impl.tasks.state.DNSStateTask#createOugoing()
00091      */
00092     @Override
00093     protected DNSOutgoing createOugoing() {
00094         return new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA);
00095     }
00096 
00097     /*
00098      * (non-Javadoc)
00099      * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForDNS(javax.jmdns.impl.DNSOutgoing)
00100      */
00101     @Override
00102     protected DNSOutgoing buildOutgoingForDNS(DNSOutgoing out) throws IOException {
00103         DNSOutgoing newOut = out;
00104         for (DNSRecord answer : this.getDns().getLocalHost().answers(DNSRecordClass.UNIQUE, this.getTTL())) {
00105             newOut = this.addAnswer(newOut, null, answer);
00106         }
00107         return newOut;
00108     }
00109 
00110     /*
00111      * (non-Javadoc)
00112      * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForInfo(javax.jmdns.impl.ServiceInfoImpl, javax.jmdns.impl.DNSOutgoing)
00113      */
00114     @Override
00115     protected DNSOutgoing buildOutgoingForInfo(ServiceInfoImpl info, DNSOutgoing out) throws IOException {
00116         DNSOutgoing newOut = out;
00117         for (DNSRecord answer : info.answers(DNSRecordClass.UNIQUE, this.getTTL(), this.getDns().getLocalHost())) {
00118             newOut = this.addAnswer(newOut, null, answer);
00119         }
00120         return newOut;
00121     }
00122 
00123     /*
00124      * (non-Javadoc)
00125      * @see javax.jmdns.impl.tasks.state.DNSStateTask#recoverTask(java.lang.Throwable)
00126      */
00127     @Override
00128     protected void recoverTask(Throwable e) {
00129         this.getDns().recover();
00130     }
00131 
00132     /*
00133      * (non-Javadoc)
00134      * @see javax.jmdns.impl.tasks.state.DNSStateTask#advanceTask()
00135      */
00136     @Override
00137     protected void advanceTask() {
00138         this.setTaskState(this.getTaskState().advance());
00139         if (!this.getTaskState().isAnnouncing()) {
00140             this.cancel();
00141 
00142             this.getDns().startRenewer();
00143         }
00144     }
00145 
00146 }


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