Example usage for javax.management.openmbean TabularType TabularType

List of usage examples for javax.management.openmbean TabularType TabularType

Introduction

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

Prototype

public TabularType(String typeName, String description, CompositeType rowType, String[] indexNames)
        throws OpenDataException 

Source Link

Document

Constructs a TabularType instance, checking for the validity of the given parameters.

Usage

From source file:org.eclipse.gyrex.monitoring.internal.mbeans.MetricSetMBean.java

private void initialize() {
    final List<OpenMBeanAttributeInfoSupport> attributes = new ArrayList<OpenMBeanAttributeInfoSupport>();
    final OpenMBeanConstructorInfoSupport[] constructors = new OpenMBeanConstructorInfoSupport[0];
    final List<OpenMBeanOperationInfoSupport> operations = new ArrayList<OpenMBeanOperationInfoSupport>(1);
    final MBeanNotificationInfo[] notifications = new MBeanNotificationInfo[0];

    // common attribute
    attributes/* w w w  . j ava 2  s  . com*/
            .add(new OpenMBeanAttributeInfoSupport(ID, "MetricSet Id", SimpleType.STRING, true, false, false));
    attributes.add(new OpenMBeanAttributeInfoSupport(DESCRIPTION, "MetricSet Description", SimpleType.STRING,
            true, false, false));

    // service property attributes
    try {
        final String[] propertyTypeNames = new String[] { "key", "value" };
        propertyType = new CompositeType("property", "A property with name and value.", propertyTypeNames,
                new String[] { "Name", "Value" }, new OpenType[] { SimpleType.STRING, SimpleType.STRING });
        propertyTableType = new TabularType(PROPERTIES, "A lst of properties.", propertyType,
                new String[] { "key" });
        attributes.add(new OpenMBeanAttributeInfoSupport(PROPERTIES, "MetricSet Properties", propertyTableType,
                true, false, false));

        // pre-build service properties
        properties = new TabularDataSupport(propertyTableType);
        final String[] propertyKeys = reference.getPropertyKeys();
        for (final String serviceProperty : propertyKeys) {
            if (serviceProperty.startsWith("gyrex.") || serviceProperty.equals(Constants.SERVICE_DESCRIPTION)
                    || serviceProperty.equals(Constants.SERVICE_VENDOR)) {
                final Object value = reference.getProperty(serviceProperty);
                if (value == null) {
                    continue;
                }
                if (isConvertibleToString(value.getClass())) {
                    final Object[] values = { serviceProperty, String.valueOf(value) };
                    properties.put(new CompositeDataSupport(propertyType, propertyTypeNames, values));
                }
            }
        }
    } catch (final OpenDataException e) {
        attributes.add(new OpenMBeanAttributeInfoSupport("propertiesError",
                "Exception occured while determining properties. " + e.toString(), SimpleType.STRING, true,
                false, false));
    }

    // metrics
    final List<BaseMetric> metrics = metricSet.getMetrics();
    metricTypesByAttributeName = new HashMap<String, CompositeType>(metrics.size());
    metricByAttributeName = new HashMap<String, BaseMetric>(metrics.size());
    for (final BaseMetric metric : metrics) {
        final String attributeName = StringUtils.removeStart(metric.getId(), metricSet.getId() + ".");
        try {
            final CompositeType type = getType(metric);
            if (type != null) {
                metricTypesByAttributeName.put(attributeName, type);
                metricByAttributeName.put(attributeName, metric);
                attributes.add(new OpenMBeanAttributeInfoSupport(attributeName, metric.getId(), type, true,
                        false, false));
            }
        } catch (final OpenDataException e) {
            attributes.add(new OpenMBeanAttributeInfoSupport(attributeName + "Error",
                    "Exception occured while determining properties. " + e.toString(), SimpleType.STRING, true,
                    false, false));
        }
    }

    // reset operation for metric
    operations.add(new OpenMBeanOperationInfoSupport(RESET_STATS, "reset the metric statistics", null,
            SimpleType.VOID, MBeanOperationInfo.ACTION));

    // build the info
    beanInfo = new OpenMBeanInfoSupport(this.getClass().getName(), metricSet.getDescription(),
            attributes.toArray(new OpenMBeanAttributeInfoSupport[attributes.size()]), constructors,
            operations.toArray(new OpenMBeanOperationInfoSupport[operations.size()]), notifications);
}

