List of usage examples for javax.management.openmbean CompositeData get
public Object get(String key);
From source file:org.eclipse.virgo.server.svt.hostedrepo.RemoteHostedRepositoryOtherThan8080Tests.java
@Test public void testScopedPlanArtifactDeployThatDependsUponArtifactsInRemoteHostedRepo() throws Exception { signature = new String[] { String.class.getName() }; params = new Object[] { new File(APP_URI_PLAN).toURI().toString() }; CompositeData compositeData = deploy(signature, params); artifactName1 = compositeData.get("symbolicName").toString(); artifactType1 = compositeData.get("type").toString(); artifactVersion1 = compositeData.get("version").toString(); waitForMBeanRegister(artifactType1, artifactName1, artifactVersion1, HALF_SECOND, TWO_MINUTES); assertArtifactExists(artifactType1, artifactName1, artifactVersion1); waitForArtifactState("plan", "scoped.plan", "1.0.0", "ACTIVE", HALF_SECOND, TWO_MINUTES); ObjectName[] objectNameList = (ObjectName[]) getMBeanServerConnection() .getAttribute(getObjectName(artifactType1, artifactName1, artifactVersion1), "Dependents"); for (ObjectName objectName : objectNameList) { assertPlanReferencedArtifacts(objectName); }/*from w w w.jav a 2 s . c o m*/ assertArtifactState(artifactType1, artifactName1, artifactVersion1, "ACTIVE"); }
From source file:org.apache.qpid.systest.management.jmx.QueueManagementTest.java
private List<Long> getAMQMessageIdsOn(ManagedQueue managedQueue, long startIndex, long endIndex) throws Exception { final SortedSet<Long> messageIds = new TreeSet<Long>(); final TabularData tab = managedQueue.viewMessages(startIndex, endIndex); final Iterator<CompositeData> rowItr = (Iterator<CompositeData>) tab.values().iterator(); while (rowItr.hasNext()) { final CompositeData row = rowItr.next(); long amqMessageId = (Long) row.get(ManagedQueue.MSG_AMQ_ID); messageIds.add(amqMessageId);/*w w w . j a va 2 s . c om*/ } return new ArrayList<Long>(messageIds); }
From source file:org.jolokia.converter.json.TabularDataExtractor.java
private Object convertToMaps(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); TabularType type = pTd.getTabularType(); List<String> indexNames = type.getIndexNames(); boolean found = false; for (CompositeData cd : (Collection<CompositeData>) pTd.values()) { Stack<String> path = (Stack<String>) pExtraArgs.clone(); try {// ww w . java2 s. c om JSONObject targetJSONObject = ret; // TODO: Check whether all keys can be represented as simple types. If not, well // we dont do any magic and return the tabular data as an array. for (int i = 0; i < indexNames.size() - 1; i++) { Object indexValue = pConverter.extractObject(cd.get(indexNames.get(i)), null, true); targetJSONObject = getNextMap(targetJSONObject, indexValue); } Object row = pConverter.extractObject(cd, path, true); String finalIndex = indexNames.get(indexNames.size() - 1); Object finalIndexValue = pConverter.extractObject(cd.get(finalIndex), null, true); targetJSONObject.put(finalIndexValue, row); found = true; } catch (ValueFaultHandler.AttributeFilteredException exp) { // Ignoring filtered attributes } } if (!pTd.isEmpty() && !found) { throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
From source file:org.wso2.carbon.analytics.common.jmx.agent.JmxAgentWebInterface.java
/** * @param mBean : The name of the MBean * @param url : The URL for the JMX server * @param userName : The User name for the JMX server * @param password : The password for the JMX server * @return : The set of attributes in a MBean * @throws MalformedObjectNameException/*w w w . j av a 2s . co m*/ * @throws IntrospectionException * @throws InstanceNotFoundException * @throws IOException * @throws ReflectionException */ public String[][] getMBeanAttributeInfo(String mBean, String url, String userName, String password) throws MalformedObjectNameException, IntrospectionException, InstanceNotFoundException, IOException, ReflectionException { JMXConnector jmxc = getJmxConnector(url, userName, password); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName mBeanName = new ObjectName(mBean); MBeanAttributeInfo[] attrs = mbsc.getMBeanInfo(mBeanName).getAttributes(); ArrayList<String[]> strAttrs = new ArrayList<String[]>(); for (MBeanAttributeInfo info : attrs) { //check the suitability of the attribute try { Object result = mbsc.getAttribute(mBeanName, info.getName()); //if this is an instance of a primary data type supported by cassandra if (result instanceof String || result instanceof Integer || result instanceof Double || result instanceof Long || result instanceof Boolean || result instanceof Float) { strAttrs.add(new String[] { info.getName() }); } //if this is a composite data type if (result instanceof CompositeData) { CompositeData cd = (CompositeData) result; ArrayList<String> keys = new ArrayList<String>(); //add the attribute name keys.add(info.getName()); for (String key : cd.getCompositeType().keySet()) { //check whether the key returns a primary data type Object attrValue = cd.get(key); if (attrValue instanceof String || attrValue instanceof Integer || attrValue instanceof Double || attrValue instanceof Long || attrValue instanceof Boolean || attrValue instanceof Float) { keys.add(key); } } //if this composite data object has keys which returns attributes with // primary data types if (keys.size() > 1) { strAttrs.add(keys.toArray(new String[keys.size()])); } } } catch (MBeanException e) { log.error("Removed the attribute " + info.getName() + " of " + mBean + " from the UI list due to: " + e.getMessage()); } catch (AttributeNotFoundException e) { log.error("Removed the attribute " + info.getName() + " of " + mBean + " from the UI list due to: " + e.getMessage()); } catch (UnmarshalException e) { log.error("Removed the attribute " + info.getName() + " of " + mBean + " from the UI list due to: " + e.getMessage()); } catch (RuntimeOperationsException e) { log.error("Removed the attribute " + info.getName() + " of " + mBean + " from the UI list due to: " + e.getMessage()); } catch (RuntimeMBeanException e) { log.error("Removed the attribute " + info.getName() + " of " + mBean + " from the UI list due to: " + e.getMessage()); } catch (ReflectionException e) { log.error("Removed the attribute " + info.getName() + " of " + mBean + " from the UI list due to: " + e.getMessage()); } catch (Exception e) { log.error("Removed the attribute " + info.getName() + " of " + mBean + " from the UI list due to: " + e.getMessage()); } } //close the connection jmxc.close(); return strAttrs.toArray(new String[strAttrs.size()][]); }
From source file:net.testdriven.psiprobe.controllers.threads.ThreadStackController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { long threadID = ServletRequestUtils.getLongParameter(request, "id", -1); String threadName = ServletRequestUtils.getStringParameter(request, "name", null); List<ThreadStackElement> stack = null; MBeanServer mBeanServer = new Registry().getMBeanServer(); ObjectName threadingOName = new ObjectName("java.lang:type=Threading"); if (threadID == -1 && threadName != null) { // find thread by name long[] allIds = (long[]) mBeanServer.getAttribute(threadingOName, "AllThreadIds"); for (long allId : allIds) { CompositeData cd = (CompositeData) mBeanServer.invoke(threadingOName, "getThreadInfo", new Object[] { allId }, new String[] { "long" }); String name = JmxTools.getStringAttr(cd, "threadName"); if (threadName.equals(name)) { threadID = allId;//from w ww .jav a 2s. co m break; } } } if (mBeanServer.queryMBeans(threadingOName, null) != null && threadID != -1) { CompositeData cd = (CompositeData) mBeanServer.invoke(threadingOName, "getThreadInfo", new Object[] { threadID, stackElementCount }, new String[] { "long", "int" }); if (cd != null) { CompositeData[] elements = (CompositeData[]) cd.get("stackTrace"); threadName = JmxTools.getStringAttr(cd, "threadName"); stack = new ArrayList<>(elements.length); for (CompositeData cd2 : elements) { 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")); stack.add(tse); } } } return new ModelAndView(getViewName(), "stack", stack).addObject("threadName", threadName); }
From source file:org.wso2.carbon.andes.core.QueueManagerServiceImpl.java
/** * {@inheritDoc}//from w w w.j a va2s.co m */ @Override public Message[] getMessageInDLCForQueue(String queueName, long nextMessageIdToRead, int maxMessageCount) throws QueueManagerException { List<Message> messageList = new ArrayList<>(); try { MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName objectName = new ObjectName( "org.wso2.andes:type=QueueManagementInformation,name=QueueManagementInformation"); String operationName = "getMessageInDLCForQueue"; Object[] parameters = new Object[] { queueName, nextMessageIdToRead, maxMessageCount }; String[] signature = new String[] { String.class.getName(), long.class.getName(), int.class.getName() }; Object result = mBeanServer.invoke(objectName, operationName, parameters, signature); if (result != null) { CompositeData[] messageDataList = (CompositeData[]) result; for (CompositeData messageData : messageDataList) { Message message = new Message(); message.setMsgProperties((String) messageData.get(QueueManagementInformation.JMS_PROPERTIES)); message.setContentType((String) messageData.get(QueueManagementInformation.CONTENT_TYPE)); message.setMessageContent((String[]) messageData.get(QueueManagementInformation.CONTENT)); message.setJMSMessageId((String) messageData.get(QueueManagementInformation.JMS_MESSAGE_ID)); message.setJMSReDelivered( (Boolean) messageData.get(QueueManagementInformation.JMS_REDELIVERED)); message.setJMSDeliveredMode( (Integer) messageData.get(QueueManagementInformation.JMS_DELIVERY_MODE)); message.setJMSTimeStamp((Long) messageData.get(QueueManagementInformation.TIME_STAMP)); message.setDlcMsgDestination( (String) messageData.get(QueueManagementInformation.MSG_DESTINATION)); message.setAndesMsgMetadataId( (Long) messageData.get(QueueManagementInformation.ANDES_MSG_METADATA_ID)); messageList.add(message); } } } catch (InstanceNotFoundException | MBeanException | ReflectionException | MalformedObjectNameException e) { throw new QueueManagerException("Cannot get message in DLC for a queue : " + queueName, e); } return messageList.toArray(new org.wso2.carbon.andes.core.types.Message[messageList.size()]); }
From source file:psiprobe.controllers.threads.ThreadStackController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { long threadId = ServletRequestUtils.getLongParameter(request, "id", -1); String threadName = ServletRequestUtils.getStringParameter(request, "name", null); List<ThreadStackElement> stack = null; MBeanServer mbeanServer = new Registry().getMBeanServer(); ObjectName threadingOName = new ObjectName("java.lang:type=Threading"); if (threadId == -1 && threadName != null) { // find thread by name for (long id : (long[]) mbeanServer.getAttribute(threadingOName, "AllThreadIds")) { CompositeData cd = (CompositeData) mbeanServer.invoke(threadingOName, "getThreadInfo", new Object[] { id }, new String[] { "long" }); String name = JmxTools.getStringAttr(cd, "threadName"); if (threadName.equals(name)) { threadId = id;//from www. j ava 2 s .c o m break; } } } if (mbeanServer.queryMBeans(threadingOName, null) != null && threadId != -1) { CompositeData cd = (CompositeData) mbeanServer.invoke(threadingOName, "getThreadInfo", new Object[] { threadId, stackElementCount }, new String[] { "long", "int" }); if (cd != null) { CompositeData[] elements = (CompositeData[]) cd.get("stackTrace"); threadName = JmxTools.getStringAttr(cd, "threadName"); stack = new ArrayList<>(elements.length); for (CompositeData cd2 : elements) { 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")); stack.add(tse); } } } return new ModelAndView(getViewName(), "stack", stack).addObject("threadName", threadName); }
From source file:org.apache.qpid.systest.management.jmx.QueueManagementTest.java
/** * Tests {@link ManagedQueue#viewMessages(long, long)} interface. *//* ww w .j av a 2s . com*/ public void testViewSingleMessage() throws Exception { final List<Message> sentMessages = sendMessage(_session, _sourceQueue, 1); syncSession(_session); final Message sentMessage = sentMessages.get(0); assertEquals("Unexpected queue depth", 1, _managedSourceQueue.getMessageCount().intValue()); // Check the contents of the message final TabularData tab = _managedSourceQueue.viewMessages(1l, 1l); assertEquals("Unexpected number of rows in table", 1, tab.size()); final Iterator<CompositeData> rowItr = (Iterator<CompositeData>) tab.values().iterator(); final CompositeData row1 = rowItr.next(); assertNotNull("Message should have AMQ message id", row1.get(ManagedQueue.MSG_AMQ_ID)); assertEquals("Unexpected queue position", 1l, row1.get(ManagedQueue.MSG_QUEUE_POS)); assertEquals("Unexpected redelivered flag", Boolean.FALSE, row1.get(ManagedQueue.MSG_REDELIVERED)); // Check the contents of header (encoded in a string array) final String[] headerArray = (String[]) row1.get(ManagedQueue.MSG_HEADER); assertNotNull("Expected message header array", headerArray); final Map<String, String> headers = headerArrayToMap(headerArray); final String expectedJMSMessageID = isBroker010() ? sentMessage.getJMSMessageID().replace("ID:", "") : sentMessage.getJMSMessageID(); final String expectedFormattedJMSTimestamp = FastDateFormat .getInstance(ManagedQueue.JMSTIMESTAMP_DATETIME_FORMAT).format(sentMessage.getJMSTimestamp()); assertEquals("Unexpected JMSMessageID within header", expectedJMSMessageID, headers.get("JMSMessageID")); assertEquals("Unexpected JMSPriority within header", String.valueOf(sentMessage.getJMSPriority()), headers.get("JMSPriority")); assertEquals("Unexpected JMSTimestamp within header", expectedFormattedJMSTimestamp, headers.get("JMSTimestamp")); }
From source file:com.googlecode.psiprobe.controllers.threads.ThreadStackController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { long threadID = ServletRequestUtils.getLongParameter(request, "id", -1); String threadName = ServletRequestUtils.getStringParameter(request, "name", null); List stack = null;// w w w . j a v a 2 s . c o m MBeanServer mBeanServer = new Registry().getMBeanServer(); ObjectName threadingOName = new ObjectName("java.lang:type=Threading"); if (threadID == -1 && threadName != null) { // find thread by name long[] allIds = (long[]) mBeanServer.getAttribute(threadingOName, "AllThreadIds"); for (int i = 0; i < allIds.length; i++) { CompositeData cd = (CompositeData) mBeanServer.invoke(threadingOName, "getThreadInfo", new Object[] { new Long(allIds[i]) }, new String[] { "long" }); String name = JmxTools.getStringAttr(cd, "threadName"); if (threadName.equals(name)) { threadID = allIds[i]; break; } } } if (mBeanServer.queryMBeans(threadingOName, null) != null && threadID != -1) { CompositeData cd = (CompositeData) mBeanServer.invoke(threadingOName, "getThreadInfo", new Object[] { new Long(threadID), new Integer(stackElementCount) }, new String[] { "long", "int" }); if (cd != null) { CompositeData[] elements = (CompositeData[]) cd.get("stackTrace"); threadName = JmxTools.getStringAttr(cd, "threadName"); stack = new ArrayList(elements.length); for (int i = 0; i < elements.length; i++) { CompositeData cd2 = elements[i]; 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")); stack.add(tse); } } } return new ModelAndView(getViewName(), "stack", stack).addObject("threadName", threadName); }
From source file:com.appleframework.jmx.core.services.MBeanServiceImpl.java
/** * Returns ObjectAttribute instance containing the value of the given * attribute. This method also handles CompositeData item with the * attribute naming convention:/* w w w .j a va 2 s . c o m*/ * <p> * Building.NumberOfFloors * <p> * where "Building" is the composite attribute name and "NumberOfFloors" * is the item name in the "Building" composite type. * * @param context * @param attribute * @return * @throws ServiceException */ public ObjectAttribute getObjectAttribute(ServiceContext context, String attribute) throws ServiceException { assert context.getObjectName() != null; assert context.getApplicationConfig() != null; canAccessThisMBean(context); // we don't support clustering here assert !context.getApplicationConfig().isCluster(); ServerConnection connection = context.getServerConnection(); List<ObjectAttribute> attrList = connection.getAttributes(context.getObjectName(), new String[] { attribute }); ObjectAttribute attrValue = (ObjectAttribute) attrList.get(0); if (attrValue.getStatus() != ObjectAttribute.STATUS_NOT_FOUND) { return attrValue; } /* see if this is a composite attribute */ String attributeName = null; String itemName = null; int index = attribute.indexOf(COMPOSITE_ATTR_SEPARATOR); if (index == -1) return attrValue; // composite data attribute itemName = attribute.substring(index + 1); attributeName = attribute.substring(0, index); attrList = connection.getAttributes(context.getObjectName(), new String[] { attributeName }); attrValue = (ObjectAttribute) attrList.get(0); if (attrValue.getStatus() == ObjectAttribute.STATUS_OK) { CompositeData compositeData = (CompositeData) attrValue.getValue(); attrValue = new ObjectAttribute(attribute, compositeData.get(itemName)); } return attrValue; }