All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zeroc.IceInternal.MetricsViewI Maven / Gradle / Ivy

Go to download

Ice is a comprehensive RPC framework that helps you build distributed applications with minimal effort using familiar object-oriented idioms

There is a newer version: 3.7.10
Show newest version
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

package com.zeroc.IceInternal;

public class MetricsViewI
{
    MetricsViewI(String name)
    {
        _name = name;
    }

    public boolean
    addOrUpdateMap(com.zeroc.Ice.Properties properties, String mapName, MetricsAdminI.MetricsMapFactory factory,
                   com.zeroc.Ice.Logger logger)
    {
        //
        // Add maps to views configured with the given map.
        //
        String viewPrefix = "IceMX.Metrics." + _name + ".";
        String mapsPrefix = viewPrefix + "Map.";
        java.util.Map mapsProps = properties.getPropertiesForPrefix(mapsPrefix);

        String mapPrefix;
        java.util.Map mapProps = new java.util.HashMap<>();
        if(!mapsProps.isEmpty())
        {
            mapPrefix = mapsPrefix + mapName + ".";
            mapProps = properties.getPropertiesForPrefix(mapPrefix);
            if(mapProps.isEmpty())
            {
                // This map isn't configured for this view.
                return _maps.remove(mapName) != null;
            }
        }
        else
        {
            mapPrefix = viewPrefix;
            mapProps = properties.getPropertiesForPrefix(mapPrefix);
        }

        if(properties.getPropertyAsInt(mapPrefix + "Disabled") > 0)
        {
            // This map is disabled for this view.
            return _maps.remove(mapName) != null;
        }

        MetricsMap m = _maps.get(mapName);
        if(m != null && m.getProperties().equals(mapProps))
        {
            return false; // The map configuration didn't change, no need to re-create.
        }

        try
        {
            _maps.put(mapName, factory.create(mapPrefix, properties));
        }
        catch(Exception ex)
        {
            logger.warning("unexpected exception while creating metrics map:\n" + ex);
            _maps.remove(mapName);
        }
        return true;
    }

    public boolean
    removeMap(String mapName)
    {
        return _maps.remove(mapName) != null;
    }

    public java.util.Map
    getMetrics()
    {
        java.util.Map metrics = new java.util.HashMap<>();
        for(java.util.Map.Entry> e : _maps.entrySet())
        {
            metrics.put(e.getKey(), e.getValue().getMetrics());
        }
        return metrics;
    }

    public com.zeroc.IceMX.MetricsFailures[]
    getFailures(String mapName)
    {
        MetricsMap m = _maps.get(mapName);
        if(m != null)
        {
            return m.getFailures();
        }
        return null;
    }

    public com.zeroc.IceMX.MetricsFailures
    getFailures(String mapName, String id)
    {
        MetricsMap m = _maps.get(mapName);
        if(m != null)
        {
            return m.getFailures(id);
        }
        return null;
    }

    public java.util.Collection
    getMaps()
    {
        return _maps.keySet();
    }

    @SuppressWarnings("unchecked")
    public  MetricsMap
    getMap(String mapName, Class cl)
    {
        return (MetricsMap)_maps.get(mapName);
    }

    final private String _name;
    final private java.util.Map> _maps = new java.util.HashMap<>();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy