Example usage for javax.management AttributeNotFoundException AttributeNotFoundException

List of usage examples for javax.management AttributeNotFoundException AttributeNotFoundException

Introduction

In this page you can find the example usage for javax.management AttributeNotFoundException AttributeNotFoundException.

Prototype

public AttributeNotFoundException() 

Source Link

Document

Default constructor.

Usage

From source file:org.echocat.jemoni.jmx.support.CacheDynamicMBean.java

@SuppressWarnings("OverlyLongMethod")
@Override//ww  w.j  ava 2  s. c  om
public Object getAttribute(String attribute)
        throws AttributeNotFoundException, MBeanException, ReflectionException {
    final Object result;
    if ("type".equals(attribute)) {
        result = _cache.getClass().getName();
    } else if ("keyType".equals(attribute)) {
        result = _cache.getKeyType().getName();
    } else if ("valueType".equals(attribute)) {
        result = _cache.getValueType().getName();
    } else if ("size".equals(attribute)) {
        result = cast(StatisticsEnabledCache.class).size();
    } else if ("hitRatio".equals(attribute)) {
        final StatisticsEnabledCache<?, ?> statisticsEnabledCache = cast(StatisticsEnabledCache.class);
        final Long numberOfHits = statisticsEnabledCache.getNumberOfHits();
        final Long numberOfRequests = statisticsEnabledCache.getNumberOfRequests();
        if (numberOfHits != null && numberOfRequests != null) {
            result = numberOfRequests != 0 ? (double) numberOfHits / (double) numberOfRequests : 0;
        } else {
            result = null;
        }
    } else if ("dropRatio".equals(attribute)) {
        final StatisticsEnabledCache<?, ?> statisticsEnabledCache = cast(StatisticsEnabledCache.class);
        final Long numberOfDrops = statisticsEnabledCache.getNumberOfDrops();
        final Long numberOfRequests = statisticsEnabledCache.getNumberOfRequests();
        if (numberOfDrops != null && numberOfRequests != null) {
            result = numberOfRequests != 0 ? (double) numberOfDrops / (double) numberOfRequests : 0;
        } else {
            result = null;
        }
    } else if ("numberOfMisses".equals(attribute)) {
        final StatisticsEnabledCache<?, ?> statisticsEnabledCache = cast(StatisticsEnabledCache.class);
        final Long numberOfHits = statisticsEnabledCache.getNumberOfHits();
        final Long numberOfRequests = statisticsEnabledCache.getNumberOfRequests();
        if (numberOfHits != null && numberOfRequests != null) {
            result = numberOfRequests - numberOfHits;
        } else {
            result = null;
        }
    } else if ("numberOfRequests".equals(attribute)) {
        result = cast(StatisticsEnabledCache.class).getNumberOfRequests();
    } else if ("numberOfHits".equals(attribute)) {
        result = cast(StatisticsEnabledCache.class).getNumberOfHits();
    } else if ("numberOfDrops".equals(attribute)) {
        result = cast(StatisticsEnabledCache.class).getNumberOfDrops();
    } else if ("created".equals(attribute)) {
        result = cast(StatisticsEnabledCache.class).getCreated();
    } else if ("maximumLifetime".equals(attribute)) {
        final Duration maximumLifetime = cast(LimitedCache.class).getMaximumLifetime();
        result = maximumLifetime != null ? maximumLifetime.toString() : null;
    } else if ("capacity".equals(attribute)) {
        result = cast(LimitedCache.class).getCapacity();
    } else if ("producingType".equals(attribute)) {
        result = cast(ProducingTypeEnabledCache.class).getProducingType().name();
    } else if ("listeners".equals(attribute)) {
        // noinspection unchecked
        final Collection<CacheListener> listeners = cast(ListenerEnabledCache.class).getListeners();
        result = getListenersAsString(listeners);
    } else {
        throw new AttributeNotFoundException();
    }
    return result;
}

From source file:org.echocat.jemoni.jmx.support.CacheDynamicMBean.java

@Override
public void setAttribute(Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    final String attributeName = attribute.getName();
    final Object value = attribute.getValue();
    if ("maximumLifetime".equals(attributeName)) {
        if (value != null && !(value instanceof String)) {
            throw new InvalidAttributeValueException();
        }//w  ww .  j  av a 2  s  .c o m
        cast(LimitedCache.class).setMaximumLifetime(
                value != null && !value.toString().trim().isEmpty() ? new Duration(value.toString()) : null);
    } else if ("capacity".equals(attributeName)) {
        if (value != null && !(value instanceof Number)) {
            throw new InvalidAttributeValueException();
        }
        cast(LimitedCache.class).setCapacity(value != null ? ((Number) value).longValue() : null);
    } else if ("producingType".equals(attributeName)) {
        if (value != null && !(value instanceof String)) {
            throw new InvalidAttributeValueException();
        }
        final ProducingType producingType;
        if (value == null || value.toString().trim().isEmpty()) {
            producingType = ProducingType.DEFAULT;
        } else {
            try {
                producingType = ProducingType.valueOf(value.toString().trim());
            } catch (IllegalArgumentException ignored) {
                throw new InvalidAttributeValueException("Illegal value: " + value + ". Possible values: "
                        + StringUtils.join(ProducingType.values(), ", "));
            }
        }
        cast(ProducingTypeEnabledCache.class).setProducingType(producingType);
    } else {
        throw new AttributeNotFoundException();
    }
}

