List of usage examples for javax.management.openmbean CompositeDataSupport get
public Object get(String key)
From source file:fr.openfarm.jmx.service.JMXQuery.java
@Override public GetWildCardMultiDataResponse getWildCardJmxData(String name, String attributeName, String key) throws MalformedObjectNameException, NullPointerException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException { ObjectName objectName = new ObjectName(name); Set<ObjectName> objectNameList = connection.queryNames(objectName, null); GetWildCardMultiDataResponse response = new GetWildCardMultiDataResponse(); List<ObjectNameAndKey> objectAndkeyList = new ArrayList<ObjectNameAndKey>(); for (ObjectName iterName : objectNameList) { objectName = iterName;/*from w w w . j a v a2 s . c om*/ ObjectNameAndKey objectAndKey = new ObjectNameAndKey(); objectAndKey.setObjectName(objectName.getCanonicalName()); Object attr = connection.getAttribute(objectName, attributeName); if (attr instanceof CompositeDataSupport) { CompositeDataSupport cds = (CompositeDataSupport) attr; if (key == null) { ErrorJmx error = new ErrorJmx(); error.setMessage("Key is null for composed data " + name); response.setError(error); return response; } KeyResponse keyResponse = new KeyResponse(); keyResponse.setKey(cds.get(key).toString()); objectAndKey.setKeyResponse(keyResponse); } else { KeyResponse keyResponse = new KeyResponse(); keyResponse.setKey(attr.toString()); objectAndKey.setKeyResponse(keyResponse); } objectAndkeyList.add(objectAndKey); } response.setResponse(objectAndkeyList); return response; }
From source file:it.jnrpe.plugin.jmx.CCheckJMX.java
@Override protected Collection<Metric> gatherMetrics(ICommandLine cl) throws MetricGatheringException { Collection<Metric> metrics = new ArrayList<Metric>(super.gatherMetrics(cl)); if (this.getInfoData() == null || this.getVerbatim() >= 2) { String metricName = getCheckName(); if (this.getCheckData() instanceof Number) { metrics.add(// w ww .j ava 2 s. c o m MetricBuilder.forMetric(metricName).withMessage(metricName + " is {0}", this.getCheckData()) .withValue((Number) this.getCheckData()).build()); } else { metrics.add(MetricBuilder.forMetric(metricName) .withMessage(metricName + " is {0}", this.getCheckData()).withValue(0).build()); } LOG.debug(getContext(), "Created metric : " + metricName); } if (this.getInfoData() != null) { String metricName = getInfo_attribute(); if (this.getInfoData() instanceof CompositeDataSupport) { CompositeDataSupport data = (CompositeDataSupport) this.getInfoData(); CompositeType type = data.getCompositeType(); for (Iterator<String> it = type.keySet().iterator(); it.hasNext();) { String key = (String) it.next(); if (data.containsKey(key) && !getCheckName().equals(metricName + "." + key)) { if (data.get(key) instanceof Number) { metrics.add(MetricBuilder.forMetric(metricName + "." + key) .withMessage(metricName + "." + key + " is {0}", data.get(key)) .withValue((Number) data.get(key)).build()); } else { metrics.add(MetricBuilder.forMetric(metricName + "." + key) .withMessage(metricName + "." + key + " is {0}", data.get(key)).withValue(0) .build()); } LOG.debug(getContext(), "Created metric : " + metricName + "." + key); } } } else { if (this.getInfoData() instanceof Number) { metrics.add(MetricBuilder.forMetric(metricName) .withMessage("info is {0}", this.getCheckData().toString()) .withValue((Number) this.getInfoData()).build()); } else { metrics.add(MetricBuilder.forMetric(metricName) .withMessage("info is {0}", this.getCheckData().toString()).withValue(0).build()); } LOG.debug(getContext(), "Created metric : " + "info"); } } return metrics; }
From source file:org.apache.qpid.systest.management.jmx.ConnectionManagementTest.java
public void testTransactedSessionWithUnackMessages() throws Exception { _connection = getConnection();//from w w w .ja va 2 s . co m _connection.start(); boolean transactional = true; int numberOfMessages = 2; final Session session = _connection.createSession(transactional, Session.SESSION_TRANSACTED); final Destination destination = session.createQueue(getTestQueueName()); final MessageConsumer consumer = session.createConsumer(destination); sendMessage(session, destination, numberOfMessages); receiveMessagesWithoutCommit(consumer, numberOfMessages); final ManagedConnection mBean = getConnectionMBean(); final CompositeDataSupport row = getTheOneChannelRow(mBean); boolean flowBlocked = false; assertChannelRowData(row, numberOfMessages, transactional, flowBlocked); // check that commit advances the lastIoTime final Date initialLastIOTime = mBean.getLastIoTime(); session.commit(); assertTrue("commit should have caused last IO time to advance", mBean.getLastIoTime().after(initialLastIOTime)); // check that channels() now returns one session with no unacknowledged messages final CompositeDataSupport rowAfterCommit = getTheOneChannelRow(mBean); final Number unackCountAfterCommit = (Number) rowAfterCommit.get(ManagedConnection.UNACKED_COUNT); assertEquals("Unexpected number of unacknowledged messages", 0, unackCountAfterCommit); }
From source file:org.cloudfoundry.identity.statsd.MBeanMap.java
private Object getCompositeWrapper(Object value, boolean prettifyKeys) { if (value instanceof CompositeDataSupport) { Map<Object, Object> map = new HashMap<Object, Object>(); CompositeDataSupport composite = (CompositeDataSupport) value; for (String key : composite.getCompositeType().keySet()) { safePut(map, key, composite.get(key)); }/*from w w w . ja v a 2s.co m*/ return map; } if (value instanceof LazyCompositeData) { Map<Object, Object> map = new HashMap<Object, Object>(); LazyCompositeData composite = (LazyCompositeData) value; for (String key : composite.getCompositeType().keySet()) { safePut(map, key, composite.get(key)); } return map; } if (value instanceof TabularDataSupport) { Map<Object, Object> map = new HashMap<Object, Object>(); TabularDataSupport composite = (TabularDataSupport) value; for (Entry<Object, Object> entry : composite.entrySet()) { Object wrapper = getCompositeWrapper(entry.getValue()); if (isKeyValuePair(wrapper)) { String key = getKey(wrapper); safePut(map, key, getValue(wrapper), prettifyKeys); } else { safePut(map, getCompositeWrapper(entry.getKey()), wrapper, prettifyKeys); } } return map; } if (value instanceof Collection) { Collection<?> composite = (Collection<?>) value; List<Object> list = new ArrayList<Object>(); for (Object element : composite) { list.add(getCompositeWrapper(element)); } return list; } if (value.getClass().isArray()) { List<Object> list = new ArrayList<Object>(); for (Object element : (Object[]) value) { list.add(getCompositeWrapper(element)); } return list; } return value; }
From source file:org.jwatch.util.JMXUtil.java
/** * Return the value already cast to a type. * <p/>/*from w w w . j a v a2s. c o m*/ * - BIGDECIMAL = new SimpleType("java.math.BigDecimal"); * - BIGINTEGER = new SimpleType("java.math.BigInteger"); * - BOOLEAN = new SimpleType("java.lang.Boolean"); * - BYTE = new SimpleType("java.lang.Byte"); * - CHARACTER = new SimpleType("java.lang.Character"); * - DATE = new SimpleType("java.util.Date"); * - DOUBLE = new SimpleType("java.lang.Double"); * - FLOAT = new SimpleType("java.lang.Float"); * - INTEGER = new SimpleType("java.lang.Integer"); * - LONG = new SimpleType("java.lang.Long"); * - OBJECTNAME = new SimpleType("javax.management.ObjectName"); * - SHORT = new SimpleType("java.lang.Short"); * - STRING = new SimpleType("java.lang.String"); * - VOID = new SimpleType("java.lang.Void"); * + BIGDECIMAL = new SimpleType<BigDecimal>("java.math.BigDecimal"); * + BIGINTEGER = new SimpleType<BigInteger>("java.math.BigInteger"); * + BOOLEAN = new SimpleType<Boolean>("java.lang.Boolean"); * + BYTE = new SimpleType<Byte>("java.lang.Byte"); * + CHARACTER = new SimpleType<Character>("java.lang.Character"); * + DATE = new SimpleType<Date>("java.util.Date"); * + DOUBLE = new SimpleType<Double>("java.lang.Double"); * + FLOAT = new SimpleType<Float>("java.lang.Float"); * + INTEGER = new SimpleType<Integer>("java.lang.Integer"); * + LONG = new SimpleType<Long>("java.lang.Long"); * + OBJECTNAME = * + new SimpleType<ObjectName>("javax.management.ObjectName"); * + SHORT = new SimpleType<Short>("java.lang.Short"); * + STRING = new SimpleType<String>("java.lang.String"); * + VOID = new SimpleType<Void>("java.lang.Void"); */ public static Object convertToType(CompositeDataSupport compositeDataSupport, String key) { if (compositeDataSupport.getCompositeType().getType(key).getClassName().equals("java.lang.String")) { return StringUtils.trimToEmpty((String) compositeDataSupport.get(key)); } else if (compositeDataSupport.getCompositeType().getType(key).getClassName() .equals("java.lang.Boolean")) { return compositeDataSupport.get(key); } else if (compositeDataSupport.getCompositeType().getType(key).getClassName().equals("java.util.Date")) { return (Date) compositeDataSupport.get(key); } else if (compositeDataSupport.getCompositeType().getType(key).getClassName() .equals("java.lang.Integer")) { return (Integer) compositeDataSupport.get(key); } else if (compositeDataSupport.getCompositeType().getType(key).getClassName().equals("java.lang.Long")) { return (Long) compositeDataSupport.get(key); } return new Object(); }
From source file:org.neo4j.server.modules.WebAdminModuleTest.java
@Test public void shouldRegisterASingleUri() throws Exception { WebServer webServer = mock(WebServer.class); NeoServerWithEmbeddedWebServer neoServer = mock(NeoServerWithEmbeddedWebServer.class); when(neoServer.baseUri()).thenReturn(new URI("http://localhost:7575")); when(neoServer.getWebServer()).thenReturn(webServer); Database db = mock(Database.class); db.graph = (mock(AbstractGraphDatabase.class)); Kernel mockKernel = mock(Kernel.class); ObjectName mockObjectName = mock(ObjectName.class); when(mockKernel.getMBeanQuery()).thenReturn(mockObjectName); when(db.graph.getManagementBeans(Kernel.class)).thenReturn(Collections.singleton(mockKernel)); when(neoServer.getDatabase()).thenReturn(db); when(neoServer.getConfiguration()).thenReturn(new MapConfiguration(new HashMap<Object, Object>())); Config config = mock(Config.class); when(db.graph.getConfig()).thenReturn(config); NodeManager nodeManager = mock(NodeManager.class); GraphDbModule graphDbModule = mock(GraphDbModule.class); when(config.getGraphDbModule()).thenReturn(graphDbModule); when(graphDbModule.getNodeManager()).thenReturn(nodeManager); CompositeDataSupport result = mock(CompositeDataSupport.class); when(result.get("used")).thenReturn(50L); when(result.get("max")).thenReturn(1000L); MBeanServer mbeanServer = mock(MBeanServer.class); when(mbeanServer.getAttribute(any(ObjectName.class), eq("HeapMemoryUsage"))).thenReturn(result); // when(mbeanServer.getAttribute(any(ObjectName.class), eq("Collector"))).thenReturn( new StatisticCollector() ); setStaticFinalField(JmxUtils.class.getDeclaredField("mbeanServer"), mbeanServer); WebAdminModule module = new WebAdminModule(); module.start(neoServer, null);/* ww w . j av a 2 s . c om*/ verify(db).setRrdDb(any(RrdDb.class)); }