@Override
public List<Future<T>> executeDistributedTask(String distributedCallableFqn,
String executionPolicyName, String failoverPolicyFqn, String nodeAddress, Map<String, String> params) {
Cache<K, V> cache = (Cache<K, V>) service.getCache(null);
DistributedExecutorService des = new DefaultExecutorService(cache);
Callable<T> callable = null;
DistributedTaskBuilder<T> taskBuilder = null;
List<Future<T>> result = null;
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (distributedCallableFqn == null) {
log.fatal("The distributedCallableFqn parameter must be specified.");
} else {
try {
callable = Utils.instantiate(classLoader, distributedCallableFqn);
taskBuilder = des.createDistributedTaskBuilder(callable);
callable = (Callable<T>) Utils.invokeMethodWithString(callable, params);
} catch (Exception e1) {
throw (new IllegalArgumentException("Could not instantiate '" + distributedCallableFqn + "' as a Callable",
e1));
}
}
if (callable != null) {
if (executionPolicyName != null) {
DistributedTaskExecutionPolicy executionPolicy = Enum.valueOf(DistributedTaskExecutionPolicy.class,
executionPolicyName);
if (executionPolicy == null) {
log.error("No DistributedTaskExecutionPolicy found with name: " + executionPolicyName);
} else {
taskBuilder = taskBuilder.executionPolicy(executionPolicy);
}
}
if (failoverPolicyFqn != null) {
try {
DistributedTaskFailoverPolicy failoverPolicy = Utils.instantiate(classLoader, failoverPolicyFqn);
taskBuilder = taskBuilder.failoverPolicy(failoverPolicy);
} catch (Exception e) {
log.error("Could not instantiate DistributedTaskFailoverPolicy class: " + failoverPolicyFqn, e);
}
}
if (nodeAddress != null) {
Address target = findHostPhysicalAddress(nodeAddress);
if (target == null) {
log.error("No host found with address: " + nodeAddress);
} else {
result = new ArrayList<Future<T>>();
result.add(des.submit(target, taskBuilder.build()));
}
} else {
result = des.submitEverywhere(taskBuilder.build());
}
}
return result;
}