use of cbit.vcell.client.task.AsynchClientTask.KeyInfo in project vcell by virtualcell.
the class ClientTaskDispatcher method runTask.
/**
* call currentTask.run(hash) with log4j logging; check for required keys
* @param currentTask not null
* @param hash not null
* @param taskList current set of tasks being dispatched
* @throws Exception
*/
private static void runTask(AsynchClientTask currentTask, Hashtable<String, Object> hash, Collection<AsynchClientTask> taskList) throws Exception {
if (lg.isDebugEnabled()) {
String msg = "Thread " + Thread.currentThread().getName() + " calling task " + currentTask.getTaskName();
if (lg.isDebugEnabled()) {
Object obj = hash.get(STACK_TRACE_ARRAY);
StackTraceElement[] ste = BeanUtils.downcast(StackTraceElement[].class, obj);
if (ste != null) {
msg += '\n' + StringUtils.join(ste, '\n');
}
lg.debug(msg);
} else {
lg.debug(msg);
}
}
// check required elements present
StringBuilder sb = null;
for (KeyInfo requiredKey : currentTask.requiredKeys()) {
Object obj = hash.get(requiredKey.name);
if (obj == null) {
if (sb == null)
sb = initStringBuilder(currentTask);
sb.append("Missing required key " + requiredKey.name + '\n');
continue;
}
Class<?> foundClass = obj.getClass();
if (!requiredKey.clzz.isAssignableFrom(foundClass)) {
if (sb == null)
sb = initStringBuilder(currentTask);
sb.append("key " + requiredKey.name + " type " + foundClass.getName() + " not of required type " + requiredKey.clzz.getName());
sb.append('\n');
}
}
if (sb == null) {
// no problems found
currentTask.run(hash);
return;
}
sb.append("Prior tasks\n");
for (AsynchClientTask pt : taskList) {
if (pt == currentTask) {
break;
}
sb.append('\t' + pt.getTaskName() + '\n');
}
hash.put(HASH_DATA_ERROR, HASH_DATA_ERROR);
throw new ProgrammingException(sb.toString());
}
Aggregations