List of usage examples for javax.management ObjectName getKeyPropertyList
public Hashtable<String, String> getKeyPropertyList()
Returns the key properties as a Hashtable.
From source file:org.springframework.jmx.support.JmxUtils.java
/** * Append an additional key/value pair to an existing {@link ObjectName} with the key being * the static value {@code identity} and the value being the identity hash code of the * managed resource being exposed on the supplied {@link ObjectName}. This can be used to * provide a unique {@link ObjectName} for each distinct instance of a particular bean or * class. Useful when generating {@link ObjectName ObjectNames} at runtime for a set of * managed resources based on the template value supplied by a * {@link org.springframework.jmx.export.naming.ObjectNamingStrategy}. * @param objectName the original JMX ObjectName * @param managedResource the MBean instance * @return an ObjectName with the MBean identity added * @throws MalformedObjectNameException in case of an invalid object name specification * @see org.springframework.util.ObjectUtils#getIdentityHexString(Object) *///from www . ja va 2 s .c o m public static ObjectName appendIdentityToObjectName(ObjectName objectName, Object managedResource) throws MalformedObjectNameException { Hashtable<String, String> keyProperties = objectName.getKeyPropertyList(); keyProperties.put(IDENTITY_OBJECT_NAME_KEY, ObjectUtils.getIdentityHexString(managedResource)); return ObjectNameManager.getInstance(objectName.getDomain(), keyProperties); }
From source file:org.apache.hadoop.hbase.util.TestJSONMetricUtil.java
@Test public void testBuildObjectName() throws MalformedObjectNameException { String[] keys = { "type", "name" }; String[] values = { "MemoryPool", "Par Eden Space" }; Hashtable<String, String> properties = JSONMetricUtil.buldKeyValueTable(keys, values); ObjectName testObject = JSONMetricUtil.buildObjectName(JSONMetricUtil.JAVA_LANG_DOMAIN, properties); assertEquals(testObject.getDomain(), JSONMetricUtil.JAVA_LANG_DOMAIN); assertEquals(testObject.getKeyPropertyList(), properties); }
From source file:org.rhq.plugins.jbosscache.JBossCacheDiscoveryComponent.java
@Override public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<JMXComponent<?>> context) { ResourceContext parentCtx = context.getParentResourceContext(); JMXComponent<JBossASServerComponent<?>> gparentComponent = (JMXComponent<JBossASServerComponent<?>>) parentCtx .getParentResourceComponent(); Set<DiscoveredResourceDetails> discovered = super.performDiscovery(context.getDefaultPluginConfiguration(), gparentComponent, context.getResourceType(), false); Set<DiscoveredResourceDetails> results = new HashSet<DiscoveredResourceDetails>(discovered.size()); // Normalize the base object names from the key for (DiscoveredResourceDetails detail : discovered) { boolean isTreeCache = false; String key = detail.getResourceKey(); if (key.contains("treecache-interceptor=")) isTreeCache = true;// w ww . j av a 2s . co m try { ObjectName on = ObjectName.getInstance(key); key = on.getDomain(); key += ":"; Set<String> propKeys = on.getKeyPropertyList().keySet(); for (String prop : propKeys) { if (!(prop.contains("cache"))) { key += prop + "=" + on.getKeyProperty(prop); key += ","; } } if (key.endsWith(",")) key = key.substring(0, key.length() - 1); if (log.isDebugEnabled()) log.debug("Translated " + detail.getResourceKey() + " to " + key); detail.setResourceKey(key); detail.setResourceName(key); String descr = ""; if (isTreeCache) descr = "Tree"; descr += "Cache at " + key; detail.setResourceDescription(descr); Configuration pluginConfiguration = detail.getPluginConfiguration(); PropertySimple onProp = pluginConfiguration.getSimple("objectName"); onProp.setStringValue(key); PropertySimple isTC = new PropertySimple("isTreeCache", isTreeCache); pluginConfiguration.put(isTC); results.add(detail); } catch (MalformedObjectNameException e) { log.warn("Invalid obectname : " + key); } } return results; }
From source file:com.heliosapm.tsdblite.handlers.json.SplitTraceInputHandler.java
public String toHostObjectNameName(final ObjectName on) { final StringBuilder b = new StringBuilder("meta."); TreeMap<String, String> tgs = new TreeMap<String, String>(on.getKeyPropertyList()); final String metricName = on.getDomain(); String h = tgs.remove("host"); String a = tgs.remove("app"); final String host = h; //==null ? "*" : h; final String app = a == null ? "ANYAPP" : a; final int segIndex = metricName.indexOf('.'); final String seg = segIndex == -1 ? metricName : metricName.substring(0, segIndex); if (host != null) { b.append(host).append(".").append(seg).append(":"); }/*from www . j ava2 s . c o m*/ if (app != null) { tgs.put("app", app); // b.append(app).append(".").append(seg).append(":"); } // if(segIndex!=-1) { // tgs.put("app", metricName.substring(segIndex+1)); // } for (Map.Entry<String, String> entry : tgs.entrySet()) { b.append(entry.getKey()).append("=").append(entry.getValue()).append(","); } b.deleteCharAt(b.length() - 1); return b.toString(); }
From source file:com.mtgi.jmx.export.naming.AppendNamingStrategy.java
public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException { ObjectName base = delegate.getObjectName(managedBean, beanKey); @SuppressWarnings("unchecked") HashMap<String, String> properties = new HashMap<String, String>(base.getKeyPropertyList()); //change the domain if required String domain = this.domain; if (domain == null) domain = base.getDomain();//from w w w. j av a2s .c o m else { String oldDomain = base.getDomain(); if (oldDomain != null) { //append the prior domain name onto the package property. String pkg = properties.get("package"); pkg = (pkg == null) ? oldDomain : pkg + "." + oldDomain; properties.put("package", pkg); } } //append extra key if required if (key != null && value != null) { //append the extra key to the object name String oldValue = properties.remove(key); properties.put(key, value); //move the displaced prior value to a different property if (oldValue != null && renameKey != null) { String prefix = properties.remove(renameKey); if (prefix != null) oldValue = prefix + "." + oldValue; properties.put(renameKey, oldValue); } } StringBuffer buf = new StringBuffer(); buf.append(quote(domain)); char sep = ':'; //enforce a canonical order on all specified properties for (String prop : PROPERTY_ORDER) { String value = properties.remove(prop); if (value != null) { buf.append(sep).append(prop).append('=').append(quote(value)); sep = ','; } } //all remaining properties get appended in unspecified order for (Iterator<Map.Entry<String, String>> it = properties.entrySet().iterator(); it.hasNext();) { Map.Entry<String, String> prop = it.next(); it.remove(); buf.append(sep).append(prop.getKey()).append('=').append(quote(prop.getValue())); sep = ','; } return ObjectName.getInstance(buf.toString()); }
From source file:dk.netarkivet.common.management.SingleMBeanObject.java
/** * Create a single mbean object./*w w w. j a v a 2 s . c o m*/ * * This is a helper method for the constructor taking a domain, which take * the domain from a preconstructed ObjectName and replaces the * nameProperties with the properties from the given object name. Use this * if you have an object name created already, which you wish to use. * * @param name The object name to register under. * @param o The object to register. * @param asInterface The interface o should implement. * @param mBeanServer The mbean server to register o in. * * @throws ArgumentNotValid on any null parameter. */ public SingleMBeanObject(ObjectName name, I o, Class<I> asInterface, MBeanServer mBeanServer) { this(name.getDomain(), o, asInterface, mBeanServer); nameProperties.clear(); nameProperties.putAll(name.getKeyPropertyList()); }
From source file:org.apache.streams.monitoring.tasks.BroadcastMonitorThread.java
/** * Get all relevant JMX beans, convert their values to strings, and then persist them *//*from ww w .j a v a 2 s.com*/ @Override public void run() { LOGGER.info("BroadcastMonitorThread running"); while (keepRunning) { try { List<String> messages = Lists.newArrayList(); Set<ObjectName> beans = server.queryNames(null, null); for (ObjectName name : beans) { String item = objectMapper.writeValueAsString(name); Broadcast broadcast = null; if (name.getKeyPropertyList().get("type") != null) { if (name.getKeyPropertyList().get("type").equals("ThroughputQueue")) { broadcast = objectMapper.readValue(item, ThroughputQueueBroadcast.class); } else if (name.getKeyPropertyList().get("type").equals("StreamsTaskCounter")) { broadcast = objectMapper.readValue(item, StreamsTaskCounterBroadcast.class); } else if (name.getKeyPropertyList().get("type").equals("DatumStatusCounter")) { broadcast = objectMapper.readValue(item, DatumStatusCounterBroadcast.class); } else if (name.getKeyPropertyList().get("type").equals("Memory")) { broadcast = objectMapper.readValue(item, MemoryUsageBroadcast.class); } if (broadcast != null) { messages.add(objectMapper.writeValueAsString(broadcast)); } } } messagePersister.persistMessages(messages); Thread.sleep(waitTime); } catch (InterruptedException e) { LOGGER.error("Interrupted!: {}", e); Thread.currentThread().interrupt(); this.keepRunning = false; } catch (Exception e) { LOGGER.error("Exception: {}", e); this.keepRunning = false; } } }
From source file:io.fabric8.mq.controller.coordination.KubernetesControl.java
private BrokerOverview populateDestinations(J4pClient client, ObjectName root, BrokerDestinationOverviewImpl.Type type, BrokerOverview brokerOverview) { try {//from w ww . j a v a 2s . c o m Hashtable<String, String> props = root.getKeyPropertyList(); props.put("destinationType", type == BrokerDestinationOverviewImpl.Type.QUEUE ? "Queue" : "Topic"); props.put("destinationName", "*"); String objectName = root.getDomain() + ":" + Utils.getOrderedProperties(props); J4pResponse<J4pReadRequest> response = client .execute(new J4pReadRequest(objectName, "Name", "QueueSize", "ConsumerCount", "ProducerCount")); JSONObject value = response.getValue(); for (Object key : value.keySet()) { //get the destinations JSONObject jsonObject = (JSONObject) value.get(key); String name = jsonObject.get("Name").toString(); String producerCount = jsonObject.get("ProducerCount").toString().trim(); String consumerCount = jsonObject.get("ConsumerCount").toString().trim(); String queueSize = jsonObject.get("QueueSize").toString().trim(); if (!name.contains("Advisory") && !name.contains(ActiveMQDestination.TEMP_DESTINATION_NAME_PREFIX)) { ActiveMQDestination destination = type == BrokerDestinationOverviewImpl.Type.QUEUE ? new ActiveMQQueue(name) : new ActiveMQTopic(name); BrokerDestinationOverviewImpl brokerDestinationOverviewImpl = new BrokerDestinationOverviewImpl( destination); brokerDestinationOverviewImpl.setNumberOfConsumers(Integer.parseInt(consumerCount)); brokerDestinationOverviewImpl.setNumberOfProducers(Integer.parseInt(producerCount)); brokerDestinationOverviewImpl.setQueueDepth(Integer.parseInt(queueSize)); brokerOverview.addDestinationStatistics(brokerDestinationOverviewImpl); } } } catch (Exception ex) { // Destinations don't exist yet on the broker LOG.debug("populateDestinations failed", ex); } return brokerOverview; }
From source file:fr.xebia.management.ServletContextAwareMBeanServerFactory.java
public MBeanServer getObject() throws Exception { if (instance == null) { InvocationHandler invocationHandler = new InvocationHandler() { /**/*from w w w .j ava 2 s.c om*/ * <p> * Copy the given <code>objectName</code> adding the extra * attributes. * </p> */ protected ObjectName addExtraAttributesToObjectName(ObjectName objectName) throws MalformedObjectNameException { Hashtable<String, String> table = new Hashtable<String, String>( objectName.getKeyPropertyList()); table.putAll(objectNameExtraAttributes); ObjectName result = ObjectName.getInstance(objectName.getDomain(), table); logger.trace("addExtraAttributesToObjectName({}): {}", objectName, result); return result; } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object[] modifiedArgs = args.clone(); for (int i = 0; i < modifiedArgs.length; i++) { Object arg = modifiedArgs[i]; if (arg instanceof ObjectName) { ObjectName objectName = (ObjectName) arg; modifiedArgs[i] = addExtraAttributesToObjectName(objectName); } } if (logger.isDebugEnabled()) { logger.debug(method + " : " + Arrays.asList(modifiedArgs)); } try { return method.invoke(server, modifiedArgs); } catch (InvocationTargetException ite) { throw ite.getCause(); } } }; instance = (MBeanServer) Proxy.newProxyInstance(ClassUtils.getDefaultClassLoader(), new Class[] { MBeanServer.class }, invocationHandler); } return instance; }
From source file:org.hyperic.hq.product.jmx.ServiceTypeFactory.java
private String getObjectNameProperty(ObjectName objectName) { final StringBuffer objectNameProperty = new StringBuffer(objectName.getDomain()).append(':'); Hashtable keyProperties = objectName.getKeyPropertyList(); for (Iterator iterator = keyProperties.entrySet().iterator(); iterator.hasNext();) { Map.Entry keyProperty = (Map.Entry) iterator.next(); objectNameProperty.append(keyProperty.getKey()).append('='); // for now, recognize only type and subtype - replace all others // with variable placeholders if ("type".equals(keyProperty.getKey()) || "subtype".equals(keyProperty.getKey())) { objectNameProperty.append(keyProperty.getValue()); } else {//from w w w.j av a2 s . c o m objectNameProperty.append('%').append(keyProperty.getKey()).append('%'); } objectNameProperty.append(','); } objectNameProperty.deleteCharAt(objectNameProperty.length() - 1); return objectNameProperty.toString(); }