Skip to content

Commit b2344ec

Browse files
committed
pool: extract comparator creation to function in IoQueueManager
Motivation: As suggested by IntelliJ IDEA, extract the creation of the comparator to its own function for clarity and encapsulation. Modification: Move the logic creating a comparator from a conditional to its own function, `getPrioritizedRequestComparator()` Also fix a minor typo in a comment. Result: Code is clearer and less susceptible to unwanted fragmentation during update or refactoring. Target: master Patch: https://rb.dcache.org/r/14525/ Requires-notes: NO Requires-book: NO Acked-By: Tigran Mkrtchyan
1 parent 8a75cc1 commit b2344ec

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

modules/dcache/src/main/java/org/dcache/pool/classic/IoQueueManager.java

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.dcache.pool.FaultEvent;
3333
import org.dcache.pool.FaultListener;
3434
import org.dcache.pool.classic.MoverRequestScheduler.Order;
35+
import org.dcache.pool.classic.MoverRequestScheduler.PrioritizedRequest;
3536
import org.dcache.util.IoPriority;
3637
import org.slf4j.Logger;
3738
import org.slf4j.LoggerFactory;
@@ -438,29 +439,12 @@ public Serializable call() throws CommandException {
438439
}
439440

440441
if (isBinary) {
441-
// ignore sortin and grouping by queue name if binnary
442+
// ignore sorting and grouping by queue name if binary
442443
return queues.stream().flatMap(s -> s.getJobInfos().stream())
443444
.toArray(IoJobInfo[]::new);
444445
} else {
445446

446-
Comparator<MoverRequestScheduler.PrioritizedRequest> comparator;
447-
if (sortBySize) {
448-
comparator = (b, a) -> Long.compare(
449-
a.getMover().getBytesTransferred(), b.getMover().getBytesTransferred()
450-
);
451-
} else if (sortByTime) {
452-
comparator = (b, a) -> Long.compare(
453-
a.getMover().getLastTransferred(), b.getMover().getLastTransferred()
454-
);
455-
} else {
456-
comparator = (b, a) -> Integer.compare(
457-
a.getId(), b.getId()
458-
);
459-
}
460-
461-
if (reverseSort) {
462-
comparator = comparator.reversed();
463-
}
447+
Comparator<PrioritizedRequest> comparator = getPrioritizedRequestComparator();
464448

465449
StringBuilder sb = new StringBuilder();
466450
if (groupByQueue) {
@@ -478,6 +462,28 @@ public Serializable call() throws CommandException {
478462
return sb.toString();
479463
}
480464
}
465+
466+
private Comparator<PrioritizedRequest> getPrioritizedRequestComparator() {
467+
Comparator<PrioritizedRequest> comparator;
468+
if (sortBySize) {
469+
comparator = (b, a) -> Long.compare(
470+
a.getMover().getBytesTransferred(), b.getMover().getBytesTransferred()
471+
);
472+
} else if (sortByTime) {
473+
comparator = (b, a) -> Long.compare(
474+
a.getMover().getLastTransferred(), b.getMover().getLastTransferred()
475+
);
476+
} else {
477+
comparator = (b, a) -> Integer.compare(
478+
a.getId(), b.getId()
479+
);
480+
}
481+
482+
if (reverseSort) {
483+
comparator = comparator.reversed();
484+
}
485+
return comparator;
486+
}
481487
}
482488

483489
@Command(name = "p2p ls", hint = "list pool to pool source movers",

0 commit comments

Comments
 (0)