From source file:org.jolokia.converter.json.TabularDataExtractorTest.java

@Test
void emptyTabularData() throws MalformedObjectNameException, OpenDataException, AttributeNotFoundException {
    CompositeType type = new CompositeType("testType", "Type for testing", new String[] { "testKey" },
            new String[] { "bla" }, new OpenType[] { STRING });
    TabularData data = new TabularDataSupport(
            new TabularType("test", "test desc", type, new String[] { "testKey" }));
    JSONObject result = (JSONObject) extract(true, data);
    assertNotNull(result);/*from www. j a  v a 2  s  .c om*/
    assertEquals(result.size(), 0);
}

From source file:org.jolokia.converter.object.StringToOpenTypeConverterTest.java

@Test
public void multipleLevleTabularData() throws OpenDataException {
    JSONObject map = new JSONObject();
    JSONObject inner = new JSONObject();
    map.put("fcn", inner);
    JSONObject innerinner = new JSONObject();
    inner.put("franconia", innerinner);
    innerinner.put("verein", "fcn");
    innerinner.put("region", "franconia");
    innerinner.put("absteiger", false);

    TabularType type = new TabularType("soccer", "soccer",
            new CompositeType("row", "row", new String[] { "verein", "region", "absteiger" },
                    new String[] { "verein", "region", "absteiger" },
                    new OpenType[] { STRING, STRING, BOOLEAN }),
            new String[] { "verein", "region" });
    TabularData data = (TabularData) converter.convertToObject(type, map);
    CompositeData row = data.get(new Object[] { "fcn", "franconia" });
    assertNotNull(row);/*from  w  w w .j  a  v  a  2s . c  om*/
    assertFalse((Boolean) row.get("absteiger"));
}

From source file:org.jolokia.converter.object.StringToOpenTypeConverterTest.java

private TabularType getSampleTabularTypeForComplexTabularData() throws OpenDataException {
    CompositeType keyType = new CompositeType("key", "key", new String[] { "name", "age" },
            new String[] { "name", "age" }, new OpenType[] { STRING, INTEGER });
    CompositeTypeAndJson ctj = new CompositeTypeAndJson(keyType, "user", null, STRING, "street", null,
            OBJECTNAME, "oname", null);
    return new TabularType("test", "test", ctj.getType(), new String[] { "user", "street" });
}

From source file:com.adobe.acs.commons.httpcache.engine.impl.HttpCacheEngineImpl.java

@Override
public TabularData getRegisteredHttpCacheRules() throws OpenDataException {
    // @formatter:off
    final CompositeType cacheEntryType = new CompositeType(JMX_HTTPCACHE_HANDLING_RULE,
            JMX_HTTPCACHE_HANDLING_RULE, new String[] { JMX_HTTPCACHE_HANDLING_RULE },
            new String[] { JMX_HTTPCACHE_HANDLING_RULE }, new OpenType[] { SimpleType.STRING });

    final TabularDataSupport tabularData = new TabularDataSupport(
            new TabularType(JMX_PN_HTTPCACHE_HANDLING_RULES, JMX_PN_HTTPCACHE_HANDLING_RULES, cacheEntryType,
                    new String[] { JMX_HTTPCACHE_HANDLING_RULE }));
    // @formatter:on

    for (final Map.Entry<String, HttpCacheHandlingRule> entry : cacheHandlingRules.entrySet()) {
        final Map<String, Object> row = new HashMap<String, Object>();

        row.put(JMX_HTTPCACHE_HANDLING_RULE, entry.getValue().getClass().getName());
        tabularData.put(new CompositeDataSupport(cacheEntryType, row));
    }//from w  ww  . j  a va 2s  .c  o m

    return tabularData;
}

From source file:com.adobe.acs.commons.httpcache.engine.impl.HttpCacheEngineImpl.java

