Java Code Examples for javax.management.MBeanParameterInfo#getType()

The following examples show how to use javax.management.MBeanParameterInfo#getType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JMXProxyServlet.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Invokes an operation on an MBean.
 *
 * @param onameStr The name of the MBean.
 * @param operation The name of the operation to invoke.
 * @param parameters An array of Strings containing the parameters to the
 *            operation. They will be converted to the appropriate types to
 *            call the requested operation.
 * @return The value returned by the requested operation.
 */
private Object invokeOperationInternal(String onameStr, String operation, String[] parameters)
        throws OperationsException, MBeanException, ReflectionException {
    ObjectName oname = new ObjectName(onameStr);
    MBeanOperationInfo methodInfo = registry.getMethodInfo(oname, operation);
    MBeanParameterInfo[] signature = methodInfo.getSignature();
    String[] signatureTypes = new String[signature.length];
    Object[] values = new Object[signature.length];
    for (int i = 0; i < signature.length; i++) {
        MBeanParameterInfo pi = signature[i];
        signatureTypes[i] = pi.getType();
        values[i] = registry.convertValue(pi.getType(), parameters[i]);
    }

    return mBeanServer.invoke(oname, operation, values, signatureTypes);
}
 
Example 2
Source File: JMXProxyServlet.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Invokes an operation on an MBean.
 * @param onameStr The name of the MBean.
 * @param operation The name of the operation to invoke.
 * @param parameters An array of Strings containing the parameters to the
 *                   operation. They will be converted to the appropriate
 *                   types to call the reuested operation.
 * @return The value returned by the requested operation.
 */
private Object invokeOperationInternal(String onameStr,
                                       String operation,
                                       String[] parameters)
    throws OperationsException, MBeanException, ReflectionException {
    ObjectName oname=new ObjectName( onameStr );
    MBeanOperationInfo methodInfo = registry.getMethodInfo(oname,operation);
    MBeanParameterInfo[] signature = methodInfo.getSignature();
    String[] signatureTypes = new String[signature.length];
    Object[] values = new Object[signature.length];
    for (int i = 0; i < signature.length; i++) {
       MBeanParameterInfo pi = signature[i];
       signatureTypes[i] = pi.getType();
       values[i] = registry.convertValue(pi.getType(), parameters[i] );
     }

    return mBeanServer.invoke(oname,operation,values,signatureTypes);
}
 
Example 3
Source File: JMXProxyServlet.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Invokes an operation on an MBean.
 * @param onameStr The name of the MBean.
 * @param operation The name of the operation to invoke.
 * @param parameters An array of Strings containing the parameters to the
 *                   operation. They will be converted to the appropriate
 *                   types to call the reuested operation.
 * @return The value returned by the requested operation.
 */
private Object invokeOperationInternal(String onameStr,
                                       String operation,
                                       String[] parameters)
    throws OperationsException, MBeanException, ReflectionException {
    ObjectName oname=new ObjectName( onameStr );
    MBeanOperationInfo methodInfo = registry.getMethodInfo(oname,operation);
    MBeanParameterInfo[] signature = methodInfo.getSignature();
    String[] signatureTypes = new String[signature.length];
    Object[] values = new Object[signature.length];
    for (int i = 0; i < signature.length; i++) {
       MBeanParameterInfo pi = signature[i];
       signatureTypes[i] = pi.getType();
       values[i] = registry.convertValue(pi.getType(), parameters[i] );
     }

    return mBeanServer.invoke(oname,operation,values,signatureTypes);
}
 
Example 4
Source File: Client.java    From vjtools with Apache License 2.0 5 votes vote down vote up
protected static Object doBeanOperation(MBeanServerConnection mbsc, ObjectInstance instance, String command,
		MBeanOperationInfo[] infos) throws Exception {
	// Parse command line.
	CommandParse parse = new CommandParse(command);

	// Get first method of name 'cmd'. Assumption is no method
	// overrides. Then, look at the method and use its signature
	// to make sure client sends over parameters of the correct type.
	MBeanOperationInfo op = (MBeanOperationInfo) getFeatureInfo(infos, parse.getCmd());
	Object result = null;
	if (op == null) {
		result = "Operation " + parse.getCmd() + " not found.";
	} else {
		MBeanParameterInfo[] paraminfos = op.getSignature();
		int paraminfosLength = (paraminfos == null) ? 0 : paraminfos.length;
		int objsLength = (parse.getArgs() == null) ? 0 : parse.getArgs().length;
		if (paraminfosLength != objsLength) {
			result = "Passed param count does not match signature count";
		} else {
			String[] signature = new String[paraminfosLength];
			Object[] params = (paraminfosLength == 0) ? null : new Object[paraminfosLength];
			for (int i = 0; i < paraminfosLength; i++) {
				MBeanParameterInfo paraminfo = paraminfos[i];
				java.lang.reflect.Constructor c = Class.forName(paraminfo.getType())
						.getConstructor(new Class[] { String.class });
				params[i] = c.newInstance(new Object[] { parse.getArgs()[i] });
				signature[i] = paraminfo.getType();
			}
			result = mbsc.invoke(instance.getObjectName(), parse.getCmd(), params, signature);
		}
	}
	return result;
}
 
Example 5
Source File: Client.java    From vjtools with Apache License 2.0 5 votes vote down vote up
protected static Object doBeanOperation(MBeanServerConnection mbsc, ObjectInstance instance, String command,
		MBeanOperationInfo[] infos) throws Exception {
	// Parse command line.
	CommandParse parse = new CommandParse(command);

	// Get first method of name 'cmd'. Assumption is no method
	// overrides. Then, look at the method and use its signature
	// to make sure client sends over parameters of the correct type.
	MBeanOperationInfo op = (MBeanOperationInfo) getFeatureInfo(infos, parse.getCmd());
	Object result = null;
	if (op == null) {
		result = "Operation " + parse.getCmd() + " not found.";
	} else {
		MBeanParameterInfo[] paraminfos = op.getSignature();
		int paraminfosLength = (paraminfos == null) ? 0 : paraminfos.length;
		int objsLength = (parse.getArgs() == null) ? 0 : parse.getArgs().length;
		if (paraminfosLength != objsLength) {
			result = "Passed param count does not match signature count";
		} else {
			String[] signature = new String[paraminfosLength];
			Object[] params = (paraminfosLength == 0) ? null : new Object[paraminfosLength];
			for (int i = 0; i < paraminfosLength; i++) {
				MBeanParameterInfo paraminfo = paraminfos[i];
				java.lang.reflect.Constructor c = Class.forName(paraminfo.getType())
						.getConstructor(new Class[] { String.class });
				params[i] = c.newInstance(new Object[] { parse.getArgs()[i] });
				signature[i] = paraminfo.getType();
			}
			result = mbsc.invoke(instance.getObjectName(), parse.getCmd(), params, signature);
		}
	}
	return result;
}