Search in sources :

Example 1 with ScriptExecutorRunnable

use of com.revolsys.parallel.tools.ScriptExecutorRunnable in project com.revolsys.open by revolsys.

the class ScriptExecutorBoundingBoxTaskSplitter method execute.

@Override
public void execute(final BoundingBox boundingBox) {
    this.outsideBoundaryObjects.expandBoundary(boundingBox.toGeometry());
    final ScriptExecutorRunnable executor = new ScriptExecutorRunnable(this.scriptName, this.attributes);
    executor.setLogScriptInfo(isLogScriptInfo());
    executor.addBean("boundingBox", boundingBox);
    final Set<Record> objects = this.outsideBoundaryObjects.getAndClearObjects();
    executor.addBean("outsideBoundaryObjects", objects);
    executor.addBeans(this.beans);
    executor.addBeans(this.inChannels);
    executor.addBeans(this.outChannels);
    executor.run();
}
Also used : Record(com.revolsys.record.Record) ScriptExecutorRunnable(com.revolsys.parallel.tools.ScriptExecutorRunnable)

Example 2 with ScriptExecutorRunnable

use of com.revolsys.parallel.tools.ScriptExecutorRunnable 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);
    }
}
Also used : ClosedException(com.revolsys.parallel.channel.ClosedException) HashMap(java.util.HashMap) ThreadInterruptedException(com.revolsys.parallel.ThreadInterruptedException) HashMapContext(org.apache.commons.jexl.context.HashMapContext) Expression(org.apache.commons.jexl.Expression) JexlContext(org.apache.commons.jexl.JexlContext) Future(java.util.concurrent.Future) ScriptExecutorRunnable(com.revolsys.parallel.tools.ScriptExecutorRunnable)

Aggregations

ScriptExecutorRunnable (com.revolsys.parallel.tools.ScriptExecutorRunnable)2 ThreadInterruptedException (com.revolsys.parallel.ThreadInterruptedException)1 ClosedException (com.revolsys.parallel.channel.ClosedException)1 Record (com.revolsys.record.Record)1 HashMap (java.util.HashMap)1 Future (java.util.concurrent.Future)1 Expression (org.apache.commons.jexl.Expression)1 JexlContext (org.apache.commons.jexl.JexlContext)1 HashMapContext (org.apache.commons.jexl.context.HashMapContext)1