Example usage for javax.management.openmbean SimpleType INTEGER

List of usage examples for javax.management.openmbean SimpleType INTEGER

Introduction

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

Prototype

SimpleType INTEGER

To view the source code for javax.management.openmbean SimpleType INTEGER.

Click Source Link

Document

The SimpleType instance describing values whose Java class name is java.lang.Integer.

Usage

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

@Test
public void simpleType() {
    assertTrue(converter.canConvert(SimpleType.STRING));
    assertEquals(converter.convertToObject(SimpleType.STRING, "bla"), "bla");
    assertEquals(converter.convertToObject(SimpleType.BOOLEAN, "true"), true);
    assertEquals(converter.convertToObject(SimpleType.BOOLEAN, false), false);
    assertEquals(converter.convertToObject(SimpleType.DOUBLE, 4.52), 4.52);
    assertEquals(converter.convertToObject(SimpleType.DOUBLE, "4.52"), 4.52);
    assertEquals(converter.convertToObject(SimpleType.INTEGER, "9876"), 9876);
}

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

@Test(expectedExceptions = { NumberFormatException.class })
public void simpleTypeFailed() {
    converter.convertToObject(SimpleType.INTEGER, "4.52");
}

From source file:org.alfresco.repo.security.authentication.ldap.Monitor.java

/**
 * test authenticate/*w  ww.j ava2  s  .  c om*/
 * 
 * @param userName String
 * @param credentials String
 * @throws AuthenticationException
 */
public CompositeData testAuthenticate(String userName, String credentials) {
    String stepKeys[] = { "id", "stepMessage", "success" };
    String stepDescriptions[] = { "id", "stepMessage", "success" };
    OpenType<?> stepTypes[] = { SimpleType.INTEGER, SimpleType.STRING, SimpleType.BOOLEAN };

    try {
        String[] key = { "id" };
        CompositeType sType = new CompositeType("Authentication Step", "Step", stepKeys, stepDescriptions,
                stepTypes);
        TabularType tType = new TabularType("Diagnostic", "Authentication Steps", sType, key);
        TabularData table = new TabularDataSupport(tType);

        String attributeKeys[] = { "authenticationMessage", "success", "diagnostic" };
        String attributeDescriptions[] = { "authenticationMessage", "success", "diagnostic" };
        OpenType<?> attributeTypes[] = { SimpleType.STRING, SimpleType.BOOLEAN, tType };
        try {
            component.authenticate(userName, credentials.toCharArray());

            CompositeType cType = new CompositeType("Authentication Result", "Result Success", attributeKeys,
                    attributeDescriptions, attributeTypes);
            Map<String, Object> value = new HashMap<String, Object>();
            value.put("authenticationMessage", "Test Passed");
            value.put("success", true);
            value.put("diagnostic", table);
            CompositeDataSupport row = new CompositeDataSupport(cType, value);
            return row;
        } catch (AuthenticationException ae) {
            CompositeType cType = new CompositeType("Authentication Result", "Result Failed", attributeKeys,
                    attributeDescriptions, attributeTypes);
            Map<String, Object> value = new HashMap<String, Object>();
            value.put("authenticationMessage", ae.getMessage());
            value.put("success", false);

            if (ae.getDiagnostic() != null) {
                int i = 0;
                for (AuthenticationStep step : ae.getDiagnostic().getSteps()) {
                    Map<String, Object> x = new HashMap<String, Object>();
                    x.put("id", i++);
                    x.put("stepMessage", step.getMessage());
                    x.put("success", step.isSuccess());
                    CompositeDataSupport row = new CompositeDataSupport(sType, x);
                    table.put(row);

                }
            }

            value.put("diagnostic", table);

            CompositeDataSupport row = new CompositeDataSupport(cType, value);

            return row;
        }

    } catch (OpenDataException oe) {
        logger.error("", oe);
        return null;
    }
}

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

private static CompositeType createServiceEventType() {
    String description = "This eventType encapsulates OSGi service events";
    String[] itemNames = ServiceStateMBean.SERVICE_EVENT;
    OpenType[] itemTypes = new OpenType[5];
    String[] itemDescriptions = new String[5];
    itemTypes[0] = SimpleType.LONG;
    itemTypes[1] = SimpleType.LONG;
    itemTypes[2] = SimpleType.STRING;
    itemTypes[3] = STRING_ARRAY_TYPE;/*from  w  w  w  . ja  va2 s .  c  om*/
    itemTypes[4] = SimpleType.INTEGER;

    itemDescriptions[0] = "The id of the bundle which registered the service";
    itemDescriptions[1] = "The id of the bundle which registered the service";
    itemDescriptions[2] = "The location of the bundle that registered the service";
    itemDescriptions[3] = "An string array containing the interfaces under which the service has been registered";
    itemDescriptions[4] = "The eventType of the event: {REGISTERED=1, MODIFIED=2 UNREGISTERING=3}";
    try {
        return new CompositeType("ServiceEvent", description, itemNames, itemDescriptions, itemTypes);
    } catch (OpenDataException e) {
        log.error("Unable to create ServiceEvent OpenData eventType", e);
        return null;
    }

}

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

