use of javax.management.MBeanOperationInfo in project symmetric-ds by JumpMind.
the class JmxCommand method executeWithOptions.
@Override
protected boolean executeWithOptions(final CommandLine line) throws Exception {
if (line.hasOption(OPTION_LISTBEANS)) {
execute(new IJmxTemplate<Object>() {
@Override
public Object execute(String engineName, MBeanServerConnection mbeanConn) throws Exception {
Set<ObjectName> beanSet = mbeanConn.queryNames(null, null);
for (ObjectName objectName : beanSet) {
if (objectName.getDomain().startsWith("org.jumpmind.symmetric." + engineName)) {
System.out.println(objectName.toString());
}
}
return null;
}
});
} else if (line.hasOption(OPTION_LISTMETHODS) || line.hasOption(OPTION_METHOD)) {
if (line.hasOption(OPTION_BEAN)) {
execute(new IJmxTemplate<Object>() {
@Override
public Object execute(String engineName, MBeanServerConnection mbeanConn) throws Exception {
String beanName = line.getOptionValue(OPTION_BEAN);
MBeanInfo info = mbeanConn.getMBeanInfo(new ObjectName(beanName));
if (info != null) {
if (line.hasOption(OPTION_LISTMETHODS)) {
MBeanOperationInfo[] operations = info.getOperations();
Map<String, MBeanOperationInfo> orderedMap = new TreeMap<String, MBeanOperationInfo>();
for (MBeanOperationInfo methodInfo : operations) {
orderedMap.put(methodInfo.getName(), methodInfo);
}
for (MBeanOperationInfo methodInfo : orderedMap.values()) {
System.out.print(methodInfo.getName() + "(");
MBeanParameterInfo[] params = methodInfo.getSignature();
int index = 0;
for (MBeanParameterInfo p : params) {
if (index > 0) {
System.out.print(", ");
}
System.out.print(p.getType() + " " + p.getName());
index++;
}
System.out.print(")");
if (methodInfo.getReturnType() != null && !methodInfo.getReturnType().equals("void")) {
System.out.print(" : " + methodInfo.getReturnType());
}
System.out.println();
}
} else if (line.hasOption(OPTION_METHOD)) {
String argsDelimiter = line.getOptionValue(OPTION_ARGS_DELIM);
if (isBlank(argsDelimiter)) {
argsDelimiter = ",";
} else {
argsDelimiter = argsDelimiter.trim();
}
String methodName = line.getOptionValue(OPTION_METHOD);
String[] args = null;
if (line.hasOption(OPTION_ARGS)) {
String argLine = line.getOptionValue(OPTION_ARGS);
args = argsDelimiter == "," ? CsvUtils.tokenizeCsvData(argLine) : argLine.split(argsDelimiter);
;
} else {
args = new String[0];
}
MBeanOperationInfo[] operations = info.getOperations();
for (MBeanOperationInfo methodInfo : operations) {
MBeanParameterInfo[] paramInfos = methodInfo.getSignature();
if (methodInfo.getName().equals(methodName) && paramInfos.length == args.length) {
String[] signature = new String[args.length];
Object[] objArgs = new Object[args.length];
int index = 0;
for (MBeanParameterInfo paramInfo : paramInfos) {
signature[index] = paramInfo.getType();
if (!paramInfo.getType().equals(String.class.getName())) {
Class<?> clazz = Class.forName(paramInfo.getType());
Constructor<?> constructor = clazz.getConstructor(String.class);
objArgs[index] = constructor.newInstance(args[index]);
} else {
objArgs[index] = args[index];
}
index++;
}
Object returnValue = mbeanConn.invoke(new ObjectName(beanName), methodName, objArgs, signature);
if (methodInfo.getReturnType() != null && !methodInfo.getReturnType().equals("void")) {
System.out.println(returnValue);
}
System.exit(0);
}
}
System.out.println("ERROR: Could not locate a JMX method named: " + methodName + " with " + args.length + " arguments on bean: " + beanName);
System.exit(1);
return null;
}
} else {
System.out.println("ERROR: Could not locate a JMX bean with the name of: " + beanName);
System.exit(1);
}
return null;
}
});
} else {
System.out.println("ERROR: Must specifiy the --bean option.");
System.exit(1);
}
} else {
return false;
}
return true;
}
use of javax.management.MBeanOperationInfo in project jdk8u_jdk by JetBrains.
the class FeatureOrderTest method main.
public static void main(String[] args) throws Exception {
// Build the lists of attributes and operations that we would expect
// if they are derived by reflection and preserve the reflection order
List<String> expectedAttributeNames = new ArrayList<String>();
List<String> expectedOperationNames = new ArrayList<String>();
for (Method m : OrderMXBean.class.getMethods()) {
String name = m.getName();
String attrName = null;
if (name.startsWith("get") && !name.equals("get") && m.getParameterTypes().length == 0 && m.getReturnType() != void.class)
attrName = name.substring(3);
else if (name.startsWith("is") && !name.equals("is") && m.getParameterTypes().length == 0 && m.getReturnType() == boolean.class)
attrName = name.substring(2);
else if (name.startsWith("set") && !name.equals("set") && m.getReturnType() == void.class && m.getParameterTypes().length == 1)
attrName = name.substring(3);
if (attrName != null) {
if (!expectedAttributeNames.contains(attrName))
expectedAttributeNames.add(attrName);
} else
expectedOperationNames.add(name);
}
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
for (boolean mxbean : booleans) {
for (boolean withStandardMBean : booleans) {
String testName = "MXBean: " + mxbean + "; " + "using javax.management.StandardMBean: " + withStandardMBean;
System.out.println("Test case: " + testName);
Object mbean;
if (mxbean) {
if (withStandardMBean) {
mbean = new StandardMBean(new OrderImpl(), OrderMXBean.class, true);
} else
mbean = new OrderImpl();
} else {
if (withStandardMBean)
mbean = new StandardMBean(new Order(), OrderMBean.class);
else
mbean = new Order();
}
ObjectName name = new ObjectName(":mxbean=" + mxbean + "," + "withStandardMBean=" + withStandardMBean);
mbs.registerMBean(mbean, name);
/* Make sure we are testing what we think. */
MBeanInfo mbi = mbs.getMBeanInfo(name);
boolean isWithStandardMBean = mbs.isInstanceOf(name, StandardMBean.class.getName());
System.out.println("classname " + mbi.getClassName());
String mxbeanField = (String) mbi.getDescriptor().getFieldValue("mxbean");
boolean isMXBean = "true".equalsIgnoreCase(mxbeanField);
if (mxbean != isMXBean)
throw new Exception("Test error: MXBean mismatch");
if (withStandardMBean != isWithStandardMBean)
throw new Exception("Test error: StandardMBean mismatch");
// Check that order of attributes and operations matches
MBeanAttributeInfo[] mbais = mbi.getAttributes();
checkEqual(expectedAttributeNames.size(), mbais.length, "number of attributes");
List<String> attributeNames = new ArrayList<String>();
for (MBeanAttributeInfo mbai : mbais) attributeNames.add(mbai.getName());
checkEqual(expectedAttributeNames, attributeNames, "order of attributes");
MBeanOperationInfo[] mbois = mbi.getOperations();
checkEqual(expectedOperationNames.size(), mbois.length, "number of operations");
List<String> operationNames = new ArrayList<String>();
for (MBeanOperationInfo mboi : mbois) operationNames.add(mboi.getName());
checkEqual(expectedOperationNames, operationNames, "order of operations");
System.out.println();
}
}
if (failed)
throw new Exception("TEST FAILED");
System.out.println("TEST PASSED");
}
use of javax.management.MBeanOperationInfo in project jdk8u_jdk by JetBrains.
the class AnnotationTest method check.
private static void check(MBeanServer mbs, ObjectName on) throws Exception {
MBeanInfo mbi = mbs.getMBeanInfo(on);
// check the MBean itself
check(mbi);
// check attributes
MBeanAttributeInfo[] attrs = mbi.getAttributes();
for (MBeanAttributeInfo attr : attrs) {
check(attr);
if (attr.getName().equals("ReadOnly"))
check("@Full", attr.getDescriptor(), expectedFullDescriptor);
}
// check operations
MBeanOperationInfo[] ops = mbi.getOperations();
for (MBeanOperationInfo op : ops) {
check(op);
check(op.getSignature());
}
MBeanConstructorInfo[] constrs = mbi.getConstructors();
for (MBeanConstructorInfo constr : constrs) {
check(constr);
check(constr.getSignature());
}
}
use of javax.management.MBeanOperationInfo in project jdk8u_jdk by JetBrains.
the class MBeanInfoInteropTest method init.
private static void init() throws Exception {
mbai = new MBeanAttributeInfo("name", "type", "descr", true, false, false);
mbpi = new MBeanParameterInfo("name", "type", "descr");
MBeanParameterInfo[] params = new MBeanParameterInfo[] { mbpi };
mbci1 = new MBeanConstructorInfo("name", "descr", null);
mbci2 = new MBeanConstructorInfo("name", "descr", params);
mbni1 = new MBeanNotificationInfo(null, "name", "descr");
mbni2 = new MBeanNotificationInfo(new String[] { "type" }, "name", "descr");
mboi1 = new MBeanOperationInfo("name", "descr", null, "type", ACTION);
mboi2 = new MBeanOperationInfo("name", "descr", params, "type", INFO);
mbi1 = new MBeanInfo("class", "descr", null, null, null, null);
mbi2 = new MBeanInfo("class", "descr", new MBeanAttributeInfo[] { mbai }, new MBeanConstructorInfo[] { mbci1, mbci2 }, new MBeanOperationInfo[] { mboi1, mboi2 }, new MBeanNotificationInfo[] { mbni1, mbni2 });
ombai1 = new OpenMBeanAttributeInfoSupport("name", "descr", INTEGER, true, false, false);
ombai2 = new OpenMBeanAttributeInfoSupport("name", "descr", INTEGER, true, false, false, 5);
ombai3 = new OpenMBeanAttributeInfoSupport("name", "descr", INTEGER, true, false, false, 5, 1, 6);
ombai4 = new OpenMBeanAttributeInfoSupport("name", "descr", INTEGER, true, false, false, 5, new Integer[] { 2, 3, 5, 7 });
ombpi1 = new OpenMBeanParameterInfoSupport("name1", "descr", INTEGER);
ombpi2 = new OpenMBeanParameterInfoSupport("name2", "descr", INTEGER, 5);
ombpi3 = new OpenMBeanParameterInfoSupport("name3", "descr", INTEGER, 5, 1, 6);
ombpi4 = new OpenMBeanParameterInfoSupport("name4", "descr", INTEGER, 5, new Integer[] { 2, 3, 5, 7 });
OpenMBeanParameterInfo[] oparams = { ombpi1, ombpi2, ombpi3, ombpi4 };
ombci1 = new OpenMBeanConstructorInfoSupport("name", "descr", null);
ombci2 = new OpenMBeanConstructorInfoSupport("name", "descr", oparams);
omboi1 = new OpenMBeanOperationInfoSupport("name", "descr", null, INTEGER, ACTION);
omboi2 = new OpenMBeanOperationInfoSupport("name", "descr", oparams, INTEGER, ACTION);
ombi1 = new OpenMBeanInfoSupport("class", "descr", null, null, null, null);
ombi2 = new OpenMBeanInfoSupport("class", "descr", new OpenMBeanAttributeInfo[] { ombai1, ombai2, ombai3, ombai4 }, new OpenMBeanConstructorInfo[] { ombci1, ombci2 }, new OpenMBeanOperationInfo[] { omboi1, omboi2 }, new MBeanNotificationInfo[] { mbni1, mbni2 });
Descriptor attrd = new DescriptorSupport(new String[] { "name=name", "descriptorType=attribute" });
mmbai1 = new ModelMBeanAttributeInfo("name", "type", "descr", true, false, false);
mmbai2 = new ModelMBeanAttributeInfo("name", "type", "descr", true, false, false, attrd);
Descriptor constrd = new DescriptorSupport(new String[] { "name=name", "descriptorType=operation", "role=constructor" });
mmbci1 = new ModelMBeanConstructorInfo("name", "descr", null);
mmbci2 = new ModelMBeanConstructorInfo("name", "descr", null, constrd);
mmbci3 = new ModelMBeanConstructorInfo("name", "descr", params);
mmbci4 = new ModelMBeanConstructorInfo("name", "descr", params, constrd);
Descriptor operd = new DescriptorSupport(new String[] { "name=name", "descriptorType=operation" });
mmboi1 = new ModelMBeanOperationInfo("name", "descr", null, "type", ACTION);
mmboi2 = new ModelMBeanOperationInfo("name", "descr", null, "type", ACTION, operd);
mmboi3 = new ModelMBeanOperationInfo("name", "descr", params, "type", ACTION);
mmboi4 = new ModelMBeanOperationInfo("name", "descr", params, "type", ACTION, operd);
Descriptor notifd = new DescriptorSupport(new String[] { "name=name", "descriptorType=notification" });
mmbni1 = new ModelMBeanNotificationInfo(null, "name", "descr");
mmbni2 = new ModelMBeanNotificationInfo(null, "name", "descr", notifd);
mmbni3 = new ModelMBeanNotificationInfo(new String[] { "type" }, "name", "descr");
mmbni4 = new ModelMBeanNotificationInfo(new String[] { "type" }, "name", "descr", notifd);
Descriptor mbeand = new DescriptorSupport(new String[] { "name=name", "descriptorType=mbean" });
mmbi1 = new ModelMBeanInfoSupport("class", "descr", null, null, null, null);
mmbi2 = new ModelMBeanInfoSupport("class", "descr", null, null, null, null, mbeand);
mmbi3 = new ModelMBeanInfoSupport("class", "descr", new ModelMBeanAttributeInfo[] { mmbai1, mmbai2 }, new ModelMBeanConstructorInfo[] { mmbci1, mmbci2, mmbci3, mmbci4 }, new ModelMBeanOperationInfo[] { mmboi1, mmboi2, mmboi3, mmboi4 }, new ModelMBeanNotificationInfo[] { mmbni1, mmbni2, mmbni3, mmbni4 });
mmbi4 = new ModelMBeanInfoSupport("class", "descr", new ModelMBeanAttributeInfo[] { mmbai1, mmbai2 }, new ModelMBeanConstructorInfo[] { mmbci1, mmbci2, mmbci3, mmbci4 }, new ModelMBeanOperationInfo[] { mmboi1, mmboi2, mmboi3, mmboi4 }, new ModelMBeanNotificationInfo[] { mmbni1, mmbni2, mmbni3, mmbni4 }, mbeand);
objects = new Serializable[] { mbai, mbpi, mbci1, mbci2, mbni1, mbni2, mboi1, mboi2, mbi1, mbi2, ombai1, ombai2, ombai3, ombai4, ombpi1, ombpi2, ombpi3, ombpi4, ombci1, ombci2, omboi1, omboi2, ombi1, ombi2, mmbai1, mmbai2, mmbci1, mmbci2, mmbci3, mmbci4, mmboi1, mmboi2, mmboi3, mmboi4, mmbni1, mmbni2, mmbni3, mmbni4 };
}
use of javax.management.MBeanOperationInfo in project jdk8u_jdk by JetBrains.
the class MustBeValidCommand method main.
public static void main(String[] args) throws Exception {
// Instantiate the MBean server
//
final MBeanAttributeInfo[] atts = makeAttInfos(attributes);
final MBeanConstructorInfo[] ctors = makeCtorInfos(constructors);
final MBeanOperationInfo[] ops = makeOpInfos(operations);
final MBeanNotificationInfo[] notifs = makeNotifInfos(notificationclasses);
for (int i = 0; i < mbeanclasses.length; i++) {
System.out.println("Create an MBeanInfo: " + mbeanclasses[i][0]);
final MBeanInfo mbi = new MBeanInfo(mbeanclasses[i][1], mbeanclasses[i][0], atts, ctors, ops, notifs);
}
// Test OK!
//
System.out.println("All MBeanInfo successfuly created!");
System.out.println("Bye! Bye!");
}
Aggregations