Example usage for javax.management.openmbean CompositeDataSupport CompositeDataSupport

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

Introduction

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

Prototype

public CompositeDataSupport(CompositeType compositeType, String[] itemNames, Object[] itemValues)
        throws OpenDataException 

Source Link

Document

Constructs a CompositeDataSupport instance with the specified compositeType , whose item values are specified by itemValues[] , in the same order as in itemNames[] .

Usage

From source file:org.osgi.jmx.codec.OSGiAuthorization.java

public CompositeData asCompositeData() throws OpenDataException {
    Object[] itemValues = new Object[2];
    String[] itemNames = UserManagerMBean.AUTHORIZATION;
    itemValues[0] = name;// w  w w.j  av a  2s  . co m
    itemValues[1] = roles;
    return new CompositeDataSupport(AUTHORIZATION, itemNames, itemValues);
}

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

private TabularData prepareMxMBeanMapData(String... keyAndValues)
        throws OpenDataException, MalformedObjectNameException {
    CompositeTypeAndJson ctj = new CompositeTypeAndJson(STRING, "key", null, OBJECTNAME, "value", null);

    TabularTypeAndJson taj = new TabularTypeAndJson(new String[] { "key" }, ctj);
    TabularData data = new TabularDataSupport(taj.getType());

    for (int i = 0; i < keyAndValues.length; i += 2) {
        CompositeData cd = new CompositeDataSupport(ctj.getType(), new String[] { "key", "value" },
                new Object[] { keyAndValues[i], new ObjectName(keyAndValues[i + 1]) });
        data.put(cd);//  w ww .  j a v a 2 s .c om
    }
    return data;
}

From source file:com.seajas.search.profiler.service.management.ManagementService.java

/**
 * {@inheritDoc}/*from w  w  w .  j  a  va  2 s.  c o  m*/
 */
@Override
public CompositeData getActiveFeedModifiers() throws OpenDataException {
    List<Modifier> modifiers = profilerService.getFeedModifiers();

    Map<Integer, Map<String, Boolean>> results = new HashMap<Integer, Map<String, Boolean>>();

    for (Modifier modifier : modifiers)
        if (modifier.getIsEnabled() && modifier.getTestFeed() != null
                && modifier.getTestFeed().getIsEnabled()) {
            TestElement testFeed = testingService.getTestFeedByModifierId(modifier.getId());

            if (testFeed != null)
                try {
                    results.put(modifier.getId(), testingService.testFeedModifier(testFeed));
                } catch (TestingException e) {
                    Map<String, Boolean> exceptionResult = new HashMap<String, Boolean>();

                    exceptionResult.put("exception", false);
                    results.put(modifier.getId(), exceptionResult);

                    logger.error("Testing exception occurred", e);
                }
        }

    Integer successful = 0, total = 0;

    for (Entry<Integer, Map<String, Boolean>> modifierResult : results.entrySet())
        for (Entry<String, Boolean> result : modifierResult.getValue().entrySet()) {
            total++;

            if (result.getValue())
                successful++;
        }

    // Return the compound status as the absolute difference - where 0 means success

    CompositeType compositeType = new CompositeType("managementResult", "Management result",
            new String[] { "compound", "status" }, new String[] { "Compound value", "Textual representation" },
            new OpenType[] { SimpleType.INTEGER, SimpleType.STRING });

    return new CompositeDataSupport(compositeType, new String[] { "compound", "status" }, new Object[] {
            Math.abs(successful - total), successful + "/" + total + " results were successful" });
}

From source file:org.osgi.jmx.codec.OSGiServiceEvent.java

/**
 * Answer the receiver encoded as CompositeData
 * /*from   ww w .ja  v a 2 s .com*/
 * @return the CompositeData encoding of the receiver.
 */
public CompositeData asCompositeData() {
    String[] itemNames = ServiceStateMBean.SERVICE_EVENT;
    Object[] itemValues = new Object[5];
    itemValues[0] = serviceId;
    itemValues[1] = bundleId;
    itemValues[2] = location;
    itemValues[3] = interfaces;
    itemValues[4] = eventType;

    try {
        return new CompositeDataSupport(SERVICE_EVENT, itemNames, itemValues);
    } catch (OpenDataException e) {
        throw new IllegalStateException("Cannot form service event open data", e);
    }
}

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

