|
38 | 38 | final List<instanceWrapper> pending_registrations = new ArrayList<>();
|
39 | 39 |
|
40 | 40 | private volatile boolean registrations_changed;
|
41 |
| - private volatile long latest_time; |
| 41 | + private volatile long latest_time_mono; |
42 | 42 |
|
43 | 43 | private final Object instance_lock = new Object();
|
44 | 44 |
|
45 | 45 | private final SpeedTokenDispenserPrioritised tokenDispenser = new SpeedTokenDispenserPrioritised();
|
46 | 46 |
|
47 |
| - private long next_peer_count_time = SystemTime.getMonotonousTime(); |
48 |
| - private long next_piece_count_time = SystemTime.getMonotonousTime(); |
| 47 | + private long next_peer_count_time_mono = SystemTime.getMonotonousTime(); |
| 48 | + private long next_piece_count_time_mono = SystemTime.getMonotonousTime(); |
49 | 49 |
|
50 |
| - private volatile long peer_count_active_time = 0; |
51 |
| - private volatile long piece_count_active_time = 0; |
| 50 | + private volatile long peer_count_active_time_mono = 0; |
| 51 | + private volatile long piece_count_active_time_mono = 0; |
52 | 52 |
|
53 | 53 | private volatile int[] last_peer_count = { 0, 0 };
|
54 | 54 | private volatile int[] last_piece_count = { 0, 0 };
|
|
57 | 57 | protected void
|
58 | 58 | schedule()
|
59 | 59 | {
|
60 |
| - latest_time = SystemTime.getMonotonousTime(); |
| 60 | + latest_time_mono = SystemTime.getMonotonousTime(); |
61 | 61 |
|
62 | 62 | SystemTime.registerMonotonousConsumer(
|
63 | 63 | new SystemTime.TickConsumer()
|
64 | 64 | {
|
65 | 65 | @Override
|
66 | 66 | public void
|
67 |
| - consume( long time ) |
| 67 | + consume( long time_mono ) |
68 | 68 | {
|
69 | 69 | boolean count_peers = false;
|
70 | 70 | boolean count_pieces = false;
|
71 | 71 |
|
72 | 72 | synchronized( PeerControlSchedulerPrioritised.this ){
|
73 | 73 |
|
74 |
| - if ( peer_count_active_time > 0 ){ |
| 74 | + if ( peer_count_active_time_mono > 0 ){ |
75 | 75 |
|
76 |
| - if ( time >= next_peer_count_time ){ |
| 76 | + if ( time_mono >= next_peer_count_time_mono ){ |
77 | 77 |
|
78 |
| - if ( time - peer_count_active_time > 15*1000 ){ |
| 78 | + if ( time_mono - peer_count_active_time_mono > 15*1000 ){ |
79 | 79 |
|
80 |
| - peer_count_active_time = 0; |
| 80 | + peer_count_active_time_mono = 0; |
81 | 81 |
|
82 | 82 | }else{
|
83 | 83 | count_peers = true;
|
84 | 84 |
|
85 |
| - next_peer_count_time = time+900; |
| 85 | + next_peer_count_time_mono = time_mono+900; |
86 | 86 | }
|
87 | 87 | }
|
88 | 88 | }
|
89 | 89 |
|
90 |
| - if ( piece_count_active_time > 0 ){ |
| 90 | + if ( piece_count_active_time_mono > 0 ){ |
91 | 91 |
|
92 |
| - if ( time >= next_piece_count_time ){ |
| 92 | + if ( time_mono >= next_piece_count_time_mono ){ |
93 | 93 |
|
94 |
| - if ( time - piece_count_active_time > 15*1000 ){ |
| 94 | + if ( time_mono - piece_count_active_time_mono > 15*1000 ){ |
95 | 95 |
|
96 |
| - piece_count_active_time = 0; |
| 96 | + piece_count_active_time_mono = 0; |
97 | 97 |
|
98 | 98 | }else{
|
99 | 99 |
|
100 | 100 | count_pieces = true;
|
101 | 101 |
|
102 |
| - next_piece_count_time = time+900; |
| 102 | + next_piece_count_time_mono = time_mono+900; |
103 | 103 | }
|
104 | 104 | }
|
105 | 105 | }
|
106 | 106 |
|
107 |
| - latest_time = time; |
| 107 | + latest_time_mono = time_mono; |
108 | 108 |
|
109 | 109 | if ( instance_map.size() > 0 || pending_registrations.size() > 0 ){
|
110 | 110 |
|
|
153 | 153 | });
|
154 | 154 |
|
155 | 155 |
|
156 |
| - ArrayList instances = new ArrayList(); |
| 156 | + ArrayList<instanceWrapper> instances = new ArrayList<>(); |
157 | 157 |
|
158 |
| - long latest_time_used = 0; |
159 |
| - int scheduledNext = 0; |
160 |
| - long currentScheduleStart = latest_time; |
161 |
| - long last_stats_time = latest_time; |
| 158 | + long latest_time_used_mono = 0; |
| 159 | + int scheduledNext = 0; |
| 160 | + long currentScheduleStartMono = latest_time_mono; |
| 161 | + long last_stats_time_mono = latest_time_mono; |
162 | 162 |
|
163 | 163 | while( true ){
|
164 | 164 |
|
165 | 165 | if ( registrations_changed ){
|
166 | 166 | synchronized( instance_lock ){
|
167 |
| - Iterator it = instances.iterator(); |
| 167 | + Iterator<instanceWrapper> it = instances.iterator(); |
168 | 168 | while( it.hasNext()){
|
169 |
| - if (((instanceWrapper)it.next()).isUnregistered()){ |
| 169 | + if (it.next().isUnregistered()){ |
170 | 170 | it.remove();
|
171 | 171 | }
|
172 | 172 | }
|
|
185 | 185 | }
|
186 | 186 |
|
187 | 187 | scheduledNext = 0;
|
188 |
| - currentScheduleStart = latest_time; |
| 188 | + currentScheduleStartMono = latest_time_mono; |
189 | 189 |
|
190 | 190 | registrations_changed = false;
|
191 | 191 | }
|
192 | 192 | }
|
193 | 193 |
|
194 |
| - tokenDispenser.update(latest_time); |
| 194 | + tokenDispenser.update(latest_time_mono); |
195 | 195 |
|
196 | 196 | for (int i = scheduledNext; i < instances.size(); i++)
|
197 | 197 | {
|
198 |
| - instanceWrapper inst = (instanceWrapper) instances.get(i); |
199 |
| - if (currentScheduleStart + inst.getScheduleOffset() > latest_time_used) |
| 198 | + instanceWrapper inst = instances.get(i); |
| 199 | + if (currentScheduleStartMono + inst.getScheduleOffset() > latest_time_used_mono) |
200 | 200 | break; // too early for next task, continue waiting
|
201 | 201 | if (i == 0 || !useWeights)
|
202 | 202 | tokenDispenser.refill();
|
|
208 | 208 | {
|
209 | 209 | scheduledNext = 0;
|
210 | 210 | // try to run every task every SCHEDULE_PERIOD_MILLIS on average
|
211 |
| - currentScheduleStart += SCHEDULE_PERIOD_MILLIS; |
| 211 | + currentScheduleStartMono += SCHEDULE_PERIOD_MILLIS; |
212 | 212 | // if tasks hog too much time then delay to prevent massive
|
213 | 213 | // catch-up-hammering
|
214 |
| - if (latest_time_used - currentScheduleStart > SCHEDULE_PERIOD_MAX_CATCHUP ) |
215 |
| - currentScheduleStart = latest_time_used + SCHEDULE_PERIOD_MILLIS; |
| 214 | + if (latest_time_used_mono - currentScheduleStartMono > SCHEDULE_PERIOD_MAX_CATCHUP ) |
| 215 | + currentScheduleStartMono = latest_time_used_mono + SCHEDULE_PERIOD_MILLIS; |
216 | 216 | }
|
217 | 217 | }
|
218 | 218 |
|
|
235 | 235 | }*/
|
236 | 236 |
|
237 | 237 | synchronized( this ){
|
238 |
| - if ( latest_time == latest_time_used ){ |
| 238 | + if ( latest_time_mono == latest_time_used_mono ){ |
239 | 239 | wait_count++;
|
240 | 240 | try{
|
241 | 241 | long wait_start = SystemTime.getHighPrecisionCounter();
|
|
251 | 251 | Thread.yield();
|
252 | 252 | }
|
253 | 253 |
|
254 |
| - latest_time_used = latest_time; |
| 254 | + latest_time_used_mono = latest_time_mono; |
255 | 255 | }
|
256 | 256 |
|
257 |
| - long stats_diff = latest_time_used - last_stats_time; |
| 257 | + long stats_diff = latest_time_used_mono - last_stats_time_mono; |
258 | 258 |
|
259 | 259 | if ( stats_diff > 10000 ){
|
260 | 260 | // System.out.println( "stats: time = " + stats_diff + ", ticks = " + tick_count + ", inst = " + instances.size());
|
261 |
| - last_stats_time = latest_time_used; |
| 261 | + last_stats_time_mono = latest_time_used_mono; |
262 | 262 | }
|
263 | 263 | }
|
264 | 264 | }
|
|
272 | 272 |
|
273 | 273 | synchronized( instance_lock ){
|
274 | 274 |
|
275 |
| - Map new_map = new HashMap( instance_map ); |
| 275 | + Map<PeerControlInstance,instanceWrapper> new_map = new HashMap<>( instance_map ); |
276 | 276 |
|
277 | 277 | new_map.put( instance, wrapper );
|
278 | 278 |
|
|
291 | 291 | {
|
292 | 292 | synchronized( instance_lock ){
|
293 | 293 |
|
294 |
| - Map new_map = new HashMap( instance_map ); |
| 294 | + Map<PeerControlInstance,instanceWrapper> new_map = new HashMap<>( instance_map ); |
295 | 295 |
|
296 | 296 | instanceWrapper wrapper = (instanceWrapper)new_map.remove(instance);
|
297 | 297 |
|
@@ -325,21 +325,21 @@ public void updateScheduleOrdering() {
|
325 | 325 | @Override
|
326 | 326 | public int[] getPeerCount()
|
327 | 327 | {
|
328 |
| - peer_count_active_time = SystemTime.getMonotonousTime(); |
| 328 | + peer_count_active_time_mono = SystemTime.getMonotonousTime(); |
329 | 329 |
|
330 | 330 | return( last_peer_count );
|
331 | 331 | }
|
332 | 332 |
|
333 | 333 | @Override
|
334 | 334 | public int[] getPieceCount()
|
335 | 335 | {
|
336 |
| - piece_count_active_time = SystemTime.getMonotonousTime(); |
| 336 | + piece_count_active_time_mono = SystemTime.getMonotonousTime(); |
337 | 337 |
|
338 | 338 | return( last_piece_count );
|
339 | 339 | }
|
340 | 340 |
|
341 | 341 | protected static class
|
342 |
| - instanceWrapper implements Comparable |
| 342 | + instanceWrapper implements Comparable<instanceWrapper> |
343 | 343 | {
|
344 | 344 | private final PeerControlInstance instance;
|
345 | 345 | private boolean unregistered;
|
@@ -397,8 +397,8 @@ public int[] getPieceCount()
|
397 | 397 | }
|
398 | 398 |
|
399 | 399 | @Override
|
400 |
| - public int compareTo(Object o) { |
401 |
| - return instance.getSchedulePriority()-((instanceWrapper)o).instance.getSchedulePriority(); |
| 400 | + public int compareTo(instanceWrapper o) { |
| 401 | + return instance.getSchedulePriority()-o.instance.getSchedulePriority(); |
402 | 402 | }
|
403 | 403 | }
|
404 | 404 | }
|
0 commit comments