Search in sources :

Example 11 with TreeNode

use of org.glassfish.flashlight.datatree.TreeNode in project Payara by payara.

the class AbstractTreeNode method getNodesInternal.

private List<TreeNode> getNodesInternal(String pattern, boolean ignoreDisabled, boolean gfv2Compatible) {
    List<TreeNode> regexMatchedTree = new ArrayList<TreeNode>();
    try {
        if (gfv2Compatible)
            pattern = convertGFv2PatternToRegex(pattern);
        Pattern mPattern = Pattern.compile(pattern);
        List<TreeNode> completeTree = traverse(ignoreDisabled);
        for (TreeNode node : completeTree) {
            String path = node.getCompletePathName();
            String path2 = null;
            if (path.indexOf("\\") >= 0)
                path2 = path.replace("\\", "");
            Matcher matcher = mPattern.matcher(path);
            if (matcher.matches()) {
                regexMatchedTree.add(node);
            } else if (path2 != null) {
                Matcher matcher2 = mPattern.matcher(path2);
                if (matcher2.matches()) {
                    regexMatchedTree.add(node);
                }
            }
        }
    } catch (java.util.regex.PatternSyntaxException e) {
    // log this
    // e.printStackTrace ();
    }
    return regexMatchedTree;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) TreeNode(org.glassfish.flashlight.datatree.TreeNode)

Example 12 with TreeNode

use of org.glassfish.flashlight.datatree.TreeNode in project Payara by payara.

the class StatsProviderManagerDelegateImpl method enableStatsProvider.

private void enableStatsProvider(StatsProviderRegistryElement spre) {
    Object statsProvider = spre.getStatsProvider();
    if (logger.isLoggable(Level.FINE))
        logger.fine("Enabling the statsProvider - " + statsProvider.getClass().getName());
    // Check if we already have TreeNodes created
    if (spre.getParentTreeNodePath() == null) {
        /* Verify if PluginPoint exists, create one if it doesn't */
        PluginPoint pp = spre.getPluginPoint();
        String subTreePath = spre.getSubTreePath();
        TreeNode ppNode = getPluginPointNode(pp, serverNode);
        TreeNode parentNode = createSubTree(ppNode, subTreePath);
        List<String> childNodeNames = createTreeForStatsProvider(parentNode, statsProvider);
        spre.setParentTreeNodePath(parentNode.getCompletePathName());
        spre.setChildNodeNames(childNodeNames);
    } else {
        updateTreeNodes(spre, true);
    }
    /* Step 2. reset statistics (OFF --> LOW, OFF --> HIGH)*/
    resetStatistics(spre);
    /* Step 3. register the StatsProvider to the flashlight */
    if (spre.getHandles() == null) {
        // register with flashlight and save the handles
        Collection<ProbeClientMethodHandle> handles = registerStatsProviderToFlashlight(statsProvider);
        spre.setHandles(handles);
    } else {
        // Enable the Flashlight handles for this statsProvider
        for (ProbeClientMethodHandle handle : spre.getHandles()) {
            if (!handle.isEnabled())
                handle.enable();
        }
    }
    /* Step 4. gmbal registration */
    if (AMXReady && getMbeanEnabledValue()) {
        // Create mom root using the statsProvider
        String subTreePath = spre.getSubTreePath();
        ManagedObjectManager mom = spre.getManagedObjectManager();
        if (mom == null) {
            mom = registerGmbal(statsProvider, subTreePath);
            spre.setManagedObjectManager(mom);
        }
    }
    spre.setEnabled(true);
}
Also used : TreeNode(org.glassfish.flashlight.datatree.TreeNode) ManagedObjectManager(org.glassfish.gmbal.ManagedObjectManager) ProbeClientMethodHandle(org.glassfish.flashlight.client.ProbeClientMethodHandle) PluginPoint(org.glassfish.external.probe.provider.PluginPoint)

Example 13 with TreeNode

use of org.glassfish.flashlight.datatree.TreeNode in project Payara by payara.

the class StatsProviderManagerDelegateImpl method createSubTree.

// TODO TODO TODO
// Here is where the slash meta-character is handled
private TreeNode createSubTree(TreeNode parent, String subTreePath) {
    StringTokenizer st = new StringTokenizer(subTreePath, "/");
    TreeNode parentNode = parent;
    // enable the parent if not enabled
    enableTreeNode(parentNode);
    while (st.hasMoreTokens()) {
        TreeNode subTreeNode = createSubTreeNode(parentNode, st.nextToken());
        parentNode = subTreeNode;
    }
    return parentNode;
}
Also used : TreeNode(org.glassfish.flashlight.datatree.TreeNode)

