Renewer.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 Renewer extends DNSStateTask {
00023     static Logger logger = Logger.getLogger(Renewer.class.getName());
00024 
00025     public Renewer(JmDNSImpl jmDNSImpl) {
00026         super(jmDNSImpl, defaultTTL());
00027 
00028         this.setTaskState(DNSState.ANNOUNCED);
00029         this.associate(DNSState.ANNOUNCED);
00030     }
00031 
00032     /*
00033      * (non-Javadoc)
00034      * @see javax.jmdns.impl.tasks.DNSTask#getName()
00035      */
00036     @Override
00037     public String getName() {
00038         return "Renewer(" + (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         if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) {
00057             timer.schedule(this, DNSConstants.ANNOUNCED_RENEWAL_TTL_INTERVAL, DNSConstants.ANNOUNCED_RENEWAL_TTL_INTERVAL);
00058         }
00059     }
00060 
00061     @Override
00062     public boolean cancel() {
00063         this.removeAssociation();
00064 
00065         return super.cancel();
00066     }
00067 
00068     /*
00069      * (non-Javadoc)
00070      * @see javax.jmdns.impl.tasks.state.DNSStateTask#getTaskDescription()
00071      */
00072     @Override
00073     public String getTaskDescription() {
00074         return "renewing";
00075     }
00076 
00077     /*
00078      * (non-Javadoc)
00079      * @see javax.jmdns.impl.tasks.state.DNSStateTask#checkRunCondition()
00080      */
00081     @Override
00082     protected boolean checkRunCondition() {
00083         return !this.getDns().isCanceling() && !this.getDns().isCanceled();
00084     }
00085 
00086     /*
00087      * (non-Javadoc)
00088      * @see javax.jmdns.impl.tasks.state.DNSStateTask#createOugoing()
00089      */
00090     @Override
00091     protected DNSOutgoing createOugoing() {
00092         return new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA);
00093     }
00094 
00095     /*
00096      * (non-Javadoc)
00097      * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForDNS(javax.jmdns.impl.DNSOutgoing)
00098      */
00099     @Override
00100     protected DNSOutgoing buildOutgoingForDNS(DNSOutgoing out) throws IOException {
00101         DNSOutgoing newOut = out;
00102         for (DNSRecord answer : this.getDns().getLocalHost().answers(DNSRecordClass.UNIQUE, this.getTTL())) {
00103             newOut = this.addAnswer(newOut, null, answer);
00104         }
00105         return newOut;
00106     }
00107 
00108     /*
00109      * (non-Javadoc)
00110      * @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForInfo(javax.jmdns.impl.ServiceInfoImpl, javax.jmdns.impl.DNSOutgoing)
00111      */
00112     @Override
00113     protected DNSOutgoing buildOutgoingForInfo(ServiceInfoImpl info, DNSOutgoing out) throws IOException {
00114         DNSOutgoing newOut = out;
00115         for (DNSRecord answer : info.answers(DNSRecordClass.UNIQUE, this.getTTL(), this.getDns().getLocalHost())) {
00116             newOut = this.addAnswer(newOut, null, answer);
00117         }
00118         return newOut;
00119     }
00120 
00121     /*
00122      * (non-Javadoc)
00123      * @see javax.jmdns.impl.tasks.state.DNSStateTask#recoverTask(java.lang.Throwable)
00124      */
00125     @Override
00126     protected void recoverTask(Throwable e) {
00127         this.getDns().recover();
00128     }
00129 
00130     /*
00131      * (non-Javadoc)
00132      * @see javax.jmdns.impl.tasks.state.DNSStateTask#advanceTask()
00133      */
00134     @Override
00135     protected void advanceTask() {
00136         this.setTaskState(this.getTaskState().advance());
00137         if (!this.getTaskState().isAnnounced()) {
00138             cancel();
00139         }
00140     }
00141 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


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