List of usage examples for javax.management.openmbean CompositeData get
public Object get(String key);
From source file:com.zabbix.gateway.JMXItemChecker.java
private String getPrimitiveAttributeValue(Object dataObject, String fieldNames) throws ZabbixException { logger.trace("drilling down with data object '{}' and field names '{}'", dataObject, fieldNames); if (null == dataObject) throw new ZabbixException("data object is null"); if (fieldNames.equals("")) { if (isPrimitiveAttributeType(dataObject.getClass())) { return dataObject.toString(); } else {/*from w ww . j av a2 s .c o m*/ if ("class weblogic.health.HealthState".equals(dataObject.getClass().toString())) { return dataObject.toString(); } else { throw new ZabbixException("data object type is not primitive: %s", dataObject.getClass()); } } } if (dataObject instanceof CompositeData) { logger.trace("'{}' contains composite data", dataObject); CompositeData comp = (CompositeData) dataObject; String dataObjectName; String newFieldNames = ""; int sep = HelperFunctionChest.separatorIndex(fieldNames); if (-1 != sep) { dataObjectName = fieldNames.substring(0, sep); newFieldNames = fieldNames.substring(sep + 1); } else dataObjectName = fieldNames; // unescape possible dots or backslashes that were escaped by user dataObjectName = HelperFunctionChest.unescapeUserInput(dataObjectName); return getPrimitiveAttributeValue(comp.get(dataObjectName), newFieldNames); } else throw new ZabbixException("unsupported data object type along the path: %s", dataObject.getClass()); }
From source file:org.springframework.integration.jmx.DefaultMBeanObjectConverter.java
/** * @param input//from ww w . j a va2 s .c om * @return recursively mapped object */ private Object checkAndConvert(Object input) { if (input == null) { return input; } else if (input.getClass().isArray()) { if (CompositeData.class.isAssignableFrom(input.getClass().getComponentType())) { List<Object> converted = new ArrayList<Object>(); int length = Array.getLength(input); for (int i = 0; i < length; i++) { Object value = checkAndConvert(Array.get(input, i)); converted.add(value); } return converted; } if (TabularData.class.isAssignableFrom(input.getClass().getComponentType())) { // TODO haven't hit this yet, but expect to log.warn("TabularData.isAssignableFrom(getComponentType) for " + input.toString()); } } else if (input instanceof CompositeData) { CompositeData data = (CompositeData) input; if (data.getCompositeType().isArray()) { // TODO? I haven't found an example where this gets thrown - but need to test it on Tomcat/Jetty or // something log.warn("(data.getCompositeType().isArray for " + input.toString()); } else { Map<String, Object> returnable = new HashMap<String, Object>(); Set<String> keys = data.getCompositeType().keySet(); for (String key : keys) { // we don't need to repeat name of this as an attribute if ("ObjectName".equals(key)) { continue; } Object value = checkAndConvert(data.get(key)); returnable.put(key, value); } return returnable; } } else if (input instanceof TabularData) { TabularData data = (TabularData) input; if (data.getTabularType().isArray()) { // TODO? I haven't found an example where this gets thrown, so might not be required log.warn("TabularData.isArray for " + input.toString()); } else { Map<Object, Object> returnable = new HashMap<Object, Object>(); @SuppressWarnings("unchecked") Set<List<?>> keySet = (Set<List<?>>) data.keySet(); for (List<?> keys : keySet) { CompositeData cd = data.get(keys.toArray()); Object value = checkAndConvert(cd); if (keys.size() == 1 && (value instanceof Map) && ((Map<?, ?>) value).size() == 2) { Object actualKey = keys.get(0); Map<?, ?> valueMap = (Map<?, ?>) value; if (valueMap.containsKey("key") && valueMap.containsKey("value") && actualKey.equals(valueMap.get("key"))) { returnable.put(valueMap.get("key"), valueMap.get("value")); } else { returnable.put(actualKey, value); } } else { returnable.put(keys, value); } } return returnable; } } return input; }
From source file:org.opennms.tools.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java
private CompAttrib createCompAttrib(MBeanServerConnection jmxServerConnection, ObjectInstance jmxObjectInstance, MBeanAttributeInfo jmxMBeanAttributeInfo) { Boolean contentAdded = false; CompAttrib xmlCompAttrib = xmlObjectFactory.createCompAttrib(); xmlCompAttrib.setName(jmxMBeanAttributeInfo.getName()); xmlCompAttrib.setType("Composite"); xmlCompAttrib.setAlias(jmxMBeanAttributeInfo.getName()); CompositeData compositeData; try {//from w ww . ja v a 2s .com logger.debug("Try to get composite data"); compositeData = (CompositeData) jmxServerConnection.getAttribute(jmxObjectInstance.getObjectName(), jmxMBeanAttributeInfo.getName()); if (compositeData == null) logger.warn( "compositeData is null. jmxObjectInstance.getObjectName: '{}', jmxMBeanAttributeInfo.getName: '{}'"); if (compositeData != null) { logger.debug("compositeData.getCompositeType: '{}'", compositeData.getCompositeType()); Set<String> keys = compositeData.getCompositeType().keySet(); for (String key : keys) { Object compositeEntry = compositeData.get(key); if (numbers.contains(compositeEntry.getClass().getName())) { contentAdded = true; CompMember xmlCompMember = xmlObjectFactory.createCompMember(); xmlCompMember.setName(key); logger.debug("composite member pure alias: '{}'", jmxMBeanAttributeInfo.getName() + StringUtils.capitalize(key)); String alias = NameTools .trimByDictionary(jmxMBeanAttributeInfo.getName() + StringUtils.capitalize(key)); alias = createAndRegisterUniceAlias(alias); xmlCompMember.setAlias(alias); logger.debug("composite member trimmed alias: '{}'", alias); xmlCompMember.setType("gauge"); xmlCompAttrib.getCompMember().add(xmlCompMember); } else { logger.debug("composite member key '{}' object's class '{}' was not a number.", key, compositeEntry.getClass().getName()); } } } } catch (Exception e) { logger.error("killed in action: '{}'", e.getMessage()); } if (contentAdded) { logger.debug("xmlCompAttrib returned by createCompAttrib it's '{}'", xmlCompAttrib); return xmlCompAttrib; } return null; }
From source file:dk.netarkivet.harvester.harvesting.controller.BnfHeritrixController.java
/** * Get the name of the one job we let this Heritrix run. The handling of * done jobs depends on Heritrix not being in crawl. This call may take * several seconds to finish./*from www .ja v a 2 s. c om*/ * * @return The name of the one job that Heritrix has. * @throws IOFailure * if the job created failed to initialize or didn't appear in * time. * @throws IllegalState * if more than one job in done list, or more than one pending * job */ private String getJobName() { /* * This is called just after we've told Heritrix to create a job. It may * take a while before the job is actually created, so we have to wait * around a bit. */ TabularData pendingJobs = null; TabularData doneJobs; int retries = 0; final int maxJmxRetries = JMXUtils.getMaxTries(); while (retries++ < maxJmxRetries) { // If the job turns up in Heritrix' pending jobs list, it's ready pendingJobs = (TabularData) executeMBeanOperation(CrawlServiceOperation.pendingJobs); if (pendingJobs != null && pendingJobs.size() > 0) { break; // It's ready, we can move on. } // If there's an error in the job configuration, the job will be put // in Heritrix' completed jobs list. doneJobs = (TabularData) executeMBeanOperation(CrawlServiceOperation.completedJobs); if (doneJobs != null && doneJobs.size() >= 1) { // Since we haven't allowed Heritrix to start any crawls yet, // the only way the job could have ended and then put into // the list of completed jobs is by error. if (doneJobs.size() > 1) { throw new IllegalState("More than one job in done list: " + doneJobs); } else { CompositeData job = JMXUtils.getOneCompositeData(doneJobs); throw new IOFailure( "Job " + job + " failed: " + job.get(CrawlServiceJobAttribute.Status.name())); } } if (retries < maxJmxRetries) { TimeUtils.exponentialBackoffSleep(retries); } } // If all went well, we now have exactly one job in the pending // jobs list. if (pendingJobs == null || pendingJobs.size() == 0) { throw new IOFailure("Heritrix has not created a job after " + (Math.pow(2, maxJmxRetries) / TimeUtils.SECOND_IN_MILLIS) + " seconds, giving up."); } else if (pendingJobs.size() > 1) { throw new IllegalState("More than one pending job: " + pendingJobs); } else { // Note that we may actually get through to here even if the job // is malformed. The job will then die as soon as we tell it to // start crawling. CompositeData job = JMXUtils.getOneCompositeData(pendingJobs); String name = job.get(JmxUtils.NAME) + "-" + job.get(UID_PROPERTY); log.info("Heritrix created a job with name " + name); return name; } }
From source file:org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java
private CompAttrib createCompAttrib(MBeanServerConnection jmxServerConnection, ObjectInstance jmxObjectInstance, MBeanAttributeInfo jmxMBeanAttributeInfo) { Boolean contentAdded = false; CompAttrib xmlCompAttrib = xmlObjectFactory.createCompAttrib(); xmlCompAttrib.setName(jmxMBeanAttributeInfo.getName()); xmlCompAttrib.setType("Composite"); xmlCompAttrib.setAlias(jmxMBeanAttributeInfo.getName()); CompositeData compositeData; try {/* w ww .j av a 2 s . c om*/ logger.debug("Try to get composite data"); compositeData = (CompositeData) jmxServerConnection.getAttribute(jmxObjectInstance.getObjectName(), jmxMBeanAttributeInfo.getName()); if (compositeData == null) { logger.warn( "compositeData is null. jmxObjectInstance.getObjectName: '{}', jmxMBeanAttributeInfo.getName: '{}'"); } if (compositeData != null) { logger.debug("compositeData.getCompositeType: '{}'", compositeData.getCompositeType()); Set<String> keys = compositeData.getCompositeType().keySet(); for (String key : keys) { Object compositeEntry = compositeData.get(key); if (numbers.contains(compositeEntry.getClass().getName())) { contentAdded = true; CompMember xmlCompMember = xmlObjectFactory.createCompMember(); xmlCompMember.setName(key); logger.debug("composite member pure alias: '{}'", jmxMBeanAttributeInfo.getName() + StringUtils.capitalize(key)); String alias = nameCutter .trimByDictionary(jmxMBeanAttributeInfo.getName() + StringUtils.capitalize(key)); alias = createAndRegisterUniqueAlias(alias); xmlCompMember.setAlias(alias); logger.debug("composite member trimmed alias: '{}'", alias); xmlCompMember.setType("gauge"); xmlCompAttrib.getCompMember().add(xmlCompMember); } else { logger.debug("composite member key '{}' object's class '{}' was not a number.", key, compositeEntry.getClass().getName()); } } } } catch (Exception e) { logger.error("killed in action: '{}'", e.getMessage()); } if (contentAdded) { logger.debug("xmlCompAttrib returned by createCompAttrib it's '{}'", xmlCompAttrib); return xmlCompAttrib; } return null; }
From source file:net.testdriven.psiprobe.controllers.threads.ListSunThreadsController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { List<SunThread> threads = null; int executionStackDepth = 1; MBeanServer mBeanServer = new Registry().getMBeanServer(); ObjectName threadingOName = new ObjectName("java.lang:type=Threading"); long[] deadlockedIds = (long[]) mBeanServer.invoke(threadingOName, "findMonitorDeadlockedThreads", null, null);/* w w w .jav a2 s . c o m*/ long[] allIds = (long[]) mBeanServer.getAttribute(threadingOName, "AllThreadIds"); if (allIds != null) { threads = new ArrayList<>(allIds.length); for (long allId : allIds) { CompositeData cd = (CompositeData) mBeanServer.invoke(threadingOName, "getThreadInfo", new Object[] { allId, executionStackDepth }, new String[] { "long", "int" }); if (cd != null) { SunThread st = new SunThread(); st.setId(JmxTools.getLongAttr(cd, "threadId")); st.setName(JmxTools.getStringAttr(cd, "threadName")); st.setState(JmxTools.getStringAttr(cd, "threadState")); st.setSuspended(JmxTools.getBooleanAttr(cd, "suspended")); st.setInNative(JmxTools.getBooleanAttr(cd, "inNative")); st.setLockName(JmxTools.getStringAttr(cd, "lockName")); st.setLockOwnerName(JmxTools.getStringAttr(cd, "lockOwnerName")); st.setWaitedCount(JmxTools.getLongAttr(cd, "waitedCount")); st.setBlockedCount(JmxTools.getLongAttr(cd, "blockedCount")); st.setDeadlocked(contains(deadlockedIds, st.getId())); CompositeData[] stack = (CompositeData[]) cd.get("stackTrace"); if (stack.length > 0) { CompositeData cd2 = stack[0]; ThreadStackElement tse = new ThreadStackElement(); tse.setClassName(JmxTools.getStringAttr(cd2, "className")); tse.setFileName(JmxTools.getStringAttr(cd2, "fileName")); tse.setMethodName(JmxTools.getStringAttr(cd2, "methodName")); tse.setLineNumber(JmxTools.getIntAttr(cd2, "lineNumber", -1)); tse.setNativeMethod(JmxTools.getBooleanAttr(cd2, "nativeMethod")); st.setExecutionPoint(tse); } threads.add(st); } } } return new ModelAndView(getViewName(), "threads", threads); }
From source file:psiprobe.controllers.threads.ListSunThreadsController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { List<SunThread> threads = null; int executionStackDepth = 1; MBeanServer mbeanServer = new Registry().getMBeanServer(); ObjectName threadingOName = new ObjectName("java.lang:type=Threading"); long[] deadlockedIds = (long[]) mbeanServer.invoke(threadingOName, "findMonitorDeadlockedThreads", null, null);//from www . j av a 2 s .co m long[] allIds = (long[]) mbeanServer.getAttribute(threadingOName, "AllThreadIds"); if (allIds != null) { threads = new ArrayList<>(allIds.length); for (long id : allIds) { CompositeData cd = (CompositeData) mbeanServer.invoke(threadingOName, "getThreadInfo", new Object[] { id, executionStackDepth }, new String[] { "long", "int" }); if (cd != null) { SunThread st = new SunThread(); st.setId(JmxTools.getLongAttr(cd, "threadId")); st.setName(JmxTools.getStringAttr(cd, "threadName")); st.setState(JmxTools.getStringAttr(cd, "threadState")); st.setSuspended(JmxTools.getBooleanAttr(cd, "suspended")); st.setInNative(JmxTools.getBooleanAttr(cd, "inNative")); st.setLockName(JmxTools.getStringAttr(cd, "lockName")); st.setLockOwnerName(JmxTools.getStringAttr(cd, "lockOwnerName")); st.setWaitedCount(JmxTools.getLongAttr(cd, "waitedCount")); st.setBlockedCount(JmxTools.getLongAttr(cd, "blockedCount")); st.setDeadlocked(contains(deadlockedIds, st.getId())); CompositeData[] stack = (CompositeData[]) cd.get("stackTrace"); if (stack.length > 0) { CompositeData cd2 = stack[0]; ThreadStackElement tse = new ThreadStackElement(); tse.setClassName(JmxTools.getStringAttr(cd2, "className")); tse.setFileName(JmxTools.getStringAttr(cd2, "fileName")); tse.setMethodName(JmxTools.getStringAttr(cd2, "methodName")); tse.setLineNumber(JmxTools.getIntAttr(cd2, "lineNumber", -1)); tse.setNativeMethod(JmxTools.getBooleanAttr(cd2, "nativeMethod")); st.setExecutionPoint(tse); } threads.add(st); } } } return new ModelAndView(getViewName(), "threads", threads); }
From source file:com.googlecode.psiprobe.controllers.threads.ListSunThreadsController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { List threads = null;//from w w w.j a v a 2 s . c om int executionStackDepth = 1; MBeanServer mBeanServer = new Registry().getMBeanServer(); ObjectName threadingOName = new ObjectName("java.lang:type=Threading"); long[] deadlockedIds = (long[]) mBeanServer.invoke(threadingOName, "findMonitorDeadlockedThreads", null, null); long[] allIds = (long[]) mBeanServer.getAttribute(threadingOName, "AllThreadIds"); if (allIds != null) { threads = new ArrayList(allIds.length); for (int i = 0; i < allIds.length; i++) { CompositeData cd = (CompositeData) mBeanServer.invoke(threadingOName, "getThreadInfo", new Object[] { new Long(allIds[i]), new Integer(executionStackDepth) }, new String[] { "long", "int" }); if (cd != null) { SunThread st = new SunThread(); st.setId(JmxTools.getLongAttr(cd, "threadId")); st.setName(JmxTools.getStringAttr(cd, "threadName")); st.setState(JmxTools.getStringAttr(cd, "threadState")); st.setSuspended(JmxTools.getBooleanAttr(cd, "suspended")); st.setInNative(JmxTools.getBooleanAttr(cd, "inNative")); st.setLockName(JmxTools.getStringAttr(cd, "lockName")); st.setLockOwnerName(JmxTools.getStringAttr(cd, "lockOwnerName")); st.setWaitedCount(JmxTools.getLongAttr(cd, "waitedCount")); st.setBlockedCount(JmxTools.getLongAttr(cd, "blockedCount")); st.setDeadlocked(contains(deadlockedIds, st.getId())); CompositeData[] stack = (CompositeData[]) cd.get("stackTrace"); if (stack.length > 0) { CompositeData cd2 = stack[0]; ThreadStackElement tse = new ThreadStackElement(); tse.setClassName(JmxTools.getStringAttr(cd2, "className")); tse.setFileName(JmxTools.getStringAttr(cd2, "fileName")); tse.setMethodName(JmxTools.getStringAttr(cd2, "methodName")); tse.setLineNumber(JmxTools.getIntAttr(cd2, "lineNumber", -1)); tse.setNativeMethod(JmxTools.getBooleanAttr(cd2, "nativeMethod")); st.setExecutionPoint(tse); } threads.add(st); } } } return new ModelAndView(getViewName(), "threads", threads); }
From source file:org.wso2.andes.management.ui.views.ViewUtility.java
/** * Populates the given composite with the CompositeData. Creates required widgets to hold the data types * @param toolkit/* w w w . ja v a 2s .c o m*/ * @param parent * @param data CompositeData */ @SuppressWarnings("unchecked") private static void populateCompositeWithCompositeData(FormToolkit toolkit, Composite parent, CompositeData data) { Control[] oldControls = parent.getChildren(); for (int i = 0; i < oldControls.length; i++) { oldControls[i].dispose(); } Composite compositeHolder = toolkit.createComposite(parent, SWT.NONE); GridLayout layout = new GridLayout(4, false); layout.horizontalSpacing = 10; compositeHolder.setLayout(layout); compositeHolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // ItemNames in composite data List<String> itemNames = new ArrayList<String>(data.getCompositeType().keySet()); for (String itemName : itemNames) { OpenType itemType = data.getCompositeType().getType(itemName); Label keyLabel = toolkit.createLabel(compositeHolder, itemName, SWT.TRAIL); GridData layoutData = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1); layoutData.minimumWidth = 70; keyLabel.setLayoutData(layoutData); if (itemType.isArray()) { OpenType type = ((ArrayType) itemType).getElementOpenType(); // If Byte array and mimetype is text, convert to text string if (type.getClassName().equals(Byte.class.getName())) { String mimeType = null; String encoding = null; if (data.containsKey("MimeType")) { mimeType = (String) data.get("MimeType"); } if (data.containsKey("Encoding")) { encoding = (String) data.get("Encoding"); } if (encoding == null || encoding.length() == 0) { encoding = Charset.defaultCharset().name(); } if ("text/plain".equals(mimeType)) { convertByteArray(toolkit, compositeHolder, data, itemName, encoding); } else { handleBinaryMessageContent(toolkit, compositeHolder, data, itemName, encoding); } } // If array of any other supported type, show as a list of String array else if (SUPPORTED_ARRAY_DATATYPES.contains(type.getClassName())) { convertArrayItemForDisplay(compositeHolder, data, itemName); } else { setNotSupportedDataType(toolkit, compositeHolder); } } else if (itemType instanceof TabularType) { Composite composite = toolkit.createComposite(compositeHolder, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1)); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; composite.setLayout(layout); createTabularDataHolder(toolkit, composite, (TabularDataSupport) data.get(itemName)); } else { Text valueText = toolkit.createText(compositeHolder, String.valueOf(data.get(itemName)), SWT.READ_ONLY | SWT.BORDER); valueText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1)); } } // layout the composite after creating new widgets. parent.layout(); }
From source file:com.heliosapm.opentsdb.TSDBSubmitterImpl.java
/** * Decoposes the passed composite data instance to a map of numeric values keyed by the composite type key * @param cd The composite data instance * @return a map of numeric values keyed by the composite type key *//* ww w . j a v a2s . com*/ protected Map<String, Number> fromOpenType(final CompositeData cd) { if (cd == null) return Collections.emptyMap(); final Map<String, Number> map = new LinkedHashMap<String, Number>(); final CompositeType ct = cd.getCompositeType(); for (final String key : ct.keySet()) { final Object value = cd.get(key); if (value != null && (value instanceof Number)) { map.put(key, (Number) value); } } return map; }