Search in sources :

Example 26 with CompositeType

use of javax.management.openmbean.CompositeType in project geode by apache.

the class OpenTypeConverter method makeCompositeConverter.

/**
   * @return the open type converrter for a given type
   */
private static OpenTypeConverter makeCompositeConverter(Class c) throws OpenDataException {
    final List<Method> methods = Arrays.asList(c.getMethods());
    final SortedMap<String, Method> getterMap = OpenTypeUtil.newSortedMap();
    for (Method method : methods) {
        final String propertyName = propertyName(method);
        if (propertyName == null)
            continue;
        Method old = getterMap.put(OpenTypeUtil.decapitalize(propertyName), method);
        if (old != null) {
            final String msg = "Class " + c.getName() + " has method name clash: " + old.getName() + ", " + method.getName();
            throw new OpenDataException(msg);
        }
    }
    final int nitems = getterMap.size();
    if (nitems == 0) {
        throw new OpenDataException("Can't map " + c.getName() + " to an open data type");
    }
    final Method[] getters = new Method[nitems];
    final String[] itemNames = new String[nitems];
    final OpenType[] openTypes = new OpenType[nitems];
    int i = 0;
    for (Map.Entry<String, Method> entry : getterMap.entrySet()) {
        itemNames[i] = entry.getKey();
        final Method getter = entry.getValue();
        getters[i] = getter;
        final Type retType = getter.getGenericReturnType();
        openTypes[i] = toConverter(retType).getOpenType();
        i++;
    }
    CompositeType compositeType = new // field
    CompositeType(// field
    c.getName(), // field
    c.getName(), // field
    itemNames, // field descriptions
    itemNames, openTypes);
    return new CompositeConverter(c, compositeType, itemNames, getters);
}
Also used : OpenType(javax.management.openmbean.OpenType) Method(java.lang.reflect.Method) GenericArrayType(java.lang.reflect.GenericArrayType) ArrayType(javax.management.openmbean.ArrayType) CompositeType(javax.management.openmbean.CompositeType) OpenType(javax.management.openmbean.OpenType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) TabularType(javax.management.openmbean.TabularType) OpenDataException(javax.management.openmbean.OpenDataException) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) SortedMap(java.util.SortedMap) CompositeType(javax.management.openmbean.CompositeType)

Example 27 with CompositeType

use of javax.management.openmbean.CompositeType in project geode by apache.

the class TableConverter method toNonNullOpenValue.

Object toNonNullOpenValue(Object value) throws OpenDataException {
    final Map<Object, Object> valueMap = (Map<Object, Object>) value;
    if (valueMap instanceof SortedMap) {
        Comparator comparator = ((SortedMap) valueMap).comparator();
        if (comparator != null) {
            final String msg = "Cannot convert SortedMap with non-null comparator: " + comparator;
            IllegalArgumentException iae = new IllegalArgumentException(msg);
            OpenDataException ode = new OpenDataException(msg);
            ode.initCause(iae);
            throw ode;
        }
    }
    final TabularType tabularType = (TabularType) getOpenType();
    final TabularData table = new TabularDataSupport(tabularType);
    final CompositeType rowType = tabularType.getRowType();
    for (Map.Entry entry : valueMap.entrySet()) {
        final Object openKey = keyConverter.toOpenValue(entry.getKey());
        final Object openValue = valueConverter.toOpenValue(entry.getValue());
        final CompositeData row;
        row = new CompositeDataSupport(rowType, keyValueArray, new Object[] { openKey, openValue });
        table.put(row);
    }
    return table;
}
Also used : TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) Comparator(java.util.Comparator) TabularData(javax.management.openmbean.TabularData) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) SortedMap(java.util.SortedMap) Map(java.util.Map) SortedMap(java.util.SortedMap) CompositeType(javax.management.openmbean.CompositeType)

Example 28 with CompositeType

use of javax.management.openmbean.CompositeType in project geode by apache.

the class CompositeConverter method toNonNullOpenValue.

/**
   * Converts to open value
   */