From source file:org.jolokia.http.HttpRequestHandlerTest.java

@Test
public void requestErrorHandling() throws MalformedObjectNameException, InstanceNotFoundException, IOException,
        ReflectionException, AttributeNotFoundException, MBeanException {
    Object[] exceptions = new Object[] { new ReflectionException(new NullPointerException()), 404, 500,
            new InstanceNotFoundException(), 404, 500, new MBeanException(new NullPointerException()), 500, 500,
            new AttributeNotFoundException(), 404, 500, new UnsupportedOperationException(), 500, 500,
            new IOException(), 500, 500, new IllegalArgumentException(), 400, 400, new SecurityException(), 403,
            403, new RuntimeMBeanException(new NullPointerException()), 500, 500 };

    for (int i = 0; i < exceptions.length; i += 3) {
        Exception e = (Exception) exceptions[i];
        reset(backend);/*from   w  ww .j  a va 2 s.  c  o m*/
        expect(backend.isDebug()).andReturn(true).anyTimes();
        backend.error(find("" + exceptions[i + 1]), EasyMock.<Throwable>anyObject());
        backend.error(find("" + exceptions[i + 2]), EasyMock.<Throwable>anyObject());
        expect(backend.handleRequest(EasyMock.<JmxRequest>anyObject())).andThrow(e);
        replay(backend);
        JSONObject resp = (JSONObject) handler.handleGetRequest("/jolokia",
                "/read/java.lang:type=Memory/HeapMemoryUsage", null);
        assertEquals(resp.get("status"), exceptions[i + 1]);

        resp = handler.handleThrowable(e);
        assertEquals(resp.get("status"), exceptions[i + 2], e.getClass().getName());
    }
}

From source file:org.apache.hadoop.hbase.metrics.MetricsMBeanBase.java

@Override
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {

    if (name == null) {
        throw new IllegalArgumentException("Attribute name is NULL");
    }//from  www  .ja  va2 s .  c  o  m

    /*
     * Ugly.  Since MetricsDynamicMBeanBase implementation is private,
     * we need to first check the parent class for the attribute.
     * In case that the MetricsRegistry contents have changed, this will
     * allow the parent to update it's internal structures (which we rely on
     * to update our own.
     */
    try {
        return super.getAttribute(name);
    } catch (AttributeNotFoundException ex) {

        checkAndUpdateAttributes();

        MetricsBase metric = this.extendedAttributes.get(name);
        if (metric != null) {
            if (metric instanceof MetricsRate) {
                return ((MetricsRate) metric).getPreviousIntervalValue();
            } else if (metric instanceof MetricsString) {
                return ((MetricsString) metric).getValue();
            } else if (metric instanceof MetricsHistogram) {
                MetricsHistogram hist = (MetricsHistogram) metric;
                if (name.endsWith(MetricsHistogram.NUM_OPS_METRIC_NAME)) {
                    return hist.getCount();
                } else if (name.endsWith(MetricsHistogram.MIN_METRIC_NAME)) {
                    return hist.getMin();
                } else if (name.endsWith(MetricsHistogram.MAX_METRIC_NAME)) {
                    return hist.getMax();
                } else if (name.endsWith(MetricsHistogram.MEAN_METRIC_NAME)) {
                    return (float) hist.getMean();
                } else if (name.endsWith(MetricsHistogram.STD_DEV_METRIC_NAME)) {
                    return (float) hist.getStdDev();
                } else if (name.endsWith(MetricsHistogram.MEDIAN_METRIC_NAME)) {
                    Snapshot s = hist.getSnapshot();
                    return (float) s.getMedian();
                } else if (name.endsWith(MetricsHistogram.SEVENTY_FIFTH_PERCENTILE_METRIC_NAME)) {
                    Snapshot s = hist.getSnapshot();
                    return (float) s.get75thPercentile();
                } else if (name.endsWith(MetricsHistogram.NINETY_FIFTH_PERCENTILE_METRIC_NAME)) {
                    Snapshot s = hist.getSnapshot();
                    return (float) s.get95thPercentile();
                } else if (name.endsWith(MetricsHistogram.NINETY_NINETH_PERCENTILE_METRIC_NAME)) {
                    Snapshot s = hist.getSnapshot();
                    return (float) s.get99thPercentile();
                }

            } else {
                LOG.warn(String.format("unknown metrics type %s for attribute %s", metric.getClass().getName(),
                        name));
            }
        }
    }

    throw new AttributeNotFoundException();
}

From source file:org.rifidi.edge.configuration.DefaultConfigurationImpl.java

@Override
public Object getAttribute(final String attribute)
        throws AttributeNotFoundException, MBeanException, ReflectionException {
    assert (attribute != null);
    for (Attribute attr : attributes.asList()) {
        if (attribute.equals(attr.getName())) {
            return attribute;
        }//www  . jav a 2  s  . c  o  m
    }
    throw new AttributeNotFoundException();
}

From source file:org.echocat.jemoni.jmx.support.CacheDynamicMBean.java

@Nonnull
protected <T extends Cache<?, ?>> T cast(@Nonnull Class<T> type) throws AttributeNotFoundException {
    if (type.isInstance(_cache)) {
        return type.cast(_cache);
    } else {//from w  w w .  j a  v  a 2 s .c o  m
        throw new AttributeNotFoundException();
    }
}