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.DNSRecord; |
13 |
|
import javax.jmdns.impl.JmDNSImpl; |
14 |
|
import javax.jmdns.impl.ServiceInfoImpl; |
15 |
|
import javax.jmdns.impl.constants.DNSConstants; |
16 |
|
import javax.jmdns.impl.constants.DNSRecordClass; |
17 |
|
import javax.jmdns.impl.constants.DNSState; |
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
|
|
| 86% |
Uncovered Elements: 6 (43) |
Complexity: 16 |
Complexity Density: 0.64 |
|
24 |
|
public class Announcer extends DNSStateTask { |
25 |
|
static Logger logger = Logger.getLogger(Announcer.class.getName()); |
26 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
27 |
51
|
public Announcer(JmDNSImpl jmDNSImpl) {... |
28 |
51
|
super(jmDNSImpl, defaultTTL()); |
29 |
|
|
30 |
51
|
this.setTaskState(DNSState.ANNOUNCING_1); |
31 |
51
|
this.associate(DNSState.ANNOUNCING_1); |
32 |
|
} |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@see |
37 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
38 |
204
|
@Override... |
39 |
|
public String getName() { |
40 |
204
|
return "Announcer(" + (this.getDns() != null ? this.getDns().getName() : "") + ")"; |
41 |
|
} |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@see |
46 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
47 |
0
|
@Override... |
48 |
|
public String toString() { |
49 |
0
|
return super.toString() + " state: " + this.getTaskState(); |
50 |
|
} |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@see |
55 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 3 |
Complexity Density: 1.5 |
|
56 |
51
|
@Override... |
57 |
|
public void start(Timer timer) { |
58 |
51
|
if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) { |
59 |
51
|
timer.schedule(this, DNSConstants.ANNOUNCE_WAIT_INTERVAL, DNSConstants.ANNOUNCE_WAIT_INTERVAL); |
60 |
|
} |
61 |
|
} |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
63 |
51
|
@Override... |
64 |
|
public boolean cancel() { |
65 |
51
|
this.removeAssociation(); |
66 |
|
|
67 |
51
|
return super.cancel(); |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
@see |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
204
|
@Override... |
75 |
|
public String getTaskDescription() { |
76 |
204
|
return "announcing"; |
77 |
|
} |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
@see |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
102
|
@Override... |
84 |
|
protected boolean checkRunCondition() { |
85 |
102
|
return !this.getDns().isCanceling() && !this.getDns().isCanceled(); |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
@see |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
102
|
@Override... |
93 |
|
protected DNSOutgoing createOugoing() { |
94 |
102
|
return new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA); |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
@see |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
101 |
53
|
@Override... |
102 |
|
protected DNSOutgoing buildOutgoingForDNS(DNSOutgoing out) throws IOException { |
103 |
53
|
DNSOutgoing newOut = out; |
104 |
54
|
for (DNSRecord answer : this.getDns().getLocalHost().answers(DNSRecordClass.UNIQUE, this.getTTL())) { |
105 |
54
|
newOut = this.addAnswer(newOut, null, answer); |
106 |
|
} |
107 |
54
|
return newOut; |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
@see |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
114 |
48
|
@Override... |
115 |
|
protected DNSOutgoing buildOutgoingForInfo(ServiceInfoImpl info, DNSOutgoing out) throws IOException { |
116 |
48
|
DNSOutgoing newOut = out; |
117 |
48
|
for (DNSRecord answer : info.answers(DNSRecordClass.UNIQUE, this.getTTL(), this.getDns().getLocalHost())) { |
118 |
146
|
newOut = this.addAnswer(newOut, null, answer); |
119 |
|
} |
120 |
48
|
return newOut; |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
@see |
126 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
127 |
0
|
@Override... |
128 |
|
protected void recoverTask(Throwable e) { |
129 |
0
|
this.getDns().recover(); |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
@see |
135 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
136 |
102
|
@Override... |
137 |
|
protected void advanceTask() { |
138 |
102
|
this.setTaskState(this.getTaskState().advance()); |
139 |
102
|
if (!this.getTaskState().isAnnouncing()) { |
140 |
51
|
this.cancel(); |
141 |
|
|
142 |
51
|
this.getDns().startRenewer(); |
143 |
|
} |
144 |
|
} |
145 |
|
|
146 |
|
} |