Go to the documentation of this file.00001
00002
00003
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
00034
00035
00036 @Override
00037 public String getName() {
00038 return "Canceler(" + (this.getDns() != null ? this.getDns().getName() : "") + ")";
00039 }
00040
00041
00042
00043
00044
00045 @Override
00046 public String toString() {
00047 return super.toString() + " state: " + this.getTaskState();
00048 }
00049
00050
00051
00052
00053
00054 @Override
00055 public void start(Timer timer) {
00056 timer.schedule(this, 0, DNSConstants.ANNOUNCE_WAIT_INTERVAL);
00057 }
00058
00059
00060
00061
00062
00063 @Override
00064 public boolean cancel() {
00065 this.removeAssociation();
00066
00067 return super.cancel();
00068 }
00069
00070
00071
00072
00073
00074 @Override
00075 public String getTaskDescription() {
00076 return "canceling";
00077 }
00078
00079
00080
00081
00082
00083 @Override
00084 protected boolean checkRunCondition() {
00085 return true;
00086 }
00087
00088
00089
00090
00091
00092 @Override
00093 protected DNSOutgoing createOugoing() {
00094 return new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA);
00095 }
00096
00097
00098
00099
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
00112
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
00125
00126
00127 @Override
00128 protected void recoverTask(Throwable e) {
00129 this.getDns().recover();
00130 }
00131
00132
00133
00134
00135
00136 @Override
00137 protected void advanceTask() {
00138 this.setTaskState(this.getTaskState().advance());
00139 if (!this.getTaskState().isCanceling()) {
00140 cancel();
00141 }
00142 }
00143 }