Canceler.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 
00022 public class Canceler extends DNSStateTask {
00023     static Logger logger = Logger.getLogger(Canceler.class.getName());
00024 
00025     public Canceler(JmDNSImpl jmDNSImpl) {
00026         super(jmDNSImpl, 0);
00027 
00028         this.setTaskState(DNSState.CANCELING_1);
00029         this.associate(DNSState.CANCELING_1);
00030     }
00031 
00032     /*
00033      * (non-Javadoc)
00034      * @see javax.jmdns.impl.tasks.DNSTask#getName()
00035      */
00036     @Override
00037     public String getName() {
00038         return "Canceler(" + (this.getDns() != null ? this.getDns().getName() : "") + ")";
00039     }
00040 
00041     /*
00042      * (non-Javadoc)
00043      * @see java.lang.Object#toString()
00044      */
00045     @Override
00046     public String toString() {
00047         return super.toString() + " state: " + this.getTaskState();
00048     }
00049 
00050     /*
00051      * (non-Javadoc)
00052      * @see javax.jmdns.impl.tasks.DNSTask#start(java.util.Timer)
00053      */
00054     @Override
00055     public void start(Timer timer) {
00056         timer.schedule(this, 0, DNSConstants.ANNOUNCE_WAIT_INTERVAL);
00057     }
00058 
00059     /*
00060      * (non-Javadoc)
00061      * @see java.util.TimerTask#cancel()
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 "canceling";
00077     }
00078 
00079     /*
00080      * (non-Javadoc)
00081      * @see javax.jmdns.impl.tasks.state.DNSStateTask#checkRunCondition()
00082      */
00083     @Override
00084     protected boolean checkRunCondition() {
00085         return true;
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().isCanceling()) {
00140             cancel();
00141         }
00142     }
00143 }


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