@Override
public TabularData getRegisteredHttpCacheConfigs() throws OpenDataException {
    // @formatter:off
    // Exposing all google guava stats.
    final CompositeType cacheEntryType = new CompositeType(JMX_PN_HTTPCACHE_CONFIG, JMX_PN_HTTPCACHE_CONFIG,
            new String[] { JMX_PN_ORDER, JMX_PN_OSGICOMPONENT },
            new String[] { JMX_PN_ORDER, JMX_PN_OSGICOMPONENT },
            new OpenType[] { SimpleType.INTEGER, SimpleType.STRING });

    final TabularDataSupport tabularData = new TabularDataSupport(new TabularType(JMX_PN_HTTPCACHE_CONFIGS,
            JMX_PN_HTTPCACHE_CONFIGS, cacheEntryType, new String[] { JMX_PN_OSGICOMPONENT }));

    // @formatter:on

    for (HttpCacheConfig cacheConfig : this.cacheConfigs) {
        final Map<String, Object> row = new HashMap<String, Object>();

        Map<String, Object> osgiConfig = cacheConfigConfigs.get(cacheConfig);

        row.put(JMX_PN_ORDER, cacheConfig.getOrder());
        row.put(JMX_PN_OSGICOMPONENT, (String) osgiConfig.get(Constants.SERVICE_PID));

        tabularData.put(new CompositeDataSupport(cacheEntryType, row));
    }//from  w ww .j a  va 2  s  . co m

    return tabularData;
}

From source file:com.adobe.acs.commons.httpcache.engine.impl.HttpCacheEngineImpl.java

