private JSONObject getAttributesForObjectNameWithPatternRequest(ObjectName pObjectName) { ObjectName pMBeanFromRequest = getRequest().getObjectName(); ObjectName objectName = pObjectName == null ? pMBeanFromRequest : pObjectName; JSONObject values = getValue(); JSONObject attributes = (JSONObject) values.get(objectName.getCanonicalName()); if (attributes == null) { throw new IllegalArgumentException("No ObjectName " + objectName + " found in the set of returned " + " ObjectNames for requested pattern " + pMBeanFromRequest); } return attributes; } }
/** * 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 */ 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(); } }
/** {@inheritDoc} */ @Override J4pReadResponse createResponse(JSONObject pResponse) { return new J4pReadResponse(this,pResponse); }
/** * 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 * @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); } }
public static String readToJSON(J4pClient j4p, String attribute) { try { J4pReadRequest request = createReadRequest(attribute); J4pReadResponse response = j4p.execute(request); return response.getValue().toString(); } catch (Exception e) { throw new RuntimeException("Failed to read " + attribute, e); } }
String routeId = rr.getValue(ROUTE_ID).toString(); if (filter == null || routeId.matches(filter)) { Map<String, String> row = new LinkedHashMap<String, String>(); for (String attribute : rr.getAttributes()) { if (rr.getValue(attribute) != null) { row.put(attribute, rr.getValue(attribute).toString());
public static String readCustomToJSON(J4pClient j4p, String mbeanUrl, String attribute) { try { J4pReadRequest request = createCustomReadRequest(mbeanUrl, attribute); J4pReadResponse response = j4p.execute(request); return response.getValue().toString(); } catch (Exception e) { throw new RuntimeException("Failed to read " + attribute, e); } }
String routeId = rr.getValue(ROUTE_ID).toString(); if (filter == null || routeId.matches(filter)) { Map<String, String> row = new LinkedHashMap<String, String>(); for (String attribute : rr.getAttributes()) { if (rr.getValue(attribute) != null) { row.put(attribute, rr.getValue(attribute).toString());
@Override public List<Map<String, String>> getCamelContexts() throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } List<Map<String, String>> answer = new ArrayList<>(); J4pSearchResponse sr = jolokia.execute(new J4pSearchRequest("*:type=context,*")); List<J4pReadRequest> list = new ArrayList<>(); for (ObjectName on : sr.getObjectNames()) { list.add(new J4pReadRequest(on, "CamelId", "State", "Uptime", "ExchangesTotal", "ExchangesInflight", "ExchangesFailed")); } List<J4pReadResponse> lrr = jolokia.execute(list); for (J4pReadResponse rr : lrr) { Map<String, String> row = new LinkedHashMap<>(); row.put("name", rr.getValue("CamelId").toString()); row.put("state", rr.getValue("State").toString()); row.put("uptime", rr.getValue("Uptime").toString()); row.put("exchangesTotal", rr.getValue("ExchangesTotal").toString()); row.put("exchangesInflight", rr.getValue("ExchangesInflight").toString()); row.put("exchangesFailed", rr.getValue("ExchangesFailed").toString()); answer.add(row); } return answer; }
for (String key : first.getAttributes()) { answer.put(asKey(key), first.getValue(key)); for (String key : second.getAttributes()) { answer.put("typeConverter." + asKey(key), second.getValue(key)); for (String key : second.getAttributes()) { answer.put("asyncProcessorAwaitManager." + asKey(key), second.getValue(key)); for (String key : rsc.getAttributes()) { answer.put("streamCaching." + asKey(key), rsc.getValue(key));
/** * 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 * @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); } }
public static <T extends Object> T read(J4pClient j4p, String attribute) { try { J4pReadRequest request = createReadRequest(attribute); J4pReadResponse response = j4p.execute(request); return response.getValue(); } catch (Exception e) { throw new RuntimeException("Failed to read " + attribute, e); } }
J4pReadRequest request = getRequest(); ObjectName requestBean = request.getObjectName(); if (requestBean.isPattern()) { "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");
@Override public List<Map<String, String>> getEndpoints(String camelContextName) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } List<Map<String, String>> answer = new ArrayList<>(); ObjectName found = lookupCamelContext(camelContextName); if (found != null) { String pattern = String.format("%s:context=%s,type=endpoints,*", found.getDomain(), found.getKeyProperty("context")); J4pSearchResponse sr = jolokia.execute(new J4pSearchRequest(pattern)); List<J4pReadRequest> list = new ArrayList<>(); for (ObjectName on : sr.getObjectNames()) { list.add(new J4pReadRequest(on, "CamelId", "EndpointUri", "State")); } List<J4pReadResponse> lrr = jolokia.execute(list); for (J4pReadResponse rr : lrr) { Map<String, String> row = new LinkedHashMap<>(); row.put("camelContextName", rr.getValue("CamelId").toString()); row.put("uri", rr.getValue("EndpointUri").toString()); row.put("state", rr.getValue("State").toString()); answer.add(row); } } return answer; }
/** * 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. */ 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(); } }
String routeId = rr.getValue("RouteId").toString(); if (filter == null || routeId.matches(filter)) { Map<String, String> row = new LinkedHashMap<>(); row.put("camelContextName", rr.getValue("CamelId").toString()); row.put("routeId", routeId); row.put("state", rr.getValue("State").toString()); row.put("uptime", rr.getValue("Uptime").toString()); row.put("exchangesTotal", rr.getValue("ExchangesTotal").toString()); row.put("exchangesInflight", rr.getValue("ExchangesInflight").toString()); row.put("exchangesFailed", rr.getValue("ExchangesFailed").toString()); answer.add(row);
try { J4pReadResponse resp = connection.execute(req); Object o = resp.getValue(); for (String i: jmxPath) { if (o instanceof Map) {
/** * @param mbeanName * @param string * @return */ public String readAttribute(String mbeanName, String attribute) { J4pReadRequest readRequest; J4pReadResponse readResponse = null; try { readRequest = new J4pReadRequest(mbeanName, attribute); readResponse = j4pClient.execute(readRequest); } catch (MalformedObjectNameException e) { return e.getMessage(); } catch (J4pException e) { return e.getMessage(); } return readResponse.getValue().toString(); } }
response = resp.getValue().toString(); } else { J4pExecRequest execReq;