public static J4pReadRequest createCustomReadRequest(String mbeanUrl, String attribute) throws MalformedObjectNameException { J4pReadRequest answer = null; if (attribute == null || attribute.toString().length() < 1) { answer = new J4pReadRequest(mbeanUrl); } else { answer = new J4pReadRequest(mbeanUrl, attribute); } answer.setPreferredHttpMethod("POST"); return answer; }
/** {@inheritDoc} */ @Override List<String> getRequestParts() { if (hasSingleAttribute()) { List<String> ret = super.getRequestParts(); ret.add(getAttribute()); addPath(ret,path); return ret; } else if (hasAllAttributes() && path == null) { return super.getRequestParts(); } // A GET request cant be used for multiple attribute fetching or for fetching // all attributes with a path return null; }
ObjectName requestBean = request.getObjectName(); if (requestBean.isPattern()) { throw new IllegalArgumentException( if (request.hasSingleAttribute()) { if (pAttribute != null && !pAttribute.equals(request.getAttribute())) { throw new IllegalArgumentException("Given attribute " + pAttribute + " doesnt match single attribute " + "given " + request.getAttribute() + " in the request");
public static List<ObjectName> getDestinations(J4pClient client, ObjectName root, String type) throws Exception { List<ObjectName> list = new ArrayList<>(); String objectNameStr = root.toString() + ",destinationType=" + type + ",destinationName=*"; J4pResponse<J4pReadRequest> response = client.execute(new J4pReadRequest(new ObjectName(objectNameStr), "Name")); JSONObject value = response.getValue(); for (Object key : value.keySet()) { ObjectName objectName = new ObjectName(key.toString()); list.add(objectName); } return list; }
J4pReadRequest readReq = new J4pReadRequest(strBeanName, strAttrName); readReq.setPreferredHttpMethod("POST"); if (strAttrPath != null) { readReq.setPath(strAttrPath);
public static List<ObjectName> getDestinations(J4pClient client, ObjectName root, String type) throws Exception { List<ObjectName> list = new ArrayList<>(); String objectNameStr = root.toString() + ",destinationType=" + type + ",destinationName=*"; J4pResponse<J4pReadRequest> response = client.execute(new J4pReadRequest(new ObjectName(objectNameStr), "Name")); JSONObject value = response.getValue(); for (Object key : value.keySet()) { ObjectName objectName = new ObjectName(key.toString()); list.add(objectName); } return list; }
/** * Returns the attribute value of the given mbean and attribute name */ public Object attributeValue(String mbean, String attribute) throws MalformedObjectNameException, J4pException { ObjectName objectName = new ObjectName(mbean); J4pResponse<J4pReadRequest> results = client.execute(new J4pReadRequest(objectName, attribute)); return results.getValue(); }
public static J4pReadRequest createReadRequest(String attribute) throws MalformedObjectNameException { J4pReadRequest answer = null; if (attribute == null || attribute.toString().length() < 1) { answer = new J4pReadRequest(MBeans.FABRIC.getUrl()); } else { answer = new J4pReadRequest(MBeans.FABRIC.getUrl(), attribute); } answer.setPreferredHttpMethod("POST"); return answer; }
public static ObjectName getRoot(J4pClient client) throws Exception { String type = "org.apache.activemq:*,type=Broker"; String attribute = "BrokerName"; ObjectName objectName = new ObjectName(type); J4pResponse<J4pReadRequest> response = client.execute(new J4pReadRequest(objectName, attribute)); JSONObject jsonObject = response.getValue(); JSONObject nameObject = (JSONObject) jsonObject.values().iterator().next(); String name = nameObject.values().iterator().next().toString(); return new ObjectName("org.apache.activemq:type=Broker,brokerName=" + name); }
public static ObjectName getRoot(J4pClient client) throws Exception { String type = "org.apache.activemq:*,type=Broker"; String attribute = "BrokerName"; ObjectName objectName = new ObjectName(type); J4pResponse<J4pReadRequest> response = client.execute(new J4pReadRequest(objectName, attribute)); JSONObject jsonObject = response.getValue(); JSONObject nameObject = (JSONObject) jsonObject.values().iterator().next(); String name = nameObject.values().iterator().next().toString(); return new ObjectName("org.apache.activemq:type=Broker,brokerName=" + name); }
public static Object getAttribute(J4pClient client, ObjectName objectName, String attribute) throws Exception { J4pResponse<J4pReadRequest> result = client.execute(new J4pReadRequest(objectName, attribute)); return result.getValue(); } }
public static Object getAttribute(J4pClient client, ObjectName objectName, String attribute) throws Exception { J4pResponse<J4pReadRequest> result = client.execute(new J4pReadRequest(objectName, attribute)); return result.getValue(); } }
@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; }
@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; }
list.add(new J4pReadRequest(found)); list.add(new J4pReadRequest(tc)); list.add(new J4pReadRequest(am)); J4pReadResponse rsc = jolokia.execute(new J4pReadRequest(sc)); if (rsc != null) { for (String key : rsc.getAttributes()) {
@SuppressWarnings("unchecked") @Override public Number getValue(ObjectName mbeanName, String attributeName, String[] jmxPath) throws InvocationTargetException { J4pReadRequest req = new J4pReadRequest(mbeanName, attributeName); try { J4pReadResponse resp = connection.execute(req);
list.add(new J4pReadRequest(on, ROUTE_ID, RESET_TIMESTAMP, EXCHANGES_TOTAL, EXCHANGES_FAILED, LAST_COMPLETED_TIMESTAMP, LAST_FAILED_TIMESTAMP, START_TIMESTAMP ));
list.add(new J4pReadRequest(on, ROUTE_ID, RESET_TIMESTAMP, EXCHANGES_TOTAL, EXCHANGES_FAILED, LAST_COMPLETED_TIMESTAMP, LAST_FAILED_TIMESTAMP, START_TIMESTAMP ));
/** * @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(); } }
list.add(new J4pReadRequest(on, "CamelId", "RouteId", "State", "Uptime", "ExchangesTotal", "ExchangesInflight", "ExchangesFailed"));