private OpenType detectType(final Class type) {
    if ((Long.class == type) || (Long.TYPE == type)) {
        return SimpleType.LONG;
    } else if ((Integer.class == type) || (Integer.TYPE == type)) {
        return SimpleType.INTEGER;
    } else if ((Double.class == type) || (Double.TYPE == type)) {
        return SimpleType.DOUBLE;
    } else if ((Float.class == type) || (Float.TYPE == type)) {
        return SimpleType.FLOAT;
    } else if ((Byte.class == type) || (Byte.TYPE == type)) {
        return SimpleType.BYTE;
    } else if ((Short.class == type) || (Short.TYPE == type)) {
        return SimpleType.SHORT;
    } else if ((Boolean.class == type) || (Boolean.TYPE == type)) {
        return SimpleType.BOOLEAN;
    } else if (BigDecimal.class == type) {
        return SimpleType.BIGDECIMAL;
    } else if (BigInteger.class == type) {
        return SimpleType.BIGINTEGER;
    } else if ((Character.class == type) || (Character.TYPE == type)) {
        return SimpleType.CHARACTER;
    }/* ww  w.  j  ava  2  s. c o  m*/

    // last fallback to strings
    if (isConvertibleToString(type)) {
        return SimpleType.STRING;
    }

    // give up
    return null;
}

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

/**
 * {@inheritDoc}/*from   w  ww.j ava 2 s .com*/
 */
@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:com.alibaba.dragoon.stat.SpringIbatisStatementStats.java

public static CompositeType getCompositeTypeInternal() throws OpenDataException {
    if (compositeType != null) {
        return compositeType;
    }//from   w w w  .j  a  va2 s.c  o  m

    OpenType<?>[] indexTypes = new OpenType<?>[] { SimpleType.STRING, SimpleType.STRING, SimpleType.LONG,
            SimpleType.LONG, SimpleType.LONG, SimpleType.DATE, SimpleType.LONG, SimpleType.LONG,
            SimpleType.LONG, SimpleType.INTEGER, SimpleType.INTEGER };

    String[] indexNames = { "id", "resource", "executeCount", "errorCount", "totalTime", "lastTime",
            "updateCount", "fetchObjectCount", "effectedRowCount", "concurrentMax", "runningCount" };

    String[] indexDescriptions = indexNames;

    compositeType = new CompositeType("IbatisStatementStat", "IbatisStatementStat", indexNames,
            indexDescriptions, indexTypes);

    return compositeType;
}

From source file:com.adobe.acs.commons.errorpagehandler.cache.impl.ErrorPageCacheImpl.java

@SuppressWarnings("squid:S1192")
public final TabularData getCacheEntries() throws OpenDataException {

    final CompositeType cacheEntryType = new CompositeType("cacheEntry", "Cache Entry",
            new String[] { "errorPage", "hit", "miss", "hitRate", "missRate", "sizeInKB" },
            new String[] { "Error Page", "Hit", "Miss", "Hit Rate", "Miss Rate", "Size in KB" },
            new OpenType[] { SimpleType.STRING, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.FLOAT,
                    SimpleType.FLOAT, SimpleType.INTEGER });

    final TabularDataSupport tabularData = new TabularDataSupport(
            new TabularType("cacheEntries", "Cache Entries", cacheEntryType, new String[] { "errorPage" }));

    for (final Map.Entry<String, CacheEntry> entry : this.cache.entrySet()) {
        final CacheEntry cacheEntry = entry.getValue();

        final Map<String, Object> data = new HashMap<String, Object>();
        data.put("errorPage", entry.getKey());
        data.put("hit", cacheEntry.getHits());
        data.put("miss", cacheEntry.getMisses());
        data.put("hitRate", cacheEntry.getHitRate());
        data.put("missRate", cacheEntry.getMissRate());
        data.put("sizeInKB", cacheEntry.getBytes() / KB_IN_BYTES);

        tabularData.put(new CompositeDataSupport(cacheEntryType, data));
    }//from   w  w w . ja  v a 2s  .  co  m

    return tabularData;
}

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

/**
 * {@inheritDoc}//w w  w  . ja v a 2s.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:com.adobe.acs.commons.httpcache.store.caffeine.impl.CaffeineMemHttpCacheStoreImpl.java

@Override
protected CompositeType getCacheEntryType() throws OpenDataException {
    return new CompositeType(AbstractCacheMBean.JMX_PN_CACHEENTRY, AbstractCacheMBean.JMX_PN_CACHEENTRY,
            new String[] { AbstractCacheMBean.JMX_PN_CACHEKEY, AbstractCacheMBean.JMX_PN_STATUS,
                    AbstractCacheMBean.JMX_PN_SIZE, AbstractCacheMBean.JMX_PN_CONTENTTYPE,
                    AbstractCacheMBean.JMX_PN_CHARENCODING, AbstractCacheMBean.JMX_PN_HITS,
                    AbstractCacheMBean.JMX_PN_TOTALSIZESERVED },
            new String[] { AbstractCacheMBean.JMX_PN_CACHEKEY, AbstractCacheMBean.JMX_PN_STATUS,
                    AbstractCacheMBean.JMX_PN_SIZE, AbstractCacheMBean.JMX_PN_CONTENTTYPE,
                    AbstractCacheMBean.JMX_PN_CHARENCODING, AbstractCacheMBean.JMX_PN_HITS,
                    AbstractCacheMBean.JMX_PN_TOTALSIZESERVED },
            new OpenType[] { SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING, SimpleType.STRING,
                    SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING });
}