Search in sources :

Example 1 with GenerateDatapointInfo

use of kutch.biff.marvin.utility.GenerateDatapointInfo in project Board-Instrumentation-Framework by intel.

the class ConfigurationReader method ReadGenerateDatapointInfo.

public static GenerateDatapointInfo ReadGenerateDatapointInfo(FrameworkNode inputNode) {
    ArrayList<Pair<String, String>> maskList = new ArrayList<>();
    ArrayList<Pair<String, String>> excludeList = new ArrayList<>();
    @SuppressWarnings("unused") ListSortMethod sortPolicy = ListSortMethod.ASCENDING;
    int precision = -1;
    boolean hasListEntry = false;
    int listEntry = 0;
    if (!inputNode.hasAttribute("Method")) {
        LOGGER.severe("GenerateDatapoint did not specify the Method of generate. ");
        return null;
    }
    boolean IsGenerateNamespaceList = inputNode.getAttribute("Method").equalsIgnoreCase("MakeNamespaceList") || inputNode.getAttribute("Method").equalsIgnoreCase("MakeIDList");
    String strMethod = inputNode.getAttribute("Method");
    Pair<String, String> genDPInfo = getNamespaceAndIdPattern(inputNode, false);
    Pair<ValueRange, String> rangeInfo = WidgetBuilder.ReadMinionSrcIndexInfo(inputNode);
    if (null == genDPInfo) {
        LOGGER.severe("Invalid GenerateDatapoint.");
        return null;
    }
    for (FrameworkNode node : inputNode.getChildNodes(true)) {
        if (node.getNodeName().equalsIgnoreCase("InputPattern")) {
            Pair<String, String> input = getNamespaceAndIdPattern(node, IsGenerateNamespaceList);
            if (null == input) {
                LOGGER.severe(String.format("Invalid GenerateDatapoint %s:%s -->%s", genDPInfo.getKey(), genDPInfo.getValue(), node.getAttributeList()));
                return null;
            }
            maskList.add(input);
        } else if (node.getNodeName().equalsIgnoreCase("ExcludePattern")) {
            Pair<String, String> exclude = getNamespaceAndIdPattern(node, IsGenerateNamespaceList);
            if (null == exclude) {
                LOGGER.severe(String.format("Invalid GenerateDatapoint %s:%s -->%s", genDPInfo.getKey(), genDPInfo.getValue(), node.getAttributeList()));
                return null;
            }
            excludeList.add(exclude);
        } else if (node.getNodeName().equalsIgnoreCase("ListEntry")) {
            try {
                listEntry = node.getIntegerContent();
                hasListEntry = true;
            } catch (NumberFormatException ex) {
                LOGGER.severe("Invalid ListEntry specified for <GenerateDatapoint>: " + node.getTextContent());
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("Decimals")) {
            try {
                precision = node.getIntegerContent();
            } catch (NumberFormatException ex) {
                LOGGER.severe("Invalid Decimals specified for <GenerateDatapoint>: " + node.getTextContent());
                return null;
            }
        } else if (node.getNodeName().equalsIgnoreCase("Refresh")) {
        // handle below
        } else if (node.getNodeName().equalsIgnoreCase("Sort")) {
            if (strMethod.equalsIgnoreCase("MakeList") || strMethod.equalsIgnoreCase("MakeNamespaceList") || strMethod.equalsIgnoreCase("MakeIDList")) {
                String strSort = node.getTextContent();
                if (strSort.equalsIgnoreCase("Ascending")) {
                    sortPolicy = ListSortMethod.ASCENDING;
                } else if (strSort.equalsIgnoreCase("Descending")) {
                    sortPolicy = ListSortMethod.DESCENDING;
                } else if (strSort.equalsIgnoreCase("None")) {
                    sortPolicy = ListSortMethod.NONE;
                } else {
                    LOGGER.severe("Invalid Sort Method for Generate Datapoint: " + strSort);
                    return null;
                }
            } else {
                LOGGER.warning("Specified Sort Method for Generate Datapoint, however " + strMethod + " does not support sorting.  Ignoring.");
            }
        } else {
            LOGGER.severe("Unknown entry in <GenerateDatapoint>: " + node.getNodeName());
            return null;
        }
    }
    GenerateDatapointInfo info = new GenerateDatapointInfo(genDPInfo.getKey(), genDPInfo.getValue(), maskList, excludeList, rangeInfo.getKey(), rangeInfo.getValue());
    if (hasListEntry) {
        if (!info.setListEntry(listEntry)) {
            LOGGER.severe("Invalid ListEntry specified for <GenerateDatapoint>: " + Integer.toString(listEntry));
            return null;
        }
        if (inputNode.hasAttribute("Separator")) {
            String token = inputNode.getAttribute("Separator");
            info.setSplitToken(token);
        } else {
            info.setSplitToken(",");
        }
    }
    if (inputNode.getAttribute("Method").equalsIgnoreCase("Add")) {
        info.setMethod(GenerateDatapointInfo.GenerateMethod.ADD);
    } else if (inputNode.getAttribute("Method").equalsIgnoreCase("Average")) {
        info.setMethod(GenerateDatapointInfo.GenerateMethod.AVERAGE);
    } else if (inputNode.getAttribute("Method").equalsIgnoreCase("MakeList")) {
        info.setMethod(GenerateDatapointInfo.GenerateMethod.MAKE_LIST);
    } else if (inputNode.getAttribute("Method").equalsIgnoreCase("MakeNamespaceList")) {
        info.setMethod(GenerateDatapointInfo.GenerateMethod.MAKE_NAMESPACE_LIST);
    } else if (inputNode.getAttribute("Method").equalsIgnoreCase("MakeIDList")) {
        info.setMethod(GenerateDatapointInfo.GenerateMethod.MAKE_ID_LIST);
    } else if (inputNode.getAttribute("Method").equalsIgnoreCase("Proxy")) {
        info.setMethod(GenerateDatapointInfo.GenerateMethod.PROXY);
        if (inputNode.hasAttribute("ProxyID")) {
            String proxyID = inputNode.getAttribute("ProxyID");
            info.setProxyID(proxyID);
        } else {
            LOGGER.warning("GenerateDatapoint [Proxy] did not have a ProxyID, you will be unable to change it with a task.");
            String proxyID = Long.toString(new Random().nextLong());
            info.setProxyID(proxyID);
        }
    } else if (inputNode.getAttribute("Method").equalsIgnoreCase("SplitList")) {
        info.setMethod(GenerateDatapointInfo.GenerateMethod.SPLIT_LIST);
        if (inputNode.hasAttribute("Separator")) {
            String token = inputNode.getAttribute("Separator");
            info.setSplitToken(token);
        } else {
            info.setSplitToken(",");
        }
    } else if (inputNode.getAttribute("Method").equalsIgnoreCase("GetListSize")) {
        info.setMethod(GenerateDatapointInfo.GenerateMethod.GET_LIST_SIZE);
    } else if (inputNode.getAttribute("Method").equalsIgnoreCase("MakeIndexList")) {
        info.setMethod(GenerateDatapointInfo.GenerateMethod.MAKE_INDEX_LIST);
    } else {
        LOGGER.severe("Invalid Method specified for GenerateDatapoint: " + inputNode.getAttribute("Method"));
        return null;
    }
    if (inputNode.hasAttribute("Scale")) {
        try {
            double scale = Double.parseDouble(inputNode.getAttribute("Scale"));
            info.setScale(scale);
        } catch (Exception ex) {
        }
    }
    if (inputNode.hasChild("Refresh")) {
        FrameworkNode rfNode = inputNode.getChild("Refresh");
        if (rfNode.hasAttribute("Frequency")) {
            int freq = rfNode.getIntegerAttribute("Frequency", -1);
            if (freq > 0) {
                info.setMinFrequency(freq);
            } else {
                return null;
            }
        } else {
            LOGGER.severe("<GenerateDatapoint> specified <Refresh> without a Frequency.");
            return null;
        }
        if (rfNode.hasAttribute("Policy")) {
            String strPolicy = rfNode.getAttribute("Policy");
            if (strPolicy.equalsIgnoreCase("REMOVE")) {
                info.setPolicy(GenerateDatapointInfo.RefreshPolicy.REMOVE);
            } else if (strPolicy.equalsIgnoreCase("REUSE")) {
                info.setPolicy(GenerateDatapointInfo.RefreshPolicy.REUSE);
            } else if (strPolicy.equalsIgnoreCase("ZERO_OUT")) {
                info.setPolicy(GenerateDatapointInfo.RefreshPolicy.ZERO_OUT);
            } else {
                LOGGER.severe("<GenerateDatapoint> specified invalid <Refresh> without a policy: " + strPolicy);
                return null;
            }
        } else {
            LOGGER.severe("<GenerateDatapoint> specified <Refresh> without a Policy.");
            return null;
        }
    }
    info.setPrecision(precision);
    return info;
}
Also used : ArrayList(java.util.ArrayList) FrameworkNode(kutch.biff.marvin.utility.FrameworkNode) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) ValueRange(java.time.temporal.ValueRange) GenerateDatapointInfo(kutch.biff.marvin.utility.GenerateDatapointInfo) Random(java.util.Random) ListSortMethod(kutch.biff.marvin.utility.GenerateDatapointInfo.ListSortMethod) Pair(javafx.util.Pair)

