List of usage examples for javax.management.openmbean SimpleType STRING
SimpleType STRING
To view the source code for javax.management.openmbean SimpleType STRING.
Click Source Link
SimpleType
instance describing values whose Java class name is java.lang.String
. From source file:org.osgi.jmx.codec.OSGiAuthorization.java
private static CompositeType createAuthorizationType() { String description = "An authorization object defines which roles has a user got"; String[] itemNames = UserManagerMBean.AUTHORIZATION; String[] itemDescriptions = new String[2]; itemDescriptions[0] = "The user name for this authorization object"; itemDescriptions[1] = "The names of the roles encapsulated by this auth object"; OpenType[] itemTypes = new OpenType[2]; itemTypes[0] = SimpleType.STRING; itemTypes[1] = Util.STRING_ARRAY_TYPE; try {/*from ww w . ja va2 s . c o m*/ return new CompositeType("Authorization", description, itemNames, itemDescriptions, itemTypes); } catch (OpenDataException e) { log.error("cannot create authorization open data type", e); return null; } }
From source file:org.jolokia.converter.object.StringToOpenTypeConverterTest.java
@Test public void nullValue() throws OpenDataException { assertNull(converter.convertToObject(SimpleType.STRING, null)); }
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.alfresco.repo.security.authentication.ldap.Monitor.java
/** * test authenticate/*ww w . j ava 2 s . co m*/ * * @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;//ww w.ja v a 2 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:com.adobe.acs.commons.util.impl.AbstractGuavaCacheMBean.java
@Override @SuppressWarnings("squid:S1192") public final TabularData getCacheStats() throws OpenDataException { // Exposing all google guava stats. final CompositeType cacheEntryType = new CompositeType("Cache Stats", "Cache Stats", new String[] { "Stat", "Value" }, new String[] { "Stat", "Value" }, new OpenType[] { SimpleType.STRING, SimpleType.STRING }); final TabularDataSupport tabularData = new TabularDataSupport( new TabularType("Cache Stats", "Cache Stats", cacheEntryType, new String[] { "Stat" })); CacheStats cacheStats = getCache().stats(); final Map<String, Object> row = new HashMap<String, Object>(); row.put("Stat", "Request Count"); row.put("Value", String.valueOf(cacheStats.requestCount())); tabularData.put(new CompositeDataSupport(cacheEntryType, row)); row.put("Stat", "Hit Count"); row.put("Value", String.valueOf(cacheStats.hitCount())); tabularData.put(new CompositeDataSupport(cacheEntryType, row)); row.put("Stat", "Hit Rate"); row.put("Value", String.format("%.0f%%", cacheStats.hitRate() * 100)); tabularData.put(new CompositeDataSupport(cacheEntryType, row)); row.put("Stat", "Miss Count"); row.put("Value", String.valueOf(cacheStats.missCount())); tabularData.put(new CompositeDataSupport(cacheEntryType, row)); row.put("Stat", "Miss Rate"); row.put("Value", String.format("%.0f%%", cacheStats.missRate() * 100)); tabularData.put(new CompositeDataSupport(cacheEntryType, row)); row.put("Stat", "Eviction Count"); row.put("Value", String.valueOf(cacheStats.evictionCount())); tabularData.put(new CompositeDataSupport(cacheEntryType, row)); row.put("Stat", "Load Count"); row.put("Value", String.valueOf(cacheStats.loadCount())); tabularData.put(new CompositeDataSupport(cacheEntryType, row)); row.put("Stat", "Load Exception Count"); row.put("Value", String.valueOf(cacheStats.loadExceptionCount())); tabularData.put(new CompositeDataSupport(cacheEntryType, row)); row.put("Stat", "Load Exception Rate"); row.put("Value", String.format("%.0f%%", cacheStats.loadExceptionRate() * 100)); tabularData.put(new CompositeDataSupport(cacheEntryType, row)); row.put("Stat", "Load Success Count"); row.put("Value", String.valueOf(cacheStats.loadSuccessCount())); tabularData.put(new CompositeDataSupport(cacheEntryType, row)); row.put("Stat", "Average Load Penalty"); row.put("Value", String.valueOf(cacheStats.averageLoadPenalty())); tabularData.put(new CompositeDataSupport(cacheEntryType, row)); row.put("Stat", "Total Load Time"); row.put("Value", String.valueOf(cacheStats.totalLoadTime())); tabularData.put(new CompositeDataSupport(cacheEntryType, row)); return tabularData; }
From source file:org.xmatthew.spy2servers.jmx.AbstractComponentViewMBean.java
protected TabularData tabularDataWrapFromMessages(List<Message> messages) throws OpenDataException { if (CollectionUtils.isBlankCollection(messages)) { return null; }/*w ww . j av a 2 s . co m*/ messages = Collections.synchronizedList(messages); String[] itemNames = Message.getKeys().toArray(new String[Message.getKeys().size()]); String[] itemDescriptions = itemNames; OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING }; CompositeType compositeType = new CompositeType("MessageList", "list spyed messages", itemNames, itemDescriptions, itemTypes); TabularType tt = new TabularType("MessageList", "MessageList", compositeType, itemNames); TabularDataSupport rc = new TabularDataSupport(tt); for (Message message : messages) { try { rc.put(new CompositeDataSupport(compositeType, message.getFileds())); } catch (Exception e) { throw new OpenDataException(e.getMessage()); } } return rc; }
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; }//from w ww . j a v a2 s . co 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. jav a2s . co 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.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); }/* www . java 2 s . c om*/ } 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)); }