1
2 package javax.jmdns.impl.tasks;
3
4 import java.io.IOException;
5 import java.util.Timer;
6 import java.util.TimerTask;
7
8 import javax.jmdns.impl.DNSIncoming;
9 import javax.jmdns.impl.DNSOutgoing;
10 import javax.jmdns.impl.DNSQuestion;
11 import javax.jmdns.impl.DNSRecord;
12 import javax.jmdns.impl.JmDNSImpl;
13 import javax.jmdns.impl.constants.DNSConstants;
14
15
16
17
18
19
20 public abstract class DNSTask extends TimerTask {
21
22
23
24
25 private final JmDNSImpl _jmDNSImpl;
26
27
28
29
30 protected DNSTask(JmDNSImpl jmDNSImpl) {
31 super();
32 this._jmDNSImpl = jmDNSImpl;
33 }
34
35
36
37
38
39
40 public JmDNSImpl getDns() {
41 return _jmDNSImpl;
42 }
43
44
45
46
47
48
49
50 public abstract void start(Timer timer);
51
52
53
54
55
56
57 public abstract String getName();
58
59
60
61
62
63 @Override
64 public String toString() {
65 return this.getName();
66 }
67
68
69
70
71
72
73
74
75
76
77
78 public DNSOutgoing addQuestion(DNSOutgoing out, DNSQuestion rec) throws IOException {
79 DNSOutgoing newOut = out;
80 try {
81 newOut.addQuestion(rec);
82 } catch (final IOException e) {
83 int flags = newOut.getFlags();
84 boolean multicast = newOut.isMulticast();
85 int maxUDPPayload = newOut.getMaxUDPPayload();
86 int id = newOut.getId();
87
88 newOut.setFlags(flags | DNSConstants.FLAGS_TC);
89 newOut.setId(id);
90 this._jmDNSImpl.send(newOut);
91
92 newOut = new DNSOutgoing(flags, multicast, maxUDPPayload);
93 newOut.addQuestion(rec);
94 }
95 return newOut;
96 }
97
98
99
100
101
102
103
104
105
106
107
108
109
110 public DNSOutgoing addAnswer(DNSOutgoing out, DNSIncoming in, DNSRecord rec) throws IOException {
111 DNSOutgoing newOut = out;
112 try {
113 newOut.addAnswer(in, rec);
114 } catch (final IOException e) {
115 int flags = newOut.getFlags();
116 boolean multicast = newOut.isMulticast();
117 int maxUDPPayload = newOut.getMaxUDPPayload();
118 int id = newOut.getId();
119
120 newOut.setFlags(flags | DNSConstants.FLAGS_TC);
121 newOut.setId(id);
122 this._jmDNSImpl.send(newOut);
123
124 newOut = new DNSOutgoing(flags, multicast, maxUDPPayload);
125 newOut.addAnswer(in, rec);
126 }
127 return newOut;
128 }
129
130
131
132
133
134
135
136
137
138
139
140
141 public DNSOutgoing addAnswer(DNSOutgoing out, DNSRecord rec, long now) throws IOException {
142 DNSOutgoing newOut = out;
143 try {
144 newOut.addAnswer(rec, now);
145 } catch (final IOException e) {
146 int flags = newOut.getFlags();
147 boolean multicast = newOut.isMulticast();
148 int maxUDPPayload = newOut.getMaxUDPPayload();
149 int id = newOut.getId();
150
151 newOut.setFlags(flags | DNSConstants.FLAGS_TC);
152 newOut.setId(id);
153 this._jmDNSImpl.send(newOut);
154
155 newOut = new DNSOutgoing(flags, multicast, maxUDPPayload);
156 newOut.addAnswer(rec, now);
157 }
158 return newOut;
159 }
160
161
162
163
164
165
166
167
168
169
170
171 public DNSOutgoing addAuthoritativeAnswer(DNSOutgoing out, DNSRecord rec) throws IOException {
172 DNSOutgoing newOut = out;
173 try {
174 newOut.addAuthorativeAnswer(rec);
175 } catch (final IOException e) {
176 int flags = newOut.getFlags();
177 boolean multicast = newOut.isMulticast();
178 int maxUDPPayload = newOut.getMaxUDPPayload();
179 int id = newOut.getId();
180
181 newOut.setFlags(flags | DNSConstants.FLAGS_TC);
182 newOut.setId(id);
183 this._jmDNSImpl.send(newOut);
184
185 newOut = new DNSOutgoing(flags, multicast, maxUDPPayload);
186 newOut.addAuthorativeAnswer(rec);
187 }
188 return newOut;
189 }
190
191
192
193
194
195
196
197
198
199
200
201
202
203 public DNSOutgoing addAdditionalAnswer(DNSOutgoing out, DNSIncoming in, DNSRecord rec) throws IOException {
204 DNSOutgoing newOut = out;
205 try {
206 newOut.addAdditionalAnswer(in, rec);
207 } catch (final IOException e) {
208 int flags = newOut.getFlags();
209 boolean multicast = newOut.isMulticast();
210 int maxUDPPayload = newOut.getMaxUDPPayload();
211 int id = newOut.getId();
212
213 newOut.setFlags(flags | DNSConstants.FLAGS_TC);
214 newOut.setId(id);
215 this._jmDNSImpl.send(newOut);
216
217 newOut = new DNSOutgoing(flags, multicast, maxUDPPayload);
218 newOut.addAdditionalAnswer(in, rec);
219 }
220 return newOut;
221 }
222
223 }