Object toNonNullOpenValue(Object value) throws OpenDataException {
    CompositeType ct = (CompositeType) getOpenType();
    if (value instanceof CompositeDataView)
        return ((CompositeDataView) value).toCompositeData(ct);
    if (value == null)
        return null;
    Object[] values = new Object[getters.length];
    for (int i = 0; i < getters.length; i++) {
        try {
            Object got = getters[i].invoke(value, (Object[]) null);
            values[i] = getterConverters[i].toOpenValue(got);
        } catch (Exception e) {
            throw openDataException("Error calling getter for " + itemNames[i] + ": " + e, e);
        }
    }
    return new CompositeDataSupport(ct, itemNames, values);
}
Also used : CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeDataView(javax.management.openmbean.CompositeDataView) OpenDataException(javax.management.openmbean.OpenDataException) InvalidObjectException(java.io.InvalidObjectException) CompositeType(javax.management.openmbean.CompositeType)

Example 29 with CompositeType

use of javax.management.openmbean.CompositeType in project karaf by apache.

the class PackagesMBeanImpl method getImports.

@Override
public TabularData getImports() {
    try {
        String[] names = new String[] { "PackageName", "Filter", "Optional", "ID", "Bundle Name", "Resolvable" };
        CompositeType bundleType = new CompositeType("PackageImports", "Imported packages", names, names, new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.LONG, SimpleType.STRING, SimpleType.BOOLEAN });
        TabularType tableType = new TabularType("PackageImports", "Imported packages", bundleType, new String[] { "Filter", "ID" });
        TabularData table = new TabularDataSupport(tableType);
        List<PackageRequirement> imports = packageService.getImports();
        for (PackageRequirement req : imports) {
            Object[] data = new Object[] { req.getPackageName(), req.getFilter(), req.isOptional(), req.getBundle().getBundleId(), req.getBundle().getSymbolicName(), req.isResolveable() };
            CompositeData comp = new CompositeDataSupport(bundleType, names, data);
            try {
                table.put(comp);
            } catch (KeyAlreadyExistsException e) {
                throw new RuntimeException("Id: " + req.getBundle().getBundleId() + ", filter: " + req.getFilter(), e);
            }
        }
        return table;
    } catch (RuntimeException e) {
        // To avoid the exception gets swallowed by jmx
        LOGGER.error(e.getMessage(), e);
        throw e;
    } catch (OpenDataException e) {
        LOGGER.error(e.getMessage(), e);
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : PackageRequirement(org.apache.karaf.packages.core.PackageRequirement) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) KeyAlreadyExistsException(javax.management.openmbean.KeyAlreadyExistsException) TabularData(javax.management.openmbean.TabularData) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Example 30 with CompositeType

use of javax.management.openmbean.CompositeType in project karaf by apache.

the class HttpMBeanImpl method getServlets.

public TabularData getServlets() throws MBeanException {
    try {
        CompositeType servletType = new CompositeType("Servlet", "HTTP Servlet", new String[] { "Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL" }, new String[] { "ID of the bundle that registered the servlet", "Class name of the servlet", "Servlet Name", "Current state of the servlet", "Aliases of the servlet", "URL of the servlet" }, new OpenType[] { SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING });
        TabularType tableType = new TabularType("Servlets", "Table of all HTTP servlets", servletType, new String[] { "Bundle-ID", "Servlet Name", "State" });
        TabularData table = new TabularDataSupport(tableType);
        List<ServletInfo> servletInfos = servletService.getServlets();
        for (ServletInfo info : servletInfos) {
            CompositeData data = new CompositeDataSupport(servletType, new String[] { "Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL" }, new Object[] { info.getBundleId(), info.getClassName(), info.getName(), info.getStateString(), info.getAlias(), Arrays.toString(info.getUrls()) });
            table.put(data);
        }
        return table;
    } catch (Exception e) {
        throw new MBeanException(null, e.toString());
    }
}
Also used : ServletInfo(org.apache.karaf.http.core.ServletInfo) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Aggregations

CompositeType (javax.management.openmbean.CompositeType)82 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)55 CompositeData (javax.management.openmbean.CompositeData)50 TabularDataSupport (javax.management.openmbean.TabularDataSupport)50 TabularData (javax.management.openmbean.TabularData)47 TabularType (javax.management.openmbean.TabularType)27 OpenType (javax.management.openmbean.OpenType)23 OpenDataException (javax.management.openmbean.OpenDataException)22 Map (java.util.Map)20 ObjectName (javax.management.ObjectName)7 EndpointUtilizationStatistics (org.apache.camel.spi.EndpointUtilizationStatistics)7 MBeanServer (javax.management.MBeanServer)6 ArrayType (javax.management.openmbean.ArrayType)6 ConcurrentMap (java.util.concurrent.ConcurrentMap)5 MBeanException (javax.management.MBeanException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)3 DataSourceProxyImpl (com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3