@Override
public TabularData getRegisteredPersistenceStores() throws OpenDataException {
    // @formatter:off
    final CompositeType cacheEntryType = new CompositeType(JMX_PN_HTTPCACHE_STORE, JMX_PN_HTTPCACHE_STORE,
            new String[] { JMX_PN_HTTPCACHE_STORE }, new String[] { JMX_PN_HTTPCACHE_STORE },
            new OpenType[] { SimpleType.STRING });

    final TabularDataSupport tabularData = new TabularDataSupport(new TabularType(JMX_PN_HTTPCACHE_STORES,
            JMX_PN_HTTPCACHE_STORES, cacheEntryType, new String[] { JMX_PN_HTTPCACHE_STORE }));
    // @formatter:on

    Enumeration<String> storeNames = cacheStoresMap.keys();
    while (storeNames.hasMoreElements()) {
        final String storeName = storeNames.nextElement();
        final Map<String, Object> row = new HashMap<String, Object>();

        row.put(JMX_PN_HTTPCACHE_STORE, storeName);
        tabularData.put(new CompositeDataSupport(cacheEntryType, row));
    }/*from  www . ja v a  2 s . c o m*/

    return tabularData;
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.IndexCopier.java

@Override
public TabularData getIndexPathMapping() {
    TabularDataSupport tds;/*  w ww.j av  a  2  s. c  o  m*/
    try {
        TabularType tt = new TabularType(IndexMappingData.class.getName(), "Lucene Index Stats",
                IndexMappingData.TYPE, new String[] { "jcrPath" });
        tds = new TabularDataSupport(tt);
        for (LocalIndexDir indexDir : indexRootDirectory.getAllLocalIndexes()) {
            String size = humanReadableByteCount(indexDir.size());
            tds.put(new CompositeDataSupport(IndexMappingData.TYPE, IndexMappingData.FIELD_NAMES,
                    new String[] { indexDir.getJcrPath(), indexDir.getFSPath(), size }));
        }
    } catch (OpenDataException e) {
        throw new IllegalStateException(e);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return tds;
}

From source file:com.cyberway.issue.crawler.Heritrix.java

/**
 * Build up the MBean info for Heritrix main.
 * @return Return created mbean info instance.
 *///from   w  w  w.  j a  v a 2  s .c  om
protected OpenMBeanInfoSupport buildMBeanInfo() {
    OpenMBeanAttributeInfoSupport[] attributes = new OpenMBeanAttributeInfoSupport[Heritrix.ATTRIBUTE_LIST
            .size()];
    OpenMBeanConstructorInfoSupport[] constructors = new OpenMBeanConstructorInfoSupport[1];
    OpenMBeanOperationInfoSupport[] operations = new OpenMBeanOperationInfoSupport[Heritrix.OPERATION_LIST
            .size()];
    MBeanNotificationInfo[] notifications = new MBeanNotificationInfo[0];

    // Attributes.
    attributes[0] = new OpenMBeanAttributeInfoSupport(Heritrix.STATUS_ATTR, "Short basic status message",
            SimpleType.STRING, true, false, false);
    // Attributes.
    attributes[1] = new OpenMBeanAttributeInfoSupport(Heritrix.VERSION_ATTR, "Heritrix version",
            SimpleType.STRING, true, false, false);
    // Attributes.
    attributes[2] = new OpenMBeanAttributeInfoSupport(Heritrix.ISRUNNING_ATTR, "Whether the crawler is running",
            SimpleType.BOOLEAN, true, false, false);
    // Attributes.
    attributes[3] = new OpenMBeanAttributeInfoSupport(Heritrix.ISCRAWLING_ATTR,
            "Whether the crawler is crawling", SimpleType.BOOLEAN, true, false, false);
    // Attributes.
    attributes[4] = new OpenMBeanAttributeInfoSupport(Heritrix.ALERTCOUNT_ATTR, "The number of alerts",
            SimpleType.INTEGER, true, false, false);
    // Attributes.
    attributes[5] = new OpenMBeanAttributeInfoSupport(Heritrix.NEWALERTCOUNT_ATTR, "The number of new alerts",
            SimpleType.INTEGER, true, false, false);
    // Attributes.
    attributes[6] = new OpenMBeanAttributeInfoSupport(Heritrix.CURRENTJOB_ATTR,
            "The name of the job currently being crawled", SimpleType.STRING, true, false, false);

    // Constructors.
    constructors[0] = new OpenMBeanConstructorInfoSupport("HeritrixOpenMBean",
            "Constructs Heritrix OpenMBean instance ", new OpenMBeanParameterInfoSupport[0]);

    // Operations.
    operations[0] = new OpenMBeanOperationInfoSupport(Heritrix.START_OPER, "Start Heritrix instance", null,
            SimpleType.VOID, MBeanOperationInfo.ACTION);

    operations[1] = new OpenMBeanOperationInfoSupport(Heritrix.STOP_OPER, "Stop Heritrix instance", null,
            SimpleType.VOID, MBeanOperationInfo.ACTION);

    OpenMBeanParameterInfo[] args = new OpenMBeanParameterInfoSupport[1];
    args[0] = new OpenMBeanParameterInfoSupport("threadName", "Name of thread to send interrupt",
            SimpleType.STRING);
    operations[2] = new OpenMBeanOperationInfoSupport(Heritrix.INTERRUPT_OPER,
            "Send thread an interrupt " + "(Used debugging)", args, SimpleType.STRING,
            MBeanOperationInfo.ACTION_INFO);

    operations[3] = new OpenMBeanOperationInfoSupport(Heritrix.START_CRAWLING_OPER,
            "Set Heritrix instance " + "into crawling mode", null, SimpleType.VOID, MBeanOperationInfo.ACTION);

    operations[4] = new OpenMBeanOperationInfoSupport(Heritrix.STOP_CRAWLING_OPER,
            "Unset Heritrix instance " + " crawling mode", null, SimpleType.VOID, MBeanOperationInfo.ACTION);

    args = new OpenMBeanParameterInfoSupport[4];
    args[0] = new OpenMBeanParameterInfoSupport("pathOrURL", "Path/URL to order or jar of order+seed",
            SimpleType.STRING);
    args[1] = new OpenMBeanParameterInfoSupport("name", "Basename for new job", SimpleType.STRING);
    args[2] = new OpenMBeanParameterInfoSupport("description", "Description to save with new job",
            SimpleType.STRING);
    args[3] = new OpenMBeanParameterInfoSupport("seeds", "Initial seed(s)", SimpleType.STRING);
    operations[5] = new OpenMBeanOperationInfoSupport(Heritrix.ADD_CRAWL_JOB_OPER, "Add new crawl job", args,
            SimpleType.STRING, MBeanOperationInfo.ACTION_INFO);

    args = new OpenMBeanParameterInfoSupport[4];
    args[0] = new OpenMBeanParameterInfoSupport("uidOrName", "Job UID or profile name", SimpleType.STRING);
    args[1] = new OpenMBeanParameterInfoSupport("name", "Basename for new job", SimpleType.STRING);
    args[2] = new OpenMBeanParameterInfoSupport("description", "Description to save with new job",
            SimpleType.STRING);
    args[3] = new OpenMBeanParameterInfoSupport("seeds", "Initial seed(s)", SimpleType.STRING);
    operations[6] = new OpenMBeanOperationInfoSupport(Heritrix.ADD_CRAWL_JOB_BASEDON_OPER,
            "Add a new crawl job based on passed Job UID or profile", args, SimpleType.STRING,
            MBeanOperationInfo.ACTION_INFO);

    args = new OpenMBeanParameterInfoSupport[1];
    args[0] = new OpenMBeanParameterInfoSupport("UID", "Job UID", SimpleType.STRING);
    operations[7] = new OpenMBeanOperationInfoSupport(DELETE_CRAWL_JOB_OPER, "Delete/stop this crawl job", args,
            SimpleType.VOID, MBeanOperationInfo.ACTION);

    args = new OpenMBeanParameterInfoSupport[1];
    args[0] = new OpenMBeanParameterInfoSupport("index", "Zero-based index into array of alerts",
            SimpleType.INTEGER);
    operations[8] = new OpenMBeanOperationInfoSupport(Heritrix.ALERT_OPER, "Return alert at passed index", args,
            SimpleType.STRING, MBeanOperationInfo.ACTION_INFO);

    try {
        this.jobCompositeType = new CompositeType("job", "Job attributes", JOB_KEYS,
                new String[] { "Job unique ID", "Job name", "Job status" },
                new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING });
        this.jobsTabularType = new TabularType("jobs", "List of jobs", this.jobCompositeType,
                new String[] { "uid" });
    } catch (OpenDataException e) {
        // This should never happen.
        throw new RuntimeException(e);
    }
    operations[9] = new OpenMBeanOperationInfoSupport(Heritrix.PENDING_JOBS_OPER,
            "List of pending jobs (or null if none)", null, this.jobsTabularType, MBeanOperationInfo.INFO);
    operations[10] = new OpenMBeanOperationInfoSupport(Heritrix.COMPLETED_JOBS_OPER,
            "List of completed jobs (or null if none)", null, this.jobsTabularType, MBeanOperationInfo.INFO);

    args = new OpenMBeanParameterInfoSupport[2];
    args[0] = new OpenMBeanParameterInfoSupport("uid", "Job unique ID", SimpleType.STRING);
    args[1] = new OpenMBeanParameterInfoSupport("name", "Report name (e.g. crawl-report, etc.)",
            SimpleType.STRING);
    operations[11] = new OpenMBeanOperationInfoSupport(Heritrix.CRAWLEND_REPORT_OPER, "Return crawl-end report",
            args, SimpleType.STRING, MBeanOperationInfo.ACTION_INFO);

    operations[12] = new OpenMBeanOperationInfoSupport(Heritrix.SHUTDOWN_OPER, "Shutdown container", null,
            SimpleType.VOID, MBeanOperationInfo.ACTION);

    args = new OpenMBeanParameterInfoSupport[2];
    args[0] = new OpenMBeanParameterInfoSupport("level", "Log level: e.g. SEVERE, WARNING, etc.",
            SimpleType.STRING);
    args[1] = new OpenMBeanParameterInfoSupport("message", "Log message", SimpleType.STRING);
    operations[13] = new OpenMBeanOperationInfoSupport(Heritrix.LOG_OPER, "Add a log message", args,
            SimpleType.VOID, MBeanOperationInfo.ACTION);

    operations[14] = new OpenMBeanOperationInfoSupport(Heritrix.DESTROY_OPER, "Destroy Heritrix instance", null,
            SimpleType.VOID, MBeanOperationInfo.ACTION);

    operations[15] = new OpenMBeanOperationInfoSupport(Heritrix.TERMINATE_CRAWL_JOB_OPER,
            "Returns false if no current job", null, SimpleType.BOOLEAN, MBeanOperationInfo.ACTION);

    operations[16] = new OpenMBeanOperationInfoSupport(Heritrix.REBIND_JNDI_OPER,
            "Rebinds this Heritrix with JNDI.", null, SimpleType.VOID, MBeanOperationInfo.ACTION);

    // Build the info object.
    return new OpenMBeanInfoSupport(this.getClass().getName(), "Heritrix Main OpenMBean", attributes,
            constructors, operations, notifications);
}