List of usage examples for javax.management ObjectName toString
@Override
public String toString()
Returns a string representation of the object name.
From source file:com.heliosapm.opentsdb.TSDBSubmitterImpl.java
/** * {@inheritDoc}/* w ww . j a v a 2 s. c om*/ * @see com.heliosapm.opentsdb.TSDBSubmitter#trace(java.util.Map) */ @Override public void trace(final Map<ObjectName, Map<String, Object>> batchResults) { if (batchResults == null || batchResults.isEmpty()) return; for (Map.Entry<ObjectName, Map<String, Object>> entry : batchResults.entrySet()) { final ObjectName on = entry.getKey(); final Map<String, Object> keyValuePairs = entry.getValue(); TSDBJMXResultTransformer transformer = tsdbConnection.transformCache.getTransformer(on); if (transformer != null) { Map<ObjectName, Number> transformed = transformer.transform(on, keyValuePairs); for (Map.Entry<ObjectName, Number> t : transformed.entrySet()) { final Number v = t.getValue(); if (v == null) continue; if (v instanceof Double) { trace(t.getKey(), v.doubleValue()); } else { trace(t.getKey(), v.longValue()); } } } else { for (Map.Entry<String, Object> attr : entry.getValue().entrySet()) { final Object v = attr.getValue(); if (v == null) continue; if (v instanceof Number) { if (v instanceof Double) { trace(JMXHelper.objectName(clean( new StringBuilder(on.toString()).append(",metric=").append(attr.getKey()))), ((Number) v).doubleValue()); } else { trace(JMXHelper.objectName(clean( new StringBuilder(on.toString()).append(",metric=").append(attr.getKey()))), ((Number) v).longValue()); } } else if (v instanceof CompositeData) { Map<ObjectName, Number> cmap = fromOpenType(on, (CompositeData) v); for (Map.Entry<ObjectName, Number> ce : cmap.entrySet()) { final Number cv = ce.getValue(); if (v instanceof Double) { trace(ce.getKey(), cv.doubleValue()); } else { trace(ce.getKey(), cv.longValue()); } } } } } } }
From source file:com.streamsets.datacollector.http.JMXJsonServlet.java
private void listBeans(JsonGenerator jg, ObjectName qry, String attribute, HttpServletResponse response) throws IOException { Set<ObjectName> names = null; names = mBeanServer.queryNames(qry, null); jg.writeArrayFieldStart("beans"); Iterator<ObjectName> it = names.iterator(); while (it.hasNext()) { ObjectName oname = it.next(); MBeanInfo minfo;//from w w w . ja va2s .c om String code = ""; Object attributeinfo = null; try { minfo = mBeanServer.getMBeanInfo(oname); code = minfo.getClassName(); String prs = ""; try { if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) { prs = "modelerType"; code = (String) mBeanServer.getAttribute(oname, prs); } if (attribute != null) { prs = attribute; attributeinfo = mBeanServer.getAttribute(oname, prs); } } catch (AttributeNotFoundException e) { // If the modelerType attribute was not found, the class name is used // instead. } catch (MBeanException e) { // The code inside the attribute getter threw an exception so // and fall back on the class name } catch (RuntimeException e) { // For some reason even with an MBeanException available to them // Runtime exceptionscan still find their way through, so treat them // the same as MBeanException } catch (ReflectionException e) { // This happens when the code inside the JMX bean (setter?? from the // java docs) threw an exception, so // class name } } catch (InstanceNotFoundException e) { //Ignored for some reason the bean was not found so don't output it continue; } catch (IntrospectionException e) { // This is an internal error, something odd happened with reflection so // continue; } catch (ReflectionException e) { // This happens when the code inside the JMX bean threw an exception, so // continue; } jg.writeStartObject(); jg.writeStringField("name", oname.toString()); jg.writeStringField("modelerType", code); if ((attribute != null) && (attributeinfo == null)) { jg.writeStringField("result", "ERROR"); jg.writeStringField("message", "No attribute with name " + attribute + " was found."); jg.writeEndObject(); jg.writeEndArray(); jg.close(); response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } if (attribute != null) { writeAttribute(jg, attribute, attributeinfo); } else { MBeanAttributeInfo attrs[] = minfo.getAttributes(); for (int i = 0; i < attrs.length; i++) { writeAttribute(jg, oname, attrs[i]); } } jg.writeEndObject(); } jg.writeEndArray(); }
From source file:org.apache.hadoop.jmx.JMXJsonServlet.java
private void listBeans(JsonGenerator jg, ObjectName qry) throws IOException { LOG.debug("Listing beans for " + qry); Set<ObjectName> names = null; names = mBeanServer.queryNames(qry, null); jg.writeArrayFieldStart("beans"); Iterator<ObjectName> it = names.iterator(); while (it.hasNext()) { ObjectName oname = it.next(); MBeanInfo minfo;//from w ww . jav a 2s . co m String code; try { minfo = mBeanServer.getMBeanInfo(oname); code = minfo.getClassName(); try { if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) { code = (String) mBeanServer.getAttribute(oname, "modelerType"); } } catch (AttributeNotFoundException e) { //Ignored the modelerType attribute was not found, so use the class name instead. } catch (MBeanException e) { //The code inside the attribute getter threw an exception so log it, and // fall back on the class name LOG.error("getting attribute modelerType of " + oname + " threw an exception", e); } catch (RuntimeException e) { //For some reason even with an MBeanException available to them Runtime exceptions //can still find their way through, so treat them the same as MBeanException LOG.error("getting attribute modelerType of " + oname + " threw an exception", e); } catch (ReflectionException e) { //This happens when the code inside the JMX bean (setter?? from the java docs) //threw an exception, so log it and fall back on the class name LOG.error("getting attribute modelerType of " + oname + " threw an exception", e); } } catch (InstanceNotFoundException e) { //Ignored for some reason the bean was not found so don't output it continue; } catch (IntrospectionException e) { //This is an internal error, something odd happened with reflection so log it and //don't output the bean. LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e); continue; } catch (ReflectionException e) { //This happens when the code inside the JMX bean threw an exception, so log it and //don't output the bean. LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e); continue; } jg.writeStartObject(); jg.writeStringField("name", oname.toString()); // can't be null - I think jg.writeStringField("modelerType", code); MBeanAttributeInfo attrs[] = minfo.getAttributes(); for (int i = 0; i < attrs.length; i++) { writeAttribute(jg, oname, attrs[i]); } // LOG.error("Caught Error writing value ",t); // ExceptionUtils.handleThrowable(t); //} jg.writeEndObject(); } jg.writeEndArray(); }
From source file:org.alfresco.solr.SolrInformationServer.java
private String getHttpPort(String defaultPort) { try {/*from www . ja va2 s . c om*/ MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0); QueryExp query = Query.and(Query.eq(Query.attr("scheme"), Query.value("http")), Query.eq(Query.attr("protocol"), Query.value("HTTP/1.1"))); Set<ObjectName> objectNames = mBeanServer.queryNames(null, query); if (objectNames != null && objectNames.size() > 0) { for (ObjectName objectName : objectNames) { String name = objectName.toString(); if (name.indexOf("port=") > -1) { String[] parts = name.split("port="); String port = parts[1]; try { Integer.parseInt(port); return port; } catch (NumberFormatException e) { log.error("Error parsing http port:" + port); return defaultPort; } } } } } catch (Throwable t) { log.error("Error getting https port:", t); } return defaultPort; }
From source file:com.heliosapm.opentsdb.TSDBSubmitterImpl.java
/** * {@inheritDoc}/*w w w . j av a 2s . c om*/ * @see com.heliosapm.opentsdb.TSDBSubmitter#trace(javax.management.ObjectName, java.lang.String, java.util.Map, java.lang.String[]) */ @Override public void trace(final ObjectName target, final String metricName, final Map<String, Object> attributeValues, final String... objectNameKeys) { if (target == null) throw new IllegalArgumentException("The passed target ObjectName was null"); if (objectNameKeys == null || objectNameKeys.length == 0) throw new IllegalArgumentException("At least one ObjectName Key is required"); if (attributeValues == null || attributeValues.isEmpty()) return; final String m = (metricName == null || metricName.trim().isEmpty()) ? target.getDomain() : metricName.trim(); final Map<String, String> tags = new LinkedHashMap<String, String>(rootTagsMap); int keyCount = 0; boolean all = (objectNameKeys.length == 1 && "*".equals(objectNameKeys[0])); if (all) { for (Map.Entry<String, String> entry : target.getKeyPropertyList().entrySet()) { tags.put(clean(entry.getKey()), clean(entry.getValue())); keyCount++; } } else { for (String key : objectNameKeys) { if (key == null || key.trim().isEmpty()) continue; String v = clean(target, key.trim()); if (v == null || v.isEmpty()) continue; tags.put(clean(key), clean(v)); keyCount++; } } if (keyCount == 0) throw new IllegalArgumentException("No ObjectName Keys Usable as Tags. Keys: " + Arrays.toString(objectNameKeys) + ", ObjectName: [" + target.toString() + "]"); for (Map.Entry<String, Object> attr : attributeValues.entrySet()) { final String attributeName = clean(attr.getKey()); try { tags.put("metric", attributeName); final Object v = attr.getValue(); if (v == null) continue; if (v instanceof Number) { if (v instanceof Double) { trace(m, (Double) v, tags); } else { trace(m, ((Number) v).longValue(), tags); } } else if (v instanceof CompositeData) { final CompositeData cd = (CompositeData) v; tags.put("ctype", attributeName); try { Map<String, Number> cmap = fromOpenType(cd); for (Map.Entry<String, Number> ce : cmap.entrySet()) { final String key = clean(ce.getKey()); tags.put("metric", key); try { final Number cv = ce.getValue(); if (v instanceof Double) { trace(m, cv.doubleValue(), tags); } else { trace(m, cv.longValue(), tags); } } finally { tags.put("metric", attributeName); } } } finally { tags.remove("ctype"); } } } finally { tags.remove("metric"); } } }
From source file:org.apache.hadoop.hbase.util.JSONBean.java
/** * @param mBeanServer/*from w ww . j a va 2 s .c o m*/ * @param qry * @param attribute * @param description * @return Return non-zero if failed to find bean. 0 * @throws IOException */ private static int write(final JsonGenerator jg, final MBeanServer mBeanServer, ObjectName qry, String attribute, final boolean description) throws IOException { LOG.trace("Listing beans for " + qry); Set<ObjectName> names = null; names = mBeanServer.queryNames(qry, null); jg.writeArrayFieldStart("beans"); Iterator<ObjectName> it = names.iterator(); while (it.hasNext()) { ObjectName oname = it.next(); MBeanInfo minfo; String code = ""; String descriptionStr = null; Object attributeinfo = null; try { minfo = mBeanServer.getMBeanInfo(oname); code = minfo.getClassName(); if (description) descriptionStr = minfo.getDescription(); String prs = ""; try { if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) { prs = "modelerType"; code = (String) mBeanServer.getAttribute(oname, prs); } if (attribute != null) { prs = attribute; attributeinfo = mBeanServer.getAttribute(oname, prs); } } catch (RuntimeMBeanException e) { // UnsupportedOperationExceptions happen in the normal course of business, // so no need to log them as errors all the time. if (e.getCause() instanceof UnsupportedOperationException) { if (LOG.isTraceEnabled()) { LOG.trace("Getting attribute " + prs + " of " + oname + " threw " + e); } } else { LOG.error("Getting attribute " + prs + " of " + oname + " threw an exception", e); } return 0; } catch (AttributeNotFoundException e) { // If the modelerType attribute was not found, the class name is used // instead. LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } catch (MBeanException e) { // The code inside the attribute getter threw an exception so log it, // and fall back on the class name LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } catch (RuntimeException e) { // For some reason even with an MBeanException available to them // Runtime exceptionscan still find their way through, so treat them // the same as MBeanException LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } catch (ReflectionException e) { // This happens when the code inside the JMX bean (setter?? from the // java docs) threw an exception, so log it and fall back on the // class name LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } } catch (InstanceNotFoundException e) { //Ignored for some reason the bean was not found so don't output it continue; } catch (IntrospectionException e) { // This is an internal error, something odd happened with reflection so // log it and don't output the bean. LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e); continue; } catch (ReflectionException e) { // This happens when the code inside the JMX bean threw an exception, so // log it and don't output the bean. LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e); continue; } jg.writeStartObject(); jg.writeStringField("name", oname.toString()); if (description && descriptionStr != null && descriptionStr.length() > 0) { jg.writeStringField("description", descriptionStr); } jg.writeStringField("modelerType", code); if (attribute != null && attributeinfo == null) { jg.writeStringField("result", "ERROR"); jg.writeStringField("message", "No attribute with name " + attribute + " was found."); jg.writeEndObject(); jg.writeEndArray(); jg.close(); return -1; } if (attribute != null) { writeAttribute(jg, attribute, descriptionStr, attributeinfo); } else { MBeanAttributeInfo[] attrs = minfo.getAttributes(); for (int i = 0; i < attrs.length; i++) { writeAttribute(jg, mBeanServer, oname, description, attrs[i]); } } jg.writeEndObject(); } jg.writeEndArray(); return 0; }
From source file:org.apache.hive.http.JMXJsonServlet.java
private void listBeans(JsonGenerator jg, ObjectName qry, String attribute, HttpServletResponse response) throws IOException { LOG.debug("Listing beans for " + qry); Set<ObjectName> names = null; names = mBeanServer.queryNames(qry, null); jg.writeArrayFieldStart("beans"); Iterator<ObjectName> it = names.iterator(); while (it.hasNext()) { ObjectName oname = it.next(); MBeanInfo minfo;// w ww . j a va 2 s.c o m String code = ""; Object attributeinfo = null; try { minfo = mBeanServer.getMBeanInfo(oname); code = minfo.getClassName(); String prs = ""; try { if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) { prs = "modelerType"; code = (String) mBeanServer.getAttribute(oname, prs); } if (attribute != null) { prs = attribute; attributeinfo = mBeanServer.getAttribute(oname, prs); } } catch (AttributeNotFoundException e) { // If the modelerType attribute was not found, the class name is used // instead. LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } catch (MBeanException e) { // The code inside the attribute getter threw an exception so log it, // and fall back on the class name LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } catch (RuntimeException e) { // For some reason even with an MBeanException available to them // Runtime exceptions can still find their way through, so treat them // the same as MBeanException LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } catch (ReflectionException e) { // This happens when the code inside the JMX bean (setter?? from the // java docs) threw an exception, so log it and fall back on the // class name LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e); } } catch (InstanceNotFoundException e) { //Ignored for some reason the bean was not found so don't output it continue; } catch (IntrospectionException e) { // This is an internal error, something odd happened with reflection so // log it and don't output the bean. LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e); continue; } catch (ReflectionException e) { // This happens when the code inside the JMX bean threw an exception, so // log it and don't output the bean. LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e); continue; } jg.writeStartObject(); jg.writeStringField("name", oname.toString()); jg.writeStringField("modelerType", code); if ((attribute != null) && (attributeinfo == null)) { jg.writeStringField("result", "ERROR"); jg.writeStringField("message", "No attribute with name " + attribute + " was found."); jg.writeEndObject(); jg.writeEndArray(); jg.close(); response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } if (attribute != null) { writeAttribute(jg, attribute, attributeinfo); } else { MBeanAttributeInfo attrs[] = minfo.getAttributes(); for (int i = 0; i < attrs.length; i++) { writeAttribute(jg, oname, attrs[i]); } } jg.writeEndObject(); } jg.writeEndArray(); }
From source file:io.fabric8.api.registry.rules.CamelEndpointFinder.java
@Override protected void appendObjectNameEndpoints(List<ApiDTO> list, ApiSnapshot snapshot, Pod pod, Container container, J4pClient jolokia, ObjectName objectName) throws MalformedObjectNameException, J4pException { String httpUrl = getHttpUrl(pod, container, jolokia); String urlPrefix = snapshot.getUrlPrefix(); if (httpUrl != null) { URL url = null;/* w w w .j a v a 2 s. c o m*/ try { url = new URL(httpUrl); } catch (MalformedURLException e) { LOG.warn("Failed to parse http URL: " + httpUrl + ". " + e, e); return; } ApiDeclaration apiDeclaration = new ApiDeclaration(); apiDeclaration.setModels(new Models()); // lets find the rest services... J4pResponse<J4pExecRequest> results = jolokia .execute(new J4pExecRequest(objectName, "listRestServices")); Object value = results.getValue(); if (value instanceof Map) { Map<String, Object> map = (Map<String, Object>) value; Set<Map.Entry<String, Object>> entrySet = map.entrySet(); for (Map.Entry<String, Object> entry : entrySet) { String uriPattern = entry.getKey(); Object entryValue = entry.getValue(); if (entryValue instanceof Map) { Map<String, Object> entryMap = (Map<String, Object>) entryValue; Set<Map.Entry<String, Object>> operations = entryMap.entrySet(); for (Map.Entry<String, Object> operation : operations) { String operationName = operation.getKey(); Object operationValue = operation.getValue(); if (operationValue instanceof Map) { Map operationMap = (Map) operationValue; CamelRestService restService = new CamelRestService(); try { BeanUtils.populate(restService, operationMap); } catch (Exception e) { LOG.warn("Failed to populate " + restService + " from " + operationMap + ". " + e, e); return; } restService.setUrl(replaceHostAndPort(url, restService.getUrl())); restService.setBaseUrl(replaceHostAndPort(url, restService.getBaseUrl())); addToApiDescription(apiDeclaration, restService, objectName); } } } } } List<Api> apis = apiDeclaration.getApis(); if (apis != null && apis.size() > 0) { // TODO where should we get the API version from? // lets add a default version if (Strings.isNullOrBlank(apiDeclaration.getApiVersion())) { apiDeclaration.setApiVersion("1.0"); } if (apiDeclaration.getSwaggerVersion() == null) { apiDeclaration.setSwaggerVersion(ApiDeclaration.SwaggerVersion._1_2); } String podId = getName(pod); // TODO this is not the container id... String containerId = getName(pod); PodAndContainerId key = new PodAndContainerId(podId, containerId); snapshot.putPodAndContainerSwagger(key, apiDeclaration); String basePath = apiDeclaration.getResourcePath(); URI basePathUri = apiDeclaration.getBasePath(); String fullUrl = null; if (basePathUri != null) { fullUrl = basePathUri.toString(); } String swaggerPath = "/swagger/pod/" + podId + "/" + containerId; String swaggerUrl = null; if (Strings.isNotBlank(urlPrefix)) { swaggerUrl = urlPathJoin(urlPrefix, swaggerPath); } String wadlPath = null; String wadlUrl = null; String wsdlPath = null; String wsdlUrl = null; int port = url.getPort(); String state = "RUNNING"; String jolokiaUrl = jolokia.getUri().toString(); String serviceId = null; ApiDTO api = new ApiDTO(pod, container, serviceId, objectName.toString(), basePath, fullUrl, port, state, jolokiaUrl, swaggerPath, swaggerUrl, wadlPath, wadlUrl, wsdlPath, wsdlUrl); list.add(api); } } }
From source file:org.apache.catalina.core.StandardContext.java
/** * Add an environment entry for this web application. * * @param envName New environment entry name *//* ww w . jav a 2 s.c om*/ public String addEnvironment(String envName, String type) throws MalformedObjectNameException { NamingResources nresources = getNamingResources(); if (nresources == null) { return null; } ContextEnvironment env = nresources.findEnvironment(envName); if (env != null) { throw new IllegalArgumentException("Invalid environment name - already exists '" + envName + "'"); } env = new ContextEnvironment(); env.setName(envName); env.setType(type); nresources.addEnvironment(env); // Return the corresponding MBean name ManagedBean managed = Registry.getRegistry().findManagedBean("ContextEnvironment"); ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), env); return (oname.toString()); }
From source file:org.apache.catalina.core.StandardContext.java
/** * Add a resource reference for this web application. * * @param resourceName New resource reference name *///ww w .ja va 2 s .c om public String addResource(String resourceName, String type) throws MalformedObjectNameException { NamingResources nresources = getNamingResources(); if (nresources == null) { return null; } ContextResource resource = nresources.findResource(resourceName); if (resource != null) { throw new IllegalArgumentException("Invalid resource name - already exists'" + resourceName + "'"); } resource = new ContextResource(); resource.setName(resourceName); resource.setType(type); nresources.addResource(resource); // Return the corresponding MBean name ManagedBean managed = Registry.getRegistry().findManagedBean("ContextResource"); ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resource); return (oname.toString()); }