@Override
public Object getAttribute(final String attributeName)
        throws AttributeNotFoundException, MBeanException, ReflectionException {
    if (ID.equals(attributeName)) {
        return metricSet.getId();
    } else if (DESCRIPTION.equals(attributeName)) {
        return metricSet.getDescription();
    } else if (PROPERTIES.equals(attributeName)) {
        return properties;
    } else if (metricTypesByAttributeName.containsKey(attributeName)) {
        final CompositeType type = metricTypesByAttributeName.get(attributeName);
        final BaseMetric metric = metricByAttributeName.get(attributeName);
        if ((type != null) && (metric != null)) {
            final Map<String, ?> rawValues = metric.getAttributeValues();
            final String[] metricAttributeNames = type.keySet().toArray(new String[0]);
            final Object[] metricValues = new Object[metricAttributeNames.length];
            for (int i = 0; i < metricValues.length; i++) {
                Object rawValue = rawValues.get(metricAttributeNames[i]);
                // convert if necessary
                if (null != rawValue) {
                    final OpenType detectedTyp = detectType(rawValue.getClass());
                    if ((SimpleType.STRING == detectedTyp) && !(rawValue instanceof String)) {
                        rawValue = String.valueOf(rawValue);
                    }/*from   www . j av a 2s  . c  o  m*/
                }
                metricValues[i] = rawValue;
            }
            try {
                return new CompositeDataSupport(type, metricAttributeNames, metricValues);
            } catch (final OpenDataException e) {
                throw new MBeanException(e);
            }
        }
    }

    throw new AttributeNotFoundException(String.format("attribute %s not found", attributeName));
}

From source file:com.seajas.search.profiler.service.management.ManagementService.java

/**
 * {@inheritDoc}//w w w .  j a  v  a  2  s . c om
 */
@Override
public CompositeData getActiveResultModifiers() throws OpenDataException {
    List<Modifier> modifiers = profilerService.getResultModifiers();

    Map<Integer, Map<String, Boolean>> results = new HashMap<Integer, Map<String, Boolean>>();

    for (Modifier modifier : modifiers)
        if (modifier.getIsEnabled() && modifier.getTestFeed() != null
                && modifier.getTestFeed().getIsEnabled()) {
            TestElement testFeed = testingService.getTestFeedByModifierId(modifier.getId());

            if (testFeed != null)
                try {
                    results.put(modifier.getId(), testingService.testResultModifier(testFeed));
                } catch (TestingException e) {
                    Map<String, Boolean> exceptionResult = new HashMap<String, Boolean>();

                    exceptionResult.put("exception", false);
                    results.put(modifier.getId(), exceptionResult);

                    logger.error("Testing exception occurred", e);
                }
        }

    Integer successful = 0, total = 0;

    for (Entry<Integer, Map<String, Boolean>> modifierResult : results.entrySet())
        for (Entry<String, Boolean> result : modifierResult.getValue().entrySet()) {
            total++;

            if (result.getValue())
                successful++;
        }

    // Return the compound status as the absolute difference - where 0 means success

    CompositeType compositeType = new CompositeType("managementResult", "Management result",
            new String[] { "compound", "status" }, new String[] { "Compound value", "Textual representation" },
            new OpenType[] { SimpleType.INTEGER, SimpleType.STRING });

    return new CompositeDataSupport(compositeType, new String[] { "compound", "status" }, new Object[] {
            Math.abs(successful - total), successful + "/" + total + " results were successful" });
}

From source file:org.archive.crawler.frontier.BdbMultipleWorkQueues.java

/**
 * @param m marker or null to start with first entry
 * @param maxMatches//  ww w.  jav  a 2s.c  o  m
 * @return list of matches starting from marker position
 * @throws DatabaseException
 */
