Search in sources :

Example 1 with ListStack

use of net.sourceforge.processdash.data.compiler.ListStack in project processdash by dtuma.

the class CompiledFunction method recalc.

protected void recalc() {
    if (isDisposed())
        // we have been disposed.  Don't try to recalc.
        return;
    Set calcNameSet = (Set) CURRENTLY_CALCULATING.get();
    if (calcNameSet.contains(name)) {
        logger.warning("Encountered recursively defined data " + "when calculating " + name + " - ABORTING");
        // break out of infinite loops.
        return;
    }
    SimpleData oldValue = value;
    SimpleData newValue = null;
    String newAlias = null;
    SubscribingExpressionContext context = null;
    // attempt to perform the calculation up to 10 times.  (This should
    // be more than generous - even one retry should be rare.)
    int retryCount = 10;
    while (retryCount-- > 0 && extChanges.isDirty()) {
        context = new SubscribingExpressionContext(data, prefix, this, name, currentSubscriptions);
        ListStack stack = new ListStack();
        int changeCount = -1;
        try {
            calcNameSet.add(name);
            changeCount = extChanges.getUnhandledChangeCount();
            script.run(stack, context);
            newAlias = (String) stack.peekDescriptor();
            newValue = (SimpleData) stack.pop();
            if (newValue != null && newAlias == null)
                newValue = (SimpleData) newValue.getEditable(false);
        } catch (ExecutionException e) {
            logger.warning("Error executing " + name + ": " + e);
            newValue = null;
        } finally {
            calcNameSet.remove(name);
        }
        if (extChanges.maybeClearDirty(changeCount, newValue, newAlias))
            break;
        else if (retryCount > 0)
            logger.finer("Retrying calculating " + name);
    }
    if (context == null)
        // of the loop above.  Nothing needs to be done.
        return;
    if (retryCount <= 0)
        logger.warning("Ran out of retries while calculating " + name);
    context.removeOldSubscriptions();
    currentSubscriptions.trimToSize();
    if (oldValue != VALUE_NEVER_QUERIED && !eq(oldValue, value))
        data.valueRecalculated(name, this);
}
Also used : Set(java.util.Set) LightweightSynchronizedSet(net.sourceforge.processdash.util.LightweightSynchronizedSet) HashSet(java.util.HashSet) LightweightSet(net.sourceforge.processdash.util.LightweightSet) ListStack(net.sourceforge.processdash.data.compiler.ListStack) SimpleData(net.sourceforge.processdash.data.SimpleData) ExecutionException(net.sourceforge.processdash.data.compiler.ExecutionException)

Example 2 with ListStack

use of net.sourceforge.processdash.data.compiler.ListStack in project processdash by dtuma.

the class DataRepository method evaluate.

public SimpleData evaluate(CompiledScript script, String prefix) throws ExecutionException {
    ListStack stack = new ListStack();
    ExpressionContext context = new SimpleExpressionContext(prefix);
    script.run(stack, context);
    SimpleData value = (SimpleData) stack.pop();
    if (value != null)
        value = (SimpleData) value.getEditable(false);
    return value;
}
Also used : ExpressionContext(net.sourceforge.processdash.data.compiler.ExpressionContext) ListStack(net.sourceforge.processdash.data.compiler.ListStack) SimpleData(net.sourceforge.processdash.data.SimpleData)

Example 3 with ListStack

use of net.sourceforge.processdash.data.compiler.ListStack in project processdash by dtuma.

the class Nvl method call.

/** Perform a procedure call.
     *
     * This method <b>must</b> be thread-safe.
     */
