Add support for alternative executor configuration.
@@ -187,18 +187,8 @@ public class Exec implements Module {
ImmutableMap
.of(
"cached", (name, n, tf, opts) -> Executors.newCachedThreadPool(tf.get()),
- "fixed", (name, n, tf, opts) -> {
- Optional<Integer> size = Optional.ofNullable(
- opts.containsKey("size") ? Integer.parseInt(opts.get("size").toString()) : null
- );
- return Executors.newFixedThreadPool(size.orElse(n), tf.get());
- },
- "scheduled", (name, n, tf, opts) -> {
- Optional<Integer> size = Optional.ofNullable(
- opts.containsKey("size") ? Integer.parseInt(opts.get("size").toString()) : null
- );
- return Executors.newScheduledThreadPool(size.orElse(n), tf.get());
- },
+ "fixed", (name, n, tf, opts) -> Executors.newFixedThreadPool(n, tf.get()),
+ "scheduled", (name, n, tf, opts) -> Executors.newScheduledThreadPool(n, tf.get()),
"forkjoin", (name, n, tf, opts) -> {
boolean asyncMode = Boolean.parseBoolean(opts.getOrDefault("asyncMode", "false")
.toString());
@@ -363,6 +353,7 @@ public class Exec implements Module {
return result;
}
+ @SuppressWarnings("unchecked")
private static Map<String, Object> executor(final String name, final boolean daemon,
final int priority,
final int n,
@@ -371,6 +362,20 @@ public class Exec implements Module {
options.put("name", name);
options.put("daemon", daemon);
options.put("priority", priority);
+ if (value instanceof Map) {
+ Map<String, Object> config = (Map<String, Object>) value;
+ String type = config.get("type").toString();
+ options.put("type", type);
+ options.put(type, config.containsKey("size") ?
+ Integer.parseInt(config.get("size").toString()) : n);
+ options.put("daemon", config.containsKey("daemon") ?
+ Boolean.parseBoolean(config.get("daemon").toString()) : daemon);
+ options.put("asyncMode", config.containsKey("asyncMode") ?
+ Boolean.parseBoolean(config.get("asyncMode").toString()) : false);
+ options.put("priority", config.containsKey("priority") ?
+ Integer.parseInt(config.get("priority").toString()) : priority);
+ } else {
+ System.out.println("Bere");
Iterable<String> spec = Splitter.on(",").trimResults().omitEmptyStrings()
.split(value.toString());
for (String option : spec) {
@@ -389,6 +394,7 @@ public class Exec implements Module {
}
options.put(optname, optvalue);
}
+ }
return options;
}
