1 |
|
|
2 |
|
package javax.jmdns.impl.tasks.state; |
3 |
|
|
4 |
|
import java.io.IOException; |
5 |
|
import java.util.ArrayList; |
6 |
|
import java.util.List; |
7 |
|
import java.util.logging.Level; |
8 |
|
import java.util.logging.Logger; |
9 |
|
|
10 |
|
import javax.jmdns.ServiceInfo; |
11 |
|
import javax.jmdns.impl.DNSOutgoing; |
12 |
|
import javax.jmdns.impl.DNSStatefulObject; |
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.DNSState; |
17 |
|
import javax.jmdns.impl.tasks.DNSTask; |
18 |
|
|
19 |
|
|
20 |
|
@link |
21 |
|
|
22 |
|
@author |
23 |
|
|
|
|
| 89.6% |
Uncovered Elements: 7 (67) |
Complexity: 16 |
Complexity Density: 0.34 |
|
24 |
|
public abstract class DNSStateTask extends DNSTask { |
25 |
|
static Logger logger1 = Logger.getLogger(DNSStateTask.class.getName()); |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
private final int _ttl; |
31 |
|
|
32 |
|
private static int _defaultTTL = DNSConstants.DNS_TTL; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
private DNSState _taskState = null; |
38 |
|
|
39 |
|
public abstract String getTaskDescription(); |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
41 |
151
|
public static int defaultTTL() {... |
42 |
151
|
return _defaultTTL; |
43 |
|
} |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@param |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
2
|
public static void setDefaultTTL(int value) {... |
51 |
2
|
_defaultTTL = value; |
52 |
|
} |
53 |
|
|
54 |
|
|
55 |
|
@param |
56 |
|
@param |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
58 |
184
|
public DNSStateTask(JmDNSImpl jmDNSImpl, int ttl) {... |
59 |
184
|
super(jmDNSImpl); |
60 |
184
|
_ttl = ttl; |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
@return |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
302
|
public int getTTL() {... |
67 |
303
|
return _ttl; |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@param |
74 |
|
|
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
76 |
184
|
protected void associate(DNSState state) {... |
77 |
184
|
synchronized (this.getDns()) { |
78 |
184
|
this.getDns().associateWithTask(this, state); |
79 |
|
} |
80 |
184
|
for (ServiceInfo serviceInfo : this.getDns().getServices().values()) { |
81 |
89
|
((ServiceInfoImpl) serviceInfo).associateWithTask(this, state); |
82 |
|
} |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
88 |
133
|
protected void removeAssociation() {... |
89 |
|
|
90 |
133
|
synchronized (this.getDns()) { |
91 |
133
|
this.getDns().removeAssociationWithTask(this); |
92 |
|
} |
93 |
|
|
94 |
|
|
95 |
133
|
for (ServiceInfo serviceInfo : this.getDns().getServices().values()) { |
96 |
64
|
((ServiceInfoImpl) serviceInfo).removeAssociationWithTask(this); |
97 |
|
} |
98 |
|
} |
99 |
|
|
|
|
| 83.3% |
Uncovered Elements: 6 (36) |
Complexity: 6 |
Complexity Density: 0.21 |
|
100 |
318
|
@Override... |
101 |
|
public void run() { |
102 |
318
|
DNSOutgoing out = this.createOugoing(); |
103 |
318
|
try { |
104 |
317
|
if (!this.checkRunCondition()) { |
105 |
0
|
this.cancel(); |
106 |
0
|
return; |
107 |
|
} |
108 |
318
|
List<DNSStatefulObject> stateObjects = new ArrayList<DNSStatefulObject>(); |
109 |
|
|
110 |
318
|
synchronized (this.getDns()) { |
111 |
317
|
if (this.getDns().isAssociatedWithTask(this, this.getTaskState())) { |
112 |
134
|
logger1.finer(this.getName() + ".run() JmDNS " + this.getTaskDescription() + " " + this.getDns().getName()); |
113 |
134
|
stateObjects.add(this.getDns()); |
114 |
135
|
out = this.buildOutgoingForDNS(out); |
115 |
|
} |
116 |
|
} |
117 |
|
|
118 |
318
|
for (ServiceInfo serviceInfo : this.getDns().getServices().values()) { |
119 |
168
|
ServiceInfoImpl info = (ServiceInfoImpl) serviceInfo; |
120 |
|
|
121 |
168
|
synchronized (info) { |
122 |
168
|
if (info.isAssociatedWithTask(this, this.getTaskState())) { |
123 |
168
|
logger1.fine(this.getName() + ".run() JmDNS " + this.getTaskDescription() + " " + info.getQualifiedName()); |
124 |
168
|
stateObjects.add(info); |
125 |
168
|
out = this.buildOutgoingForInfo(info, out); |
126 |
|
} |
127 |
|
} |
128 |
|
} |
129 |
317
|
if (!out.isEmpty()) { |
130 |
302
|
logger1.finer(this.getName() + ".run() JmDNS " + this.getTaskDescription() + " #" + this.getTaskState()); |
131 |
303
|
this.getDns().send(out); |
132 |
|
|
133 |
|
|
134 |
303
|
this.advanceObjectsState(stateObjects); |
135 |
|
} else { |
136 |
|
|
137 |
15
|
this.advanceObjectsState(stateObjects); |
138 |
|
|
139 |
|
|
140 |
15
|
cancel(); |
141 |
15
|
return; |
142 |
|
} |
143 |
|
} catch (Throwable e) { |
144 |
0
|
logger1.log(Level.WARNING, this.getName() + ".run() exception ", e); |
145 |
0
|
this.recoverTask(e); |
146 |
|
} |
147 |
|
|
148 |
303
|
this.advanceTask(); |
149 |
|
} |
150 |
|
|
151 |
|
protected abstract boolean checkRunCondition(); |
152 |
|
|
153 |
|
protected abstract DNSOutgoing buildOutgoingForDNS(DNSOutgoing out) throws IOException; |
154 |
|
|
155 |
|
protected abstract DNSOutgoing buildOutgoingForInfo(ServiceInfoImpl info, DNSOutgoing out) throws IOException; |
156 |
|
|
157 |
|
protected abstract DNSOutgoing createOugoing(); |
158 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
159 |
318
|
protected void advanceObjectsState(List<DNSStatefulObject> list) {... |
160 |
318
|
if (list != null) { |
161 |
318
|
for (DNSStatefulObject object : list) { |
162 |
303
|
synchronized (object) { |
163 |
303
|
object.advanceState(this); |
164 |
|
} |
165 |
|
} |
166 |
|
} |
167 |
|
} |
168 |
|
|
169 |
|
protected abstract void recoverTask(Throwable e); |
170 |
|
|
171 |
|
protected abstract void advanceTask(); |
172 |
|
|
173 |
|
|
174 |
|
@return |
175 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
176 |
1395
|
protected DNSState getTaskState() {... |
177 |
1395
|
return this._taskState; |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
@param |
182 |
|
|
183 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
184 |
487
|
protected void setTaskState(DNSState taskState) {... |
185 |
487
|
this._taskState = taskState; |
186 |
|
} |
187 |
|
|
188 |
|
} |