List of usage examples for javax.management ObjectName isPattern
public boolean isPattern()
From source file:org.hyperic.hq.plugin.websphere.WebsphereUtil.java
public static ObjectName resolve(AdminClient mServer, ObjectName name) throws PluginException { if (!name.isPattern()) { return name; }//from ww w . ja va 2s . co m log.debug("[resolve] name: " + name); Set beansSet; try { beansSet = mServer.queryNames(name, null); } catch (ConnectorException e) { String msg = "[resolve] name:" + name + " error: " + e.getMessage(); throw new PluginException(msg, e); } for (Object object : beansSet) { log.debug("[resolve] object found: " + object); } if (beansSet.size() != 1) { String msg = name + " query returned " + beansSet.size() + " results"; throw new PluginException(msg); } ObjectName fullName = (ObjectName) beansSet.iterator().next(); if (log.isDebugEnabled()) { log.debug(name + " resolved to: " + fullName); } return fullName; }
From source file:org.hyperic.hq.plugin.websphere.WebsphereUtil.java
public static Object invoke(AdminClient mServer, String objectName, String method, Object[] args, String[] sig) throws PluginException { ObjectName obj; try {/*from w ww .j av a2 s. c o m*/ obj = new ObjectName(objectName); } catch (MalformedObjectNameException e) { throw new PluginException(e); } try { if (obj.isPattern()) { obj = resolve(mServer, obj); } return mServer.invoke(obj, method, args, sig); } catch (InstanceNotFoundException e) { throw new PluginException(e.getMessage(), e); } catch (MBeanException e) { throw new PluginException(e.getMessage(), e); } catch (ReflectionException e) { throw new PluginException(e.getMessage(), e); } catch (ConnectorException e) { throw new PluginException(e.getMessage(), e); } catch (IllegalArgumentException e) { throw new PluginException(e.getMessage(), e); } }
From source file:org.jolokia.request.JmxObjectNameRequest.java
/** * Name prepared according to requested formatting note. The key ordering can be influenced by the * processing parameter {@link ConfigKey#CANONICAL_NAMING}. If not given or set to "true", * then the canonical order is used, if set to "initial" the name is given to construction time * is used./* w w w .jav a 2s.c o m*/ * * @param pName name to format * @return formatted string */ public String getOrderedObjectName(ObjectName pName) { // For patterns we always return the canonical name if (pName.isPattern()) { return pName.getCanonicalName(); } if (getParameterAsBool(ConfigKey.CANONICAL_NAMING)) { return pName.getCanonicalName(); } else { return pName.getDomain() + ":" + pName.getKeyPropertyListString(); } }
From source file:org.jolokia.client.request.J4pReadResponse.java
/** * Get all MBean names for which the request fetched values. If the request * contained an MBean pattern then all MBean names matching this pattern and which contained * attributes of the given name are returned. If the MBean wasnt a pattern a single * value collection with the single MBean name of the request is returned. * * @return list of MBean names//from ww w . j a v a 2s.c om * @throws MalformedObjectNameException if the returned MBean names could not be converted to * {@link ObjectName}s. Shouldnt occur, though. */ public Collection<ObjectName> getObjectNames() throws MalformedObjectNameException { ObjectName mBean = getRequest().getObjectName(); if (mBean.isPattern()) { // The result value contains the list of fetched object names JSONObject values = getValue(); Set<ObjectName> ret = new HashSet<ObjectName>(); for (Object name : values.keySet()) { ret.add(new ObjectName((String) name)); } return ret; } else { return Arrays.asList(mBean); } }
From source file:org.jolokia.client.request.J4pReadResponse.java
/** * Get all attributes obtained. This method can be only used, if the requested MBean * was not a pattern (i.e. the request was for a single MBean). * * @return a list of attributes for this request. If the request was performed for * only a single attribute, the attribute name of the request is returend as * a single valued list. For more than one attribute, the attribute names * a returned from the returned list. *//*from w w w .j av a2s. c o m*/ public Collection<String> getAttributes() { J4pReadRequest request = getRequest(); ObjectName requestBean = request.getObjectName(); if (requestBean.isPattern()) { throw new IllegalArgumentException("Attributes can be fetched only for non-pattern request (current: " + requestBean.getCanonicalName() + ")"); } // The attribute names are the same as from the request if (request.hasSingleAttribute()) { // Contains only a single attribute: return request.getAttributes(); } else { JSONObject attributes = getValue(); return attributes.keySet(); } }
From source file:org.jolokia.client.request.J4pReadResponse.java
/** * Get the value for a certain MBean and a given attribute. This method is especially * useful if the request leading to this response was done for multiple MBeans (i.e. * a read for an MBean pattern) and multiple attributes. However, this method can be * used for a request for single MBeans and single attributes as well, but then the given * parameters must match the parameters given in the request. * * @param pObjectName name of the Mbean or <code>null</code> if the request was only for a single * Mbeans in which case this single MBean is taken from the request * @param pAttribute the attribute or <code>null</code> if the request was for a single * attribute in which case the attribute name is taken from the request * @param <V> the object type of the return value ({@link String},{@link Map} or {@link List}) * @return the value/* ww w. j a v a 2 s . c o m*/ * @throws IllegalArgumentException if there was no value for the given parameters or if <code>null</code> * was given for given for one or both arguments and the request was for multiple MBeans * or attributes. */ public <V> V getValue(ObjectName pObjectName, String pAttribute) { ObjectName requestMBean = getRequest().getObjectName(); if (requestMBean.isPattern()) { JSONObject mAttributes = getAttributesForObjectNameWithPatternRequest(pObjectName); if (!mAttributes.containsKey(pAttribute)) { throw new IllegalArgumentException("No attribute " + pAttribute + " for ObjectName " + pObjectName + " returned for" + " the given request"); } return (V) mAttributes.get(pAttribute); } else { return (V) getValue(pAttribute); } }
From source file:org.jolokia.client.request.J4pReadResponse.java
/** * Get the name of all attributes fetched for a certain MBean name. If the request was * performed for a single MBean, then the given name must match that of the MBean name * provided in the request. If <code>null</code> is given as argument, then this method * will return all attributes for the single MBean given in the request * * @param pObjectName MBean for which to get the attribute names, * @return a collection of attribute names */// w w w . jav a 2 s . c o m public Collection<String> getAttributes(ObjectName pObjectName) { ObjectName requestMBean = getRequest().getObjectName(); if (requestMBean.isPattern()) { // We need to got down one level in the returned values JSONObject attributes = getAttributesForObjectNameWithPatternRequest(pObjectName); return attributes.keySet(); } else { if (pObjectName != null && !pObjectName.equals(requestMBean)) { throw new IllegalArgumentException("Given ObjectName " + pObjectName + " doesn't match with" + " the single ObjectName " + requestMBean + " given in the request"); } return getAttributes(); } }
From source file:org.jolokia.client.request.J4pReadResponse.java
/** * Get the value for a single attribute. This method is appropriate if the request was done for a single * MBean (no pattern), but multiple attributes. If it is called for a request with non-pattern MBean * and a single attribute, the given attribute must match the attribute of the request. If this method is * called with a <code>null</code> argument, then it will return the value if the request was for * a single attribute, otherwise it will raise an {@link IllegalArgumentException} * * @param pAttribute attribute for which to get the value * @param <V> value type/* ww w . j a v a2 s. c o m*/ * @return value * @throws IllegalArgumentException if the attribute could not be found in the return value or if this method * is called with a <code>null</code> argument, but the request leads to multiple attribute return values. */ public <V> V getValue(String pAttribute) { J4pReadRequest request = getRequest(); ObjectName requestBean = request.getObjectName(); if (requestBean.isPattern()) { throw new IllegalArgumentException( "Attributes without ObjectName can be fetched only for non-pattern request (current: " + requestBean.getCanonicalName() + ")"); } // The attribute names are the same as from the request if (request.hasSingleAttribute()) { // Contains only a single attribute: if (pAttribute != null && !pAttribute.equals(request.getAttribute())) { throw new IllegalArgumentException( "Given attribute " + pAttribute + " doesnt match single attribute " + "given " + request.getAttribute() + " in the request"); } return (V) getValue(); } else { JSONObject attributes = getValue(); if (pAttribute == null) { throw new IllegalArgumentException( "Cannot use null-attribute name to fetch a value from a multi-attribute request"); } if (!attributes.containsKey(pAttribute)) { throw new IllegalArgumentException( "No such key " + pAttribute + " in the set of returned attribute values"); } return (V) attributes.get(pAttribute); } }
From source file:com.betfair.cougar.core.impl.jmx.HtmlAdaptorParser.java
private void query(StringBuilder buf, String son, String attrName, String separator) { try {//from w w w. j av a 2 s .c om ObjectName on = new ObjectName(son); if (on.isPattern()) { Set<ObjectInstance> res = mbs.queryMBeans(on, null); if (res != null && res.size() > 0) { Iterator<ObjectInstance> j = res.iterator(); while (j.hasNext()) { on = j.next().getObjectName(); appendMBean(mbs, on, attrName, separator, buf); if (j.hasNext()) { buf.append("|"); } } } } else { appendMBean(mbs, on, attrName, separator, buf); } } catch (Exception e) { LOGGER.debug("Unable to retrieve Bean information for bean " + son, e); } }
From source file:org.jolokia.history.HistoryStore.java
private void updateReadHistory(JmxReadRequest pJmxReq, JSONObject pJson, long pTimestamp) { ObjectName name = pJmxReq.getObjectName(); if (name.isPattern()) { // We have a pattern and hence a value structure // of bean -> attribute_key -> attribute_value Map<String, Object> values = (Map<String, Object>) pJson.get(KEY_VALUE); // Can be null if used with path and no single match occurred if (values != null) { JSONObject history = updateHistoryForPatternRead(pJmxReq, pTimestamp, values); if (history.size() > 0) { pJson.put(KEY_HISTORY, history); }//from w w w .jav a 2 s . c o m } } else if (pJmxReq.isMultiAttributeMode() || !pJmxReq.hasAttribute()) { // Multiple attributes, but a single bean. // Value has the following structure: // attribute_key -> attribute_value JSONObject history = addMultipleAttributeValues(pJmxReq, ((Map<String, Object>) pJson.get(KEY_VALUE)), pJmxReq.getObjectNameAsString(), pTimestamp); if (history.size() > 0) { pJson.put(KEY_HISTORY, history); } } else { // Single attribute, single bean. Value is the attribute_value // itself. addAttributeFromSingleValue(pJson, new HistoryKey(pJmxReq), KEY_HISTORY, pJson.get(KEY_VALUE), pTimestamp); } }