List of usage examples for javax.management.openmbean CompositeDataSupport CompositeDataSupport
public CompositeDataSupport(CompositeType compositeType, String[] itemNames, Object[] itemValues) throws OpenDataException
Constructs a CompositeDataSupport instance with the specified compositeType , whose item values are specified by itemValues[] , in the same order as in itemNames[] .
From source file:org.jolokia.converter.json.TabularDataExtractorTest.java
@Test public void extractWithWildCardPath() throws OpenDataException, MalformedObjectNameException, AttributeNotFoundException { TabularTypeAndJson taj = new TabularTypeAndJson(new String[] { "id" }, new CompositeTypeAndJson(LONG, "id", null, OBJECTNAME, "oName", null, BOOLEAN, "flag", null)); TabularData data = new TabularDataSupport(taj.getType()); data.put(new CompositeDataSupport(taj.getType().getRowType(), new String[] { "id", "oName", "flag" }, new Object[] { 10L, new ObjectName("test:type=bundle"), false })); data.put(new CompositeDataSupport(taj.getType().getRowType(), new String[] { "id", "oName", "flag" }, new Object[] { 20L, new ObjectName("java.lang:type=Memory"), true })); // Path: */*/domain --> 1. Level: 10, 20 -- 2. Level: CD key-value (e.g {id: 10, oName: test=type...}), -- 3. level: Objects // Here: Only ObjetNames should be picked JSONObject result = (JSONObject) extract(true, data, null, null, "domain"); assertEquals(result.size(), 2); // 10 & 20 JSONObject inner = (JSONObject) result.get(10L); assertEquals(inner.size(), 1);/* w w w . ja v a 2 s . co m*/ assertEquals(inner.get("oName"), "test"); inner = (JSONObject) result.get(20L); assertEquals(inner.size(), 1); assertEquals(inner.get("oName"), "java.lang"); // Path: */oName --> 1. Level: 10,20 -- 2. Level: { oName : { 10 vals}} result = (JSONObject) extract(true, data, null, "oName"); assertEquals(result.size(), 2); inner = (JSONObject) result.get(10L); assertEquals(inner.get("domain"), "test"); inner = (JSONObject) result.get(20L); assertEquals(inner.get("domain"), "java.lang"); }
From source file:org.trpr.platform.batch.impl.spring.jmx.JobAdministrator.java
/** * Wraps the job statistics into JMX types *///from w w w .ja v a2s. c o m private void populateJobStatistics() { // clear existing stats in the TabularDataSupport and re-populate it with current data extracted from batch framework classes batchInvocationStatistics.clear(); JobStatistics[] stats = getStats(); for (JobStatistics stat : stats) { Object[] statValues = new Object[ATTRIBUTE_NAMES.length]; statValues[0] = stat.getHostIP(); statValues[1] = stat.getHostStartTimeStamp().getTime(); statValues[2] = stat.getJobName(); statValues[3] = stat.getJobStatus(); statValues[4] = stat.getJobSteps().toArray(new String[0]); statValues[5] = stat.getJobStepInError(); statValues[6] = stat.getJobMessage(); statValues[7] = stat.getJobStartTimeStamp() == null ? null : stat.getJobStartTimeStamp().getTime(); statValues[8] = stat.getJobEndTimestamp() == null ? null : stat.getJobEndTimestamp().getTime(); CompositeData compositeData; try { compositeData = new CompositeDataSupport(compositeType, ATTRIBUTE_NAMES, statValues); batchInvocationStatistics.put(compositeData); } catch (OpenDataException e) { // ideally we should not get this exception LOGGER.error("Error constructing JMX data type from job statistics. Error is : " + e.getMessage(), e); } } }
From source file:com.seajas.search.profiler.service.management.ManagementService.java
/** * {@inheritDoc}/*from w ww . jav a 2 s . com*/ */ @Override public CompositeData getActiveArchiveConnections() throws OpenDataException { List<Archive> archives = profilerService.getEnabledArchives(); Map<Integer, Map<String, Boolean>> results = new HashMap<Integer, Map<String, Boolean>>(); for (Archive archive : archives) try { results.put(archive.getId(), testingService.testArchiveConnection(archive)); } catch (TestingException e) { logger.error( "Could not test feed with ID " + archive.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 + " archives could successfully connect" }); }
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 .ja v a 2 s. co m .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:com.seajas.search.profiler.service.management.ManagementService.java
/** * {@inheritDoc}// ww w .j a va 2 s . c o m */ @Override public CompositeData getLoggingCount() throws OpenDataException { Integer count = profilerService.getLoggingCount(); // Return the compound status as the number of messages 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[] { count, "The logging table contains " + count + " entries" }); }
From source file:org.jolokia.converter.json.TabularDataExtractorTest.java
@Test(expectedExceptions = ValueFaultHandler.AttributeFilteredException.class) public void noMatchWithWildcardPattern() throws OpenDataException, MalformedObjectNameException, AttributeNotFoundException { TabularTypeAndJson taj = new TabularTypeAndJson(new String[] { "oName" }, new CompositeTypeAndJson(OBJECTNAME, "oName", null)); TabularData data = new TabularDataSupport(taj.getType()); data.put(new CompositeDataSupport(taj.getType().getRowType(), new String[] { "oName" }, new Object[] { new ObjectName("test:type=bundle") })); extract(true, data, null, "oName2"); }
From source file:com.seajas.search.profiler.service.management.ManagementService.java
/** * {@inheritDoc}// w w w.j a v a 2s . c om */ @Override public CompositeData getElementCacheCount() throws OpenDataException { Integer count = cacheService.getCacheCounts().get("elementCache"); // Return the compound status as the number of messages 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[] { count, "The queue cache contains " + count + " entries" }); }
From source file:org.jolokia.converter.json.TabularDataExtractorTest.java
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".*Boolean.*") void extractTabularDataWithPathButWrongIndexType() throws OpenDataException, AttributeNotFoundException { TabularTypeAndJson taj = new TabularTypeAndJson(new String[] { "verein", "absteiger" }, new CompositeTypeAndJson(STRING, "verein", null, INTEGER, "platz", null, BOOLEAN, "absteiger", null));//w w w. j ava2 s. c om TabularData data = new TabularDataSupport(taj.getType()); data.put(new CompositeDataSupport(taj.getType().getRowType(), new String[] { "verein", "platz", "absteiger" }, new Object[] { "fcn", 6, false })); extract(true, data, "fcn", "true"); }
From source file:com.seajas.search.profiler.service.management.ManagementService.java
/** * {@inheritDoc}//from w w w. ja va2s .co m */ @Override public CompositeData getDeleteCacheCount() throws OpenDataException { Integer count = cacheService.getCacheCounts().get("deleteCache"); // Return the compound status as the number of messages 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[] { count, "The delete cache contains " + count + " entries" }); }
From source file:org.apache.qpid.server.jmx.mbeans.QueueMBean.java
public TabularData viewMessages(long startPosition, long endPosition) throws IOException, JMException { if ((startPosition > endPosition) || (startPosition < 1)) { throw new OperationsException("From Index = " + startPosition + ", To Index = " + endPosition + "\n\"From Index\" should be greater than 0 and less than \"To Index\""); }/*from w w w. jav a 2 s. c o m*/ if ((endPosition - startPosition) > Integer.MAX_VALUE) { throw new OperationsException( "Specified MessageID interval is too large. Intervals must be less than 2^31 in size"); } List<QueueEntry> messages = getMessages(startPosition, endPosition); TabularDataSupport messageTable = new TabularDataSupport(MSG_LIST_DATA_TYPE); // Create the tabular list of message header contents long position = startPosition; for (QueueEntry queueEntry : messages) { ServerMessage serverMsg = queueEntry.getMessage(); AMQMessageHeader header = serverMsg.getMessageHeader(); String[] headerAttributes = { "reply-to = " + header.getReplyTo(), "propertyFlags = ", "ApplicationID = " + header.getAppId(), "ClusterID = ", "UserId = " + header.getUserId(), "JMSMessageID = " + header.getMessageId(), "JMSCorrelationID = " + header.getCorrelationId(), "JMSDeliveryMode = " + (serverMsg.isPersistent() ? "Persistent" : "Non_Persistent"), "JMSPriority = " + header.getPriority(), "JMSType = " + header.getType(), "JMSExpiration = " + (header.getExpiration() == 0 ? null : FAST_DATE_FORMAT.format(header.getExpiration())), "JMSTimestamp = " + (header.getTimestamp() == 0 ? null : FAST_DATE_FORMAT.format(header.getTimestamp())) }; Object[] itemValues = new Object[] { serverMsg.getMessageNumber(), headerAttributes, serverMsg.getSize(), queueEntry.isRedelivered(), position, queueEntry.getDeliveryCount() }; position++; CompositeData messageData = new CompositeDataSupport(MSG_DATA_TYPE, VIEW_MSGS_COMPOSITE_ITEM_NAMES_DESC_ARRAY, itemValues); messageTable.put(messageData); } return messageTable; }