1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
package javax.jmdns.impl.tasks.state; |
6 |
|
|
7 |
|
import java.io.IOException; |
8 |
|
import java.util.Timer; |
9 |
|
import java.util.logging.Logger; |
10 |
|
|
11 |
|
import javax.jmdns.impl.DNSOutgoing; |
12 |
|
import javax.jmdns.impl.DNSQuestion; |
13 |
|
import javax.jmdns.impl.DNSRecord; |
14 |
|
import javax.jmdns.impl.JmDNSImpl; |
15 |
|
import javax.jmdns.impl.ServiceInfoImpl; |
16 |
|
import javax.jmdns.impl.constants.DNSConstants; |
17 |
|
import javax.jmdns.impl.constants.DNSRecordClass; |
18 |
|
import javax.jmdns.impl.constants.DNSRecordType; |
19 |
|
import javax.jmdns.impl.constants.DNSState; |
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
|
|
| 85.5% |
Uncovered Elements: 8 (55) |
Complexity: 19 |
Complexity Density: 0.58 |
|
27 |
|
public class Prober extends DNSStateTask { |
28 |
|
static Logger logger = Logger.getLogger(Prober.class.getName()); |
29 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
30 |
49
|
public Prober(JmDNSImpl jmDNSImpl) {... |
31 |
49
|
super(jmDNSImpl, defaultTTL()); |
32 |
|
|
33 |
49
|
this.setTaskState(DNSState.PROBING_1); |
34 |
49
|
this.associate(DNSState.PROBING_1); |
35 |
|
} |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@see |
40 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
41 |
282
|
@Override... |
42 |
|
public String getName() { |
43 |
282
|
return "Prober(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; |
44 |
|
} |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@see |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
0
|
@Override... |
51 |
|
public String toString() { |
52 |
0
|
return super.toString() + " state: " + this.getTaskState(); |
53 |
|
} |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@see |
58 |
|
|
|
|
| 80% |
Uncovered Elements: 3 (15) |
Complexity: 6 |
Complexity Density: 0.67 |
|
59 |
49
|
@Override... |
60 |
|
public void start(Timer timer) { |
61 |
49
|
long now = System.currentTimeMillis(); |
62 |
49
|
if (now - this.getDns().getLastThrottleIncrement() < DNSConstants.PROBE_THROTTLE_COUNT_INTERVAL) { |
63 |
0
|
this.getDns().setThrottle(this.getDns().getThrottle() + 1); |
64 |
|
} else { |
65 |
49
|
this.getDns().setThrottle(1); |
66 |
|
} |
67 |
49
|
this.getDns().setLastThrottleIncrement(now); |
68 |
|
|
69 |
49
|
if (this.getDns().isAnnounced() && this.getDns().getThrottle() < DNSConstants.PROBE_THROTTLE_COUNT) { |
70 |
20
|
timer.schedule(this, JmDNSImpl.getRandom().nextInt(1 + DNSConstants.PROBE_WAIT_INTERVAL), DNSConstants.PROBE_WAIT_INTERVAL); |
71 |
29
|
} else if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) { |
72 |
29
|
timer.schedule(this, DNSConstants.PROBE_CONFLICT_INTERVAL, DNSConstants.PROBE_CONFLICT_INTERVAL); |
73 |
|
} |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
76 |
49
|
@Override... |
77 |
|
public boolean cancel() { |
78 |
49
|
this.removeAssociation(); |
79 |
|
|
80 |
49
|
return super.cancel(); |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
@see |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
87 |
282
|
@Override... |
88 |
|
public String getTaskDescription() { |
89 |
282
|
return "probing"; |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
@see |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
143
|
@Override... |
97 |
|
protected boolean checkRunCondition() { |
98 |
143
|
return !this.getDns().isCanceling() && !this.getDns().isCanceled(); |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
@see |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
143
|
@Override... |
106 |
|
protected DNSOutgoing createOugoing() { |
107 |
143
|
return new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY); |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
@see |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
114 |
81
|
@Override... |
115 |
|
protected DNSOutgoing buildOutgoingForDNS(DNSOutgoing out) throws IOException { |
116 |
81
|
DNSOutgoing newOut = out; |
117 |
80
|
newOut.addQuestion(DNSQuestion.newQuestion(this.getDns().getLocalHost().getName(), DNSRecordType.TYPE_ANY, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); |
118 |
80
|
for (DNSRecord answer : this.getDns().getLocalHost().answers(DNSRecordClass.NOT_UNIQUE, this.getTTL())) { |
119 |
81
|
newOut = this.addAuthoritativeAnswer(newOut, answer); |
120 |
|
} |
121 |
81
|
return newOut; |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
@see |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
128 |
60
|
@Override... |
129 |
|
protected DNSOutgoing buildOutgoingForInfo(ServiceInfoImpl info, DNSOutgoing out) throws IOException { |
130 |
60
|
DNSOutgoing newOut = out; |
131 |
60
|
newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(info.getQualifiedName(), DNSRecordType.TYPE_ANY, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE)); |
132 |
|
|
133 |
60
|
newOut = this.addAuthoritativeAnswer(newOut, new DNSRecord.Service(info.getQualifiedName(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, this.getTTL(), info.getPriority(), info.getWeight(), info.getPort(), this.getDns().getLocalHost() |
134 |
|
.getName())); |
135 |
60
|
return newOut; |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
@see |
141 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
142 |
0
|
@Override... |
143 |
|
protected void recoverTask(Throwable e) { |
144 |
0
|
this.getDns().recover(); |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
@see |
150 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
151 |
141
|
@Override... |
152 |
|
protected void advanceTask() { |
153 |
141
|
this.setTaskState(this.getTaskState().advance()); |
154 |
141
|
if (!this.getTaskState().isProbing()) { |
155 |
47
|
cancel(); |
156 |
|
|
157 |
47
|
this.getDns().startAnnouncer(); |
158 |
|
} |
159 |
|
} |
160 |
|
|
161 |
|
} |