Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit adcc5d8

Browse files
feffijknack
authored andcommitted
fixed minor code issues (jooby-project#1153)
1 parent ca8ff70 commit adcc5d8

File tree

1 file changed

+20
-21
lines changed
  • modules/jooby-executor/src/main/java/org/jooby/exec

1 file changed

+20
-21
lines changed

modules/jooby-executor/src/main/java/org/jooby/exec/Exec.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ public class Exec implements Module {
364364

365365
private int priority = Thread.NORM_PRIORITY;
366366

367-
private Map<String, Throwing.Function4<String, Integer, Supplier<ThreadFactory>, Map<String, Object>, ExecutorService>> f =
367+
private final Map<String, Throwing.Function4<String, Integer, Supplier<ThreadFactory>, Map<String, Object>, ExecutorService>> f =
368368
/** executor factory. */
369369
ImmutableMap
370370
.of(
@@ -377,7 +377,7 @@ public class Exec implements Module {
377377
return new ForkJoinPool(n, fjwtf(name), null, asyncMode);
378378
});
379379

380-
private String namespace;
380+
private final String namespace;
381381

382382
protected Exec(final String namespace) {
383383
this.namespace = namespace;
@@ -459,14 +459,10 @@ protected void configure(final Env env, final Config conf, final Binder binder,
459459
services.stream()
460460
.filter(it -> it.getKey().equals("default"))
461461
.findFirst()
462-
.ifPresent(e -> {
463-
bind(binder, null, e.getValue());
464-
});
462+
.ifPresent(e -> bind(binder, null, e.getValue()));
465463

466464
env.onStop(() -> {
467-
services.forEach(exec -> Try.run(() -> exec.getValue().shutdown()).onFailure(cause -> {
468-
log.error("shutdown of {} resulted in error", exec.getKey(), cause);
469-
}));
465+
services.forEach(exec -> Try.run(() -> exec.getValue().shutdown()).onFailure(cause -> log.error("shutdown of {} resulted in error", exec.getKey(), cause)));
470466
services.clear();
471467
});
472468
}
@@ -528,8 +524,7 @@ private static List<Map<String, Object>> executors(final ConfigValue candidate,
528524
for (Entry<String, ConfigValue> executor : conf.entrySet()) {
529525
String name = executor.getKey();
530526
Object value = executor.getValue().unwrapped();
531-
Map<String, Object> options = new HashMap<>();
532-
options.putAll(executor(name, daemon, priority, n, value));
527+
Map<String, Object> options = new HashMap<>(executor(name, daemon, priority, n, value));
533528
result.add(options);
534529
}
535530
return result;
@@ -556,8 +551,7 @@ private static Map<String, Object> executor(final String name, final boolean dae
556551
Integer.parseInt(config.get("size").toString()) : n);
557552
options.put("daemon", config.containsKey("daemon") ?
558553
Boolean.parseBoolean(config.get("daemon").toString()) : daemon);
559-
options.put("asyncMode", config.containsKey("asyncMode") ?
560-
Boolean.parseBoolean(config.get("asyncMode").toString()) : false);
554+
options.put("asyncMode", config.containsKey("asyncMode") && Boolean.parseBoolean(config.get("asyncMode").toString()));
561555
options.put("priority", config.containsKey("priority") ?
562556
Integer.parseInt(config.get("priority").toString()) : priority);
563557
} else {
@@ -567,15 +561,20 @@ private static Map<String, Object> executor(final String name, final boolean dae
567561
String[] opt = option.split("=");
568562
String optname = opt[0].trim();
569563
Object optvalue;
570-
if (optname.equals("daemon")) {
571-
optvalue = opt.length > 1 ? Boolean.parseBoolean(opt[1].trim()) : daemon;
572-
} else if (optname.equals("asyncMode")) {
573-
optvalue = opt.length > 1 ? Boolean.parseBoolean(opt[1].trim()) : false;
574-
} else if (optname.equals("priority")) {
575-
optvalue = opt.length > 1 ? Integer.parseInt(opt[1].trim()) : priority;
576-
} else {
577-
optvalue = opt.length > 1 ? Integer.parseInt(opt[1].trim()) : n;
578-
options.put("type", optname);
564+
switch (optname) {
565+
case "daemon":
566+
optvalue = opt.length > 1 ? Boolean.parseBoolean(opt[1].trim()) : daemon;
567+
break;
568+
case "asyncMode":
569+
optvalue = opt.length > 1 && Boolean.parseBoolean(opt[1].trim());
570+
break;
571+
case "priority":
572+
optvalue = opt.length > 1 ? Integer.parseInt(opt[1].trim()) : priority;
573+
break;
574+
default:
575+
optvalue = opt.length > 1 ? Integer.parseInt(opt[1].trim()) : n;
576+
options.put("type", optname);
577+
break;
579578
}
580579
options.put(optname, optvalue);
581580
}

0 commit comments

Comments
 (0)