Example 14 with TreeNode

use of org.glassfish.flashlight.datatree.TreeNode in project Payara by payara.

the class StatsProviderManagerDelegateImpl method unregister.

public void unregister(Object statsProvider) {
    // Unregisters the statsProvider
    try {
        StatsProviderRegistryElement spre = statsProviderRegistry.getStatsProviderRegistryElement(statsProvider);
        if (spre == null) {
            logger.log(Level.INFO, invalidStatsProvider, new Object[] { statsProvider.getClass().getName() });
            return;
        }
        // get the Parent node and delete all children nodes (only that we know of)
        String parentNodePath = spre.getParentTreeNodePath();
        List<String> childNodeNames = spre.getChildTreeNodeNames();
        TreeNode rootNode = mrdr.get(instanceName);
        if ((rootNode != null) && (parentNodePath != null)) {
            // This has to return one node
            List<TreeNode> nodeList = rootNode.getNodes(parentNodePath, false, true);
            if (nodeList.size() > 0) {
                TreeNode parentNode = nodeList.get(0);
                // Remove each of the child nodes
                Collection<TreeNode> childNodes = parentNode.getChildNodes();
                for (TreeNode childNode : childNodes) {
                    if (childNodeNames.contains(childNode.getName())) {
                        parentNode.removeChild(childNode);
                    }
                }
                if (!parentNode.hasChildNodes())
                    removeParentNode(parentNode);
            }
        }
        // get the handles and unregister the listeners from Flashlight
        Collection<ProbeClientMethodHandle> handles = spre.getHandles();
        if (handles != null) {
            for (ProbeClientMethodHandle handle : handles) {
                // handle.remove????? Mahesh?
                // TODO IMPLEMENTATION
                // For now disable the handle => remove the client from invokerlist
                handle.disable();
            }
        }
        // unregister the statsProvider from Gmbal
        if (spre.getManagedObjectManager() != null)
            unregisterGmbal(spre);
        // Unregister from the MonitoringDataTreeRegistry and the map entries
        statsProviderRegistry.unregisterStatsProvider(statsProvider);
    } catch (Exception ex) {
        String msg = MessageFormat.format(errorUnregisteringStatsProvider, statsProvider.getClass().getName());
        logger.log(Level.SEVERE, msg, ex);
    }
}
Also used : TreeNode(org.glassfish.flashlight.datatree.TreeNode) StatsProviderRegistryElement(org.glassfish.admin.monitor.StatsProviderRegistry.StatsProviderRegistryElement) ProbeClientMethodHandle(org.glassfish.flashlight.client.ProbeClientMethodHandle) PropertyVetoException(java.beans.PropertyVetoException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 15 with TreeNode

use of org.glassfish.flashlight.datatree.TreeNode in project Payara by payara.

the class StatsProviderManagerDelegateImpl method resetChildNodeStatistics.

private void resetChildNodeStatistics(String parentNodePath, List<String> childNodeNames, String statsProviderName) {
    TreeNode rootNode = mrdr.get(instanceName);
    if (rootNode != null) {
        List<TreeNode> nodeList = rootNode.getNodes(parentNodePath, false, true);
        if (nodeList.size() > 0) {
            TreeNode parentNode = nodeList.get(0);
            Collection<TreeNode> childNodes = parentNode.getChildNodes();
            for (TreeNode childNode : childNodes) {
                if (childNodeNames.contains(childNode.getName())) {
                    invokeStatisticResetMethod(childNode.getValue());
                }
            }
        } else {
            logger.log(Level.WARNING, nodeNotFound, new Object[] { parentNodePath, statsProviderName });
        }
    }
}
Also used : TreeNode(org.glassfish.flashlight.datatree.TreeNode)

Aggregations

TreeNode (org.glassfish.flashlight.datatree.TreeNode)23 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Pattern (java.util.regex.Pattern)2 StatsProviderRegistryElement (org.glassfish.admin.monitor.StatsProviderRegistry.StatsProviderRegistryElement)2 ProbeClientMethodHandle (org.glassfish.flashlight.client.ProbeClientMethodHandle)2 Domain (com.sun.enterprise.config.serverbeans.Domain)1 Server (com.sun.enterprise.config.serverbeans.Server)1 PropertyVetoException (java.beans.PropertyVetoException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 Matcher (java.util.regex.Matcher)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 PathSegment (javax.ws.rs.core.PathSegment)1