public CompositeData getFrom(String m, int maxMatches, Pattern pattern, boolean verbose)
        throws DatabaseException {
    int matches = 0;
    ArrayList<String> results = new ArrayList<String>(maxMatches);

    DatabaseEntry key;
    if (m == null) {
        key = getFirstKey();
    } else {
        byte[] marker = m.getBytes(); // = FrontierJMXTypes.fromString(m);
        key = new DatabaseEntry(marker);
    }

    DatabaseEntry value = new DatabaseEntry();

    Cursor cursor = null;
    OperationStatus result = null;
    try {
        cursor = pendingUrisDB.openCursor(null, null);
        result = cursor.getSearchKey(key, value, null);

        while (matches < maxMatches && result == OperationStatus.SUCCESS) {
            if (value.getData().length > 0) {
                CrawlURI curi = (CrawlURI) crawlUriBinding.entryToObject(value);
                if (pattern.matcher(curi.toString()).matches()) {
                    if (verbose) {
                        results.add("[" + curi.getClassKey() + "] " + curi.shortReportLine());
                    } else {
                        results.add(curi.toString());
                    }
                    matches++;
                }
            }
            result = cursor.getNext(key, value, null);
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    if (result != OperationStatus.SUCCESS) {
        // end of scan
        m = null;
    } else {
        m = new String(key.getData()); // = FrontierJMXTypes.toString(key.getData());
    }

    String[] arr = results.toArray(new String[results.size()]);
    CompositeData cd;
    try {
        cd = new CompositeDataSupport(/*FrontierJMXTypes.URI_LIST_DATA*/ null,
                new String[] { "list", "marker" }, new Object[] { arr, m });
    } catch (OpenDataException e) {
        throw new IllegalStateException(e);
    }
    return cd;
}

From source file:org.trpr.platform.servicefw.impl.ServiceStatisticsGatherer.java

/**
 * Wraps the service statistics into JMX types
 *///from   www. j av a 2s  . c  o m
private void populateServiceStatistics(boolean clearCollectedStats) {
    // clear existing stats in the TabularDataSupport and re-populate it with current data extracted from service framework classes
    serviceInvocationStatistics.clear();
    ServiceStatistics[] stats = getStats(clearCollectedStats);
    for (ServiceStatistics stat : stats) {
        Object[] statValues = new Object[attributeNames.length];
        statValues[0] = stat.getServiceName();
        statValues[1] = stat.getServiceVersion();
        statValues[2] = stat.getStartupTimeStamp().getTime();
        statValues[3] = stat.getLastCalledTimestamp() == null ? null : stat.getLastCalledTimestamp().getTime();
        statValues[4] = stat.getActiveRequestsCount();
        statValues[5] = stat.getTotalRequestsCount();
        statValues[6] = stat.getAverageResponseTime();
        statValues[7] = stat.getMinimumResponseTime();
        statValues[8] = stat.getMaximumResponseTime();
        statValues[9] = stat.getLastServiceRequestResponseTime();
        statValues[10] = stat.getErrorRequestsCount();
        statValues[11] = stat.getSuccessRequestsCount();
        CompositeData compositeData;
        try {
            compositeData = new CompositeDataSupport(compositeType, attributeNames, statValues);
            serviceInvocationStatistics.put(compositeData);
        } catch (OpenDataException e) {
            // ideally we should not get this exception
            LOGGER.error(
                    "Error constructing JMX data type from service statistics. Error is : " + e.getMessage(),
                    e);
        }
    }
}

From source file:com.seajas.search.profiler.service.management.ManagementService.java

/**
 * {@inheritDoc}/*from  ww  w.j av  a  2s.c o  m*/
 */
@Override
public CompositeData getActiveFeedConnections() throws OpenDataException {
    List<Feed> feeds = profilerService.getEnabledFeeds();

    Map<Integer, Map<String, Boolean>> results = new HashMap<Integer, Map<String, Boolean>>();

    for (Feed feed : feeds)
        try {
            results.put(feed.getId(), testingService.testFeedConnection(feed));
        } catch (TestingException e) {
            logger.error("Could not test feed with ID " + feed.getId() + " as no testing response was received",
                    e);
        }

    Integer successful = 0, total = 0;

    for (Entry<Integer, Map<String, Boolean>> modifierResult : results.entrySet())
        for (Entry<String, Boolean> result : modifierResult.getValue().entrySet()) {
            total++;

            if (result.getValue())
                successful++;
        }

    // Return the compound status as the absolute difference - where 0 means success

    CompositeType compositeType = new CompositeType("managementResult", "Management result",
            new String[] { "compound", "status" }, new String[] { "Compound value", "Textual representation" },
            new OpenType[] { SimpleType.INTEGER, SimpleType.STRING });

    return new CompositeDataSupport(compositeType, new String[] { "compound", "status" },
            new Object[] { Math.abs(successful - total),
                    successful + "/" + total + " feeds could be successfully retrieved" });
}

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

@Test
void extractGenericTabularDataWithIntegerAndObjectNamePath()
        throws OpenDataException, AttributeNotFoundException, MalformedObjectNameException {
    TabularTypeAndJson taj = new TabularTypeAndJson(new String[] { "bundleId", "oName" },
            new CompositeTypeAndJson(LONG, "bundleId", null, OBJECTNAME, "oName", null, BOOLEAN, "active",
                    null));/*from  ww  w . j  av a 2  s  .com*/
    TabularData data = new TabularDataSupport(taj.getType());
    data.put(
            new CompositeDataSupport(taj.getType().getRowType(), new String[] { "bundleId", "oName", "active" },
                    new Object[] { 10L, new ObjectName("test:type=bundle"), false }));
    JSONObject result = (JSONObject) extract(true, data, "10", "test:type=bundle");
    assertEquals(result.size(), 3);
    assertEquals(result.get("bundleId"), 10L);
    assertEquals(result.get("active"), false);
}