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; }
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(); }
protected Object operationResult(String mbean, String operation, Object... arguments) throws MalformedObjectNameException, J4pException { ObjectName objectName = new ObjectName(mbean); J4pResponse<J4pExecRequest> results = client.execute(new J4pExecRequest(objectName, operation, arguments)); return results.getValue(); }
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(); } }
return expectedReturnType.cast(response.getValue());
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String name = method.getName(); String attribute; AbtractJ4pMBeanRequest request; if ((attribute = getterAttributeName(method)) != null) { request = new J4pReadRequest(objectName, attribute); } else if ((attribute = setterAttributeName(method)) != null) { request = new J4pWriteRequest(objectName, attribute, args[0]); } else { name = executeMethodName(method); if (args == null | method.getParameterTypes().length == 0) { request = new J4pExecRequest(objectName, name); } else { request = new J4pExecRequest(objectName, name, args); } } try { request.setPreferredHttpMethod("POST"); J4pResponse response = jolokia.execute(request); Object value = response.getValue(); return JolokiaHelpers.convertJolokiaToJavaType(method.getReturnType(), value); } catch (J4pException e) { List<Object> argsList = args == null ? null : Arrays.asList(args); LOG.warn("Failed to invoke " + objectName + " method: " + name + " with arguments: " + argsList + ". " + e, e); throw e; } }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String name = method.getName(); String attribute; AbtractJ4pMBeanRequest request; if ((attribute = getterAttributeName(method)) != null) { request = new J4pReadRequest(objectName, attribute); } else if ((attribute = setterAttributeName(method)) != null) { request = new J4pWriteRequest(objectName, attribute, args[0]); } else { name = executeMethodName(method); if (args == null | method.getParameterTypes().length == 0) { request = new J4pExecRequest(objectName, name); } else { request = new J4pExecRequest(objectName, name, args); } } try { request.setPreferredHttpMethod("POST"); J4pResponse response = jolokia.execute(request); Object value = response.getValue(); return JolokiaClients.convertJolokiaToJavaType(method.getReturnType(), value); } catch (J4pException e) { List<Object> argsList = args == null ? null : Arrays.asList(args); LOG.warn("Failed to invoke " + objectName + " method: " + name + " with arguments: " + argsList + ". " + e, e); throw e; } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { if (isGetter(method)) { String attname = getAttributeName(method); J4pReadRequest readReq = new J4pReadRequest(objectName, attname); Object result = client.execute(readReq).getValue(); return unmarshalResult(method, result); } else if (isSetter(method)) { String attname = getAttributeName(method); Object[] params = marshalParameters(method, args); J4pWriteRequest writeReq = new J4pWriteRequest(objectName, attname, params); writeReq.setPreferredHttpMethod("POST"); client.execute(writeReq); return null; } else { Object[] params = marshalParameters(method, args); String operation = getOperationInfo(method).getName(); J4pExecRequest execReq = new J4pExecRequest(objectName, operation, params); execReq.setPreferredHttpMethod("POST"); Object result = client.execute(execReq).getValue(); return unmarshalResult(method, result); } } catch (Throwable th) { LOGGER.error("Proxy invocation error on: " + method.getDeclaringClass().getName() + "." + method.getName(), th); throw th; } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { if (isGetter(method)) { String attname = getAttributeName(method); J4pReadRequest readReq = new J4pReadRequest(objectName, attname); Object result = client.execute(readReq).getValue(); return unmarshalResult(method, result); } else if (isSetter(method)) { String attname = getAttributeName(method); Object[] params = marshalParameters(method, args); J4pWriteRequest writeReq = new J4pWriteRequest(objectName, attname, params); writeReq.setPreferredHttpMethod("POST"); client.execute(writeReq); return null; } else { Object[] params = marshalParameters(method, args); String operation = getOperationInfo(method).getName(); J4pExecRequest execReq = new J4pExecRequest(objectName, operation, params); execReq.setPreferredHttpMethod("POST"); Object result = client.execute(execReq).getValue(); return unmarshalResult(method, result); } } catch (Throwable th) { LOGGER.error("Proxy invocation error on: " + method.getDeclaringClass().getName() + "." + method.getName(), th); throw th; } }