public Object call(List arguments, ExpressionContext context) {
    ListStack stack = null;
    for (Iterator iter = arguments.iterator(); iter.hasNext(); ) {
        Object arg = iter.next();
        if (arg instanceof CompiledScript) {
            try {
                CompiledScript script = (CompiledScript) arg;
                if (stack == null)
                    stack = new ListStack();
                else
                    stack.clear();
                script.run(stack, context);
                arg = stack.pop();
            } catch (Exception e) {
            }
        }
        if (arg instanceof SimpleData && !isBadValue((SimpleData) arg))
            return arg;
    }
    return null;
}
Also used : CompiledScript(net.sourceforge.processdash.data.compiler.CompiledScript) ListStack(net.sourceforge.processdash.data.compiler.ListStack) Iterator(java.util.Iterator) SimpleData(net.sourceforge.processdash.data.SimpleData)

Example 4 with ListStack

use of net.sourceforge.processdash.data.compiler.ListStack in project processdash by dtuma.

the class Eval method call.

/** Perform a procedure call.
     *
     * This method <b>must</b> be thread-safe.
     */
public Object call(List arguments, ExpressionContext context) {
    String expression = asString(getArg(arguments, 0));
    if (expression == null || expression.length() == 0)
        return null;
    String prefix = asString(getArg(arguments, 1));
    CompiledScript script = Compiler.compile(expression);
    try {
        Stack stack = new ListStack();
        if (prefix != null)
            context = new RelativeExpressionContext(context, prefix);
        script.run(stack, context);
        return stack.pop();
    } catch (ExecutionException ee) {
        return null;
    }
}
Also used : CompiledScript(net.sourceforge.processdash.data.compiler.CompiledScript) RelativeExpressionContext(net.sourceforge.processdash.data.compiler.RelativeExpressionContext) ListStack(net.sourceforge.processdash.data.compiler.ListStack) ExecutionException(net.sourceforge.processdash.data.compiler.ExecutionException) Stack(net.sourceforge.processdash.data.compiler.Stack) ListStack(net.sourceforge.processdash.data.compiler.ListStack)

Example 5 with ListStack

use of net.sourceforge.processdash.data.compiler.ListStack in project processdash by dtuma.

the class Filter method call.

/** Perform a procedure call.
     *
     * This method <b>must</b> be thread-safe.
     */
public Object call(List arguments, ExpressionContext context) {
    CompiledScript script = null;
    try {
        script = (CompiledScript) arguments.get(0);
    } catch (ClassCastException cce) {
    }
    if (script == null)
        return null;
    ListData result = new ListData();
    LocalExpressionContext lContext = new LocalExpressionContext(context);
    ListStack stack = new ListStack();
    Iterator i = collapseLists(arguments, 1).iterator();
    Object item;
    while (i.hasNext()) try {
        lContext.setLocalValue(item = i.next());
        stack.clear();
        script.run(stack, lContext);
        handleItem(result, item, stack.pop());
    } catch (Exception e) {
    }
    return result;
}
Also used : CompiledScript(net.sourceforge.processdash.data.compiler.CompiledScript) LocalExpressionContext(net.sourceforge.processdash.data.compiler.LocalExpressionContext) ListStack(net.sourceforge.processdash.data.compiler.ListStack) Iterator(java.util.Iterator) ListData(net.sourceforge.processdash.data.ListData)

Aggregations

ListStack (net.sourceforge.processdash.data.compiler.ListStack)6 SimpleData (net.sourceforge.processdash.data.SimpleData)4 CompiledScript (net.sourceforge.processdash.data.compiler.CompiledScript)4 Iterator (java.util.Iterator)2 ExecutionException (net.sourceforge.processdash.data.compiler.ExecutionException)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ListData (net.sourceforge.processdash.data.ListData)1 ExpressionContext (net.sourceforge.processdash.data.compiler.ExpressionContext)1 LocalExpressionContext (net.sourceforge.processdash.data.compiler.LocalExpressionContext)1 RelativeExpressionContext (net.sourceforge.processdash.data.compiler.RelativeExpressionContext)1 Stack (net.sourceforge.processdash.data.compiler.Stack)1 LightweightSet (net.sourceforge.processdash.util.LightweightSet)1 LightweightSynchronizedSet (net.sourceforge.processdash.util.LightweightSynchronizedSet)1