Example 2 with GenerateDatapointInfo

use of kutch.biff.marvin.utility.GenerateDatapointInfo in project Board-Instrumentation-Framework by intel.

the class DataManager method ChangeValue.

public void ChangeValue(String ID, String Namespace, String Value) {
    boolean OnDemandItemFound = false;
    boolean OnDemandTabFound = false;
    synchronized (this) {
        for (Pair<DynamicItemInfoContainer, OnDemandWidgetBuilder> entry : _OnDemandQueue) {
            if (entry.getKey().Matches(Namespace, ID, Value)) {
                LateCreateTask objTask = new LateCreateTask(entry.getValue(), Namespace, ID, Value, entry.getKey().getLastMatchedSortStr());
                TaskManager.getTaskManager().AddDeferredTaskObject(objTask);
                OnDemandItemFound = true;
                if (entry.getValue() instanceof OnDemandTabBuilder) {
                    OnDemandTabFound = true;
                }
            }
        }
        if (OnDemandItemFound) {
            Configuration.getConfig().setCursorToWait();
        }
        // go and handle any GenerateDatapoint stuff
        for (GenerateDatapointInfo info : __GenerateDatapointList) {
            if (info.Matches(Namespace, ID)) {
                info.BuildDatapoint(Namespace, ID);
            }
        }
    }
    synchronized (this) {
        String Key = Utility.generateKey(Namespace, ID);
        _UpdateCount++;
        boolean inWildcard = HandleWildcardChangeValue(ID, Namespace, Value);
        if (false == _DataMap.containsKey(Key)) {
            _DataMap.put(Key, new DataSet());
            if (false == inWildcard) {
                _UnassignedDataPoints++;
                // nifty stuff to dynamically add a tab to show 'unregistered' data points.
                if (kutch.biff.marvin.widget.DynamicTabWidget.isEnabled()) {
                    DynamicDebugWidgetTask objTask = new DynamicDebugWidgetTask(Namespace, ID, Value);
                    TaskManager.getTaskManager().AddPostponedTask(objTask, 0);
                }
            }
        }
        if (// if didn't exist, is created above
        _DataMap.containsKey(Key)) {
            _DataMap.get(Key).setLatestValue(Value);
        }
    }
    if (true == OnDemandTabFound) {
    // ApplyOnDemandTabStyle objTask = new ApplyOnDemandTabStyle();
    // TaskManager.getTaskManager().AddPostponedTask(objTask, 1000);
    }
}
Also used : DynamicItemInfoContainer(kutch.biff.marvin.utility.DynamicItemInfoContainer) OnDemandWidgetBuilder(kutch.biff.marvin.widget.widgetbuilder.OnDemandWidgetBuilder) GenerateDatapointInfo(kutch.biff.marvin.utility.GenerateDatapointInfo) LateCreateTask(kutch.biff.marvin.task.LateCreateTask) OnDemandTabBuilder(kutch.biff.marvin.widget.widgetbuilder.OnDemandTabBuilder) DynamicDebugWidgetTask(kutch.biff.marvin.task.DynamicDebugWidgetTask)

Aggregations

GenerateDatapointInfo (kutch.biff.marvin.utility.GenerateDatapointInfo)2 IOException (java.io.IOException)1 ValueRange (java.time.temporal.ValueRange)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Pair (javafx.util.Pair)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 DynamicDebugWidgetTask (kutch.biff.marvin.task.DynamicDebugWidgetTask)1 LateCreateTask (kutch.biff.marvin.task.LateCreateTask)1 DynamicItemInfoContainer (kutch.biff.marvin.utility.DynamicItemInfoContainer)1 FrameworkNode (kutch.biff.marvin.utility.FrameworkNode)1 ListSortMethod (kutch.biff.marvin.utility.GenerateDatapointInfo.ListSortMethod)1 OnDemandTabBuilder (kutch.biff.marvin.widget.widgetbuilder.OnDemandTabBuilder)1 OnDemandWidgetBuilder (kutch.biff.marvin.widget.widgetbuilder.OnDemandWidgetBuilder)1 SAXException (org.xml.sax.SAXException)1