Search in sources :

Example 1 with SimpleData

use of net.sourceforge.processdash.data.SimpleData 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 SimpleData

use of net.sourceforge.processdash.data.SimpleData in project processdash by dtuma.

the class DataMessageHandler method maybeSaveValue.

private void maybeSaveValue(MessageEvent message, String dataName, SimpleData value, Date editTimestamp) {
    // discard malformed data values
    if (value instanceof MalformedData) {
        logger.warning("When handling message with ID '" + message.getMessageId() + //
        "', found malformed definition for '" + dataName + "'. Discarding value.");
        return;
    }
    // check to see if this data element has been edited locally *after*
    // the time in the message. If so, prefer the local edit and discard
    // this data change.
    DataRepository data = ctx.getData();
    String localTimestampName = dataName + "/Edit_Timestamp";
    if (editTimestamp != null) {
        SimpleData localTimestamp = data.getSimpleValue(localTimestampName);
        if (localTimestamp instanceof DateData) {
            if (((DateData) localTimestamp).getValue().after(editTimestamp))
                return;
        }
    }
    // store the value in the data repository
    data.userPutValue(dataName, value);
    if (editTimestamp != null)
        data.putValue(localTimestampName, new DateData(editTimestamp, true));
}
Also used : DateData(net.sourceforge.processdash.data.DateData) SimpleData(net.sourceforge.processdash.data.SimpleData) MalformedData(net.sourceforge.processdash.data.MalformedData)

Example 3 with SimpleData

use of net.sourceforge.processdash.data.SimpleData 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 4 with SimpleData

use of net.sourceforge.processdash.data.SimpleData in project processdash by dtuma.

the class DataRepository method remapDataNames.

/** this renames data values in the global datafile. */
private void remapDataNames(String oldPrefix, String newPrefix) {
    String name, newName;
    DataElement element;
    SaveableData value;
    oldPrefix = oldPrefix + "/";
    newPrefix = newPrefix + "/";
    int oldPrefixLen = oldPrefix.length();
    Iterator k = getInternalKeys();
    while (k.hasNext()) {
        name = (String) k.next();
        if (!name.startsWith(oldPrefix))
            continue;
        element = (DataElement) data.get(name);
        if (element == null || element.isDefaultName() || element.datafile == null || element.datafile.prefix == null || element.datafile.prefix.length() > 0)
            // only remap data which lives in the global datafile.
            continue;
        value = element.getValue();
        // move - but none of that stuff should be moving.
        if (value instanceof SimpleData) {
            newName = newPrefix + name.substring(oldPrefixLen);
            newName = intern(newName, false);
            //System.out.println("renaming " + name + " to " + newName);
            putValue(newName, value.getSimpleValue(), IS_NOT_DEFAULT_VAL);
            putValue(name, null, IS_NOT_DEFAULT_VAL);
        }
    }
}
Also used : Iterator(java.util.Iterator) SimpleData(net.sourceforge.processdash.data.SimpleData) EscapeString(net.sourceforge.processdash.util.EscapeString) SaveableData(net.sourceforge.processdash.data.SaveableData)

Example 5 with SimpleData

use of net.sourceforge.processdash.data.SimpleData 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)

Aggregations

SimpleData (net.sourceforge.processdash.data.SimpleData)164 ListData (net.sourceforge.processdash.data.ListData)20 DoubleData (net.sourceforge.processdash.data.DoubleData)15 SaveableData (net.sourceforge.processdash.data.SaveableData)14 StringData (net.sourceforge.processdash.data.StringData)13 IOException (java.io.IOException)11 DataRepository (net.sourceforge.processdash.data.repository.DataRepository)11 DateData (net.sourceforge.processdash.data.DateData)10 Iterator (java.util.Iterator)9 List (java.util.List)7 PropertyKey (net.sourceforge.processdash.hier.PropertyKey)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 ImmutableDoubleData (net.sourceforge.processdash.data.ImmutableDoubleData)6 NumberData (net.sourceforge.processdash.data.NumberData)6 Element (org.w3c.dom.Element)6 Map (java.util.Map)5 DataContext (net.sourceforge.processdash.data.DataContext)5 EscapeString (net.sourceforge.processdash.util.EscapeString)5 File (java.io.File)4