use of com.revolsys.parallel.channel.ClosedException in project com.revolsys.open by revolsys.
the class ScriptExecutorProcess method executeScript.
private void executeScript(final Record record) {
try {
final JexlContext context = new HashMapContext();
final Map<String, Object> vars = new HashMap<>(this.attributes);
vars.putAll(record);
context.setVars(vars);
final Map<String, Object> scriptParams = new HashMap<>();
scriptParams.putAll(this.attributes);
for (final Entry<String, Expression> param : this.expressions.entrySet()) {
final String key = param.getKey();
final Expression expression = param.getValue();
final Object value = JexlUtil.evaluateExpression(context, expression);
scriptParams.put(key, value);
}
final ScriptExecutorRunnable scriptRunner = new ScriptExecutorRunnable(this.script, scriptParams);
if (this.executor == null) {
scriptRunner.run();
} else {
while (this.tasks.size() >= this.maxConcurrentScripts) {
try {
synchronized (this) {
ThreadUtil.pause(1000);
for (final Iterator<Future<?>> taskIter = this.tasks.iterator(); taskIter.hasNext(); ) {
final Future<?> task = taskIter.next();
if (task.isDone()) {
taskIter.remove();
}
}
}
} catch (final ThreadInterruptedException e) {
throw new ClosedException(e);
}
}
final Future<?> future = this.executor.submit(scriptRunner);
this.tasks.add(future);
}
} catch (final ThreadDeath e) {
throw e;
} catch (final Throwable t) {
Logs.error(this, t);
}
}
Aggregations