use of javax.management.MBeanParameterInfo in project tomee by apache.
the class StatelessInvocationStatsTest method testBasic.
/**
* This whole method is a template, feel free to split it anyway you like
* Fine to have one big
*
* @throws Exception
*/
public void testBasic() throws Exception {
// some pre-load to avoid to load the class lazily with the first invocation
new CounterBean().red();
new CounterBean().blue();
new CounterBean().green();
// end preload
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, org.apache.openejb.core.LocalInitialContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
// containers
final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
statelessContainerInfo.properties.setProperty("AccessTimeout", "100");
statelessContainerInfo.properties.setProperty("MaxSize", "15");
statelessContainerInfo.properties.setProperty("MinSize", "3");
statelessContainerInfo.properties.setProperty("StrictPooling", "true");
assembler.createContainer(statelessContainerInfo);
// Setup the descriptor information
CounterBean.instances.set(0);
final EjbJar ejbJar = new EjbJar("StatsModule");
ejbJar.addEnterpriseBean(new StatelessBean(CounterBean.class));
assembler.createApplication(config.configureApplication(ejbJar));
final javax.naming.Context context = new InitialContext();
final CounterBean bean = (CounterBean) context.lookup("CounterBeanLocalBean");
// Invoke each method once
bean.red();
bean.green();
bean.blue();
final MBeanServer server = LocalMBeanServer.get();
final ObjectName invocationsName = new ObjectName("openejb.management:J2EEServer=openejb,J2EEApplication=<empty>,EJBModule=StatsModule,StatelessSessionBean=CounterBean,j2eeType=Invocations,name=CounterBean");
// Grab the mbeanInfo and check the expected attributes exist and have the correct return types and parameters
/*
* Invocation MBeanInfo
*
*/
final List<MBeanAttributeInfo> expectedAttributes = new ArrayList<MBeanAttributeInfo>();
expectedAttributes.add(new MBeanAttributeInfo("InvocationCount", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("InvocationTime", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("MonitoredMethods", "long", "", true, false, false));
final Map<String, Object> expectedValues = new TreeMap<String, Object>();
expectedValues.put("InvocationCount", (long) 6);
expectedValues.put("InvocationTime", (long) 0);
expectedValues.put("MonitoredMethods", (long) 4);
final String[] methods = { "PostConstruct()", "blue()", "green()", "red()" };
for (final String s : methods) {
expectedAttributes.add(new MBeanAttributeInfo(s + ".Count", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".GeometricMean", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".Kurtosis", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".Max", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".Mean", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".Min", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile01", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile10", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile25", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile50", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile75", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile90", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile99", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".SampleSize", "int", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".Skewness", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".StandardDeviation", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".Sum", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".Sumsq", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo(s + ".Variance", "double", "", true, false, false));
if (s.equals("PostConstruct()")) {
expectedValues.put(s + ".Count", (long) 3);
} else {
expectedValues.put(s + ".Count", (long) 1);
}
expectedValues.put(s + ".GeometricMean", 0.0);
expectedValues.put(s + ".Kurtosis", Double.NaN);
expectedValues.put(s + ".Max", 0.0);
expectedValues.put(s + ".Mean", 0.0);
expectedValues.put(s + ".Min", 0.0);
expectedValues.put(s + ".Percentile01", 0.0);
expectedValues.put(s + ".Percentile10", 0.0);
expectedValues.put(s + ".Percentile25", 0.0);
expectedValues.put(s + ".Percentile50", 0.0);
expectedValues.put(s + ".Percentile75", 0.0);
expectedValues.put(s + ".Percentile90", 0.0);
expectedValues.put(s + ".Percentile99", 0.0);
expectedValues.put(s + ".SampleSize", 2000);
expectedValues.put(s + ".Skewness", Double.NaN);
expectedValues.put(s + ".StandardDeviation", 0.0);
expectedValues.put(s + ".Sum", 0.0);
expectedValues.put(s + ".Sumsq", 0.0);
expectedValues.put(s + ".Variance", 0.0);
}
final List<MBeanAttributeInfo> actualAttributes = new ArrayList<MBeanAttributeInfo>();
final Map<String, Object> actualValues = new TreeMap<String, Object>();
final MBeanInfo beanInfo = server.getMBeanInfo(invocationsName);
for (final MBeanAttributeInfo info : beanInfo.getAttributes()) {
actualAttributes.add(info);
actualValues.put(info.getName(), server.getAttribute(invocationsName, info.getName()));
}
//Verify invocation attributes and values
assertEquals(expectedAttributes, actualAttributes);
boolean ok = true;
for (final Map.Entry<String, Object> entry : actualValues.entrySet()) {
final Number value = (Number) expectedValues.get(entry.getKey());
final Number real = (Number) actualValues.get(entry.getKey());
if (!value.equals(real)) {
// tolerating a 1 wide range
Logger.getLogger(StatelessInvocationStatsTest.class.getName()).log(Level.WARNING, "Test tolerance: " + entry.getKey() + " => " + entry.getValue() + "/" + expectedValues.get(entry.getKey()));
final Double abs = Math.abs(real.doubleValue() - value.doubleValue());
if (abs.intValue() > 1) {
ok = false;
}
}
}
// assertEquals(expectedValues, actualValues);
assertTrue(ok);
// Grab invocation mbean operations
final MBeanParameterInfo[] invocationParameters1 = { new MBeanParameterInfo("excludeRegex", "java.lang.String", "\"\""), new MBeanParameterInfo("includeRegex", "java.lang.String", "\"\"") };
final MBeanParameterInfo[] invocationParameters2 = { new MBeanParameterInfo("p1", "int", "") };
final List<MBeanOperationInfo> expectedOperations = new ArrayList<MBeanOperationInfo>();
expectedOperations.add(new MBeanOperationInfo("FilterAttributes", "Filters the attributes that show up in the MBeanInfo. The exclude is applied first, then any attributes that match the include are re-added. It may be required to disconnect and reconnect the JMX console to force a refresh of the MBeanInfo", invocationParameters1, "void", MBeanOperationInfo.UNKNOWN));
for (final String s : methods) {
expectedOperations.add(new MBeanOperationInfo(s + ".setSampleSize", "", invocationParameters2, "void", MBeanOperationInfo.UNKNOWN));
expectedOperations.add(new MBeanOperationInfo(s + ".sortedValues", "", new MBeanParameterInfo[0], "[D", MBeanOperationInfo.UNKNOWN));
expectedOperations.add(new MBeanOperationInfo(s + ".values", "", new MBeanParameterInfo[0], "[D", MBeanOperationInfo.UNKNOWN));
}
final List<MBeanOperationInfo> actualOperations1 = new ArrayList<MBeanOperationInfo>();
actualOperations1.addAll(Arrays.asList(beanInfo.getOperations()));
//Verify invocation operation information and remove bean.
assertEquals(expectedOperations, actualOperations1);
}
use of javax.management.MBeanParameterInfo in project tomee by apache.
the class StatelessPoolStatsTest method testBasic.
/**
* @throws Exception On error
*/
public void testBasic() throws Exception {
final Properties properties = new Properties();
properties.setProperty("AccessTimeout", "100");
properties.setProperty("MaxSize", "15");
properties.setProperty("SweepInterval", "10 ms");
properties.setProperty("MinSize", "3");
properties.setProperty("StrictPooling", "true");
deploy("testBasic", properties);
// Grab the mbeanInfo and check the expected attributes exist and have the correct return types and parameters
final MBeanInfo poolMBeanInfo = server.getMBeanInfo(objectName);
/*
* Pool MBeanInfo
*
*/
final List<MBeanAttributeInfo> expectedAttributes = new ArrayList<MBeanAttributeInfo>();
expectedAttributes.add(new MBeanAttributeInfo("AccessTimeouts", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("AccessTimeouts.Latest", "java.lang.String", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("AccessTimeouts.LatestTime", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Aged", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Aged.Latest", "java.lang.String", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Aged.LatestTime", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("AvailablePermits", "int", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Flushed", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Flushed.Latest", "java.lang.String", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Flushed.LatestTime", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Flushes", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Flushes.Latest", "java.lang.String", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Flushes.LatestTime", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("GarbageCollected", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("GarbageCollected.Latest", "java.lang.String", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("GarbageCollected.LatestTime", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("GarbageCollection", "boolean", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("IdleTimeout", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("IdleTimeouts", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("IdleTimeouts.Latest", "java.lang.String", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("IdleTimeouts.LatestTime", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("InstancesActive", "int", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("InstancesIdle", "int", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("InstancesInitializing", "int", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("InstancesPooled", "int", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("MaxAge", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("MaxAgeOffset", "double", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("MaxSize", "int", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("MinSize", "int", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("MinimumInstances", "int", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Overdrafts", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Overdrafts.Latest", "java.lang.String", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Overdrafts.LatestTime", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("PoolVersion", "int", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("ReplaceAged", "boolean", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("ReplaceFlushed", "boolean", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Replaced", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Replaced.Latest", "java.lang.String", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Replaced.LatestTime", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("StrictPooling", "boolean", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("SweepInterval", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Sweeps", "long", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Sweeps.Latest", "java.lang.String", "", true, false, false));
expectedAttributes.add(new MBeanAttributeInfo("Sweeps.LatestTime", "long", "", true, false, false));
// The hardest part, check the values of each, PoolVersion is AtomicaInteger, *.Latest are time-sensitive, so not verified.
final Map<String, Object> expectedAttributesValue = new TreeMap<String, Object>();
expectedAttributesValue.put("AccessTimeouts", (long) 0);
expectedAttributesValue.put("Aged", (long) 0);
expectedAttributesValue.put("AvailablePermits", 15);
expectedAttributesValue.put("Flushed", (long) 0);
expectedAttributesValue.put("Flushes", (long) 0);
expectedAttributesValue.put("GarbageCollected", (long) 0);
expectedAttributesValue.put("GarbageCollection", false);
expectedAttributesValue.put("IdleTimeout", (long) 0);
expectedAttributesValue.put("IdleTimeouts", (long) 0);
expectedAttributesValue.put("InstancesPooled", 3);
expectedAttributesValue.put("InstancesActive", 0);
expectedAttributesValue.put("InstancesIdle", 3);
expectedAttributesValue.put("InstancesInitializing", 0);
expectedAttributesValue.put("MaxAge", (long) 0);
expectedAttributesValue.put("MaxAgeOffset", -1.0);
expectedAttributesValue.put("MaxSize", 15);
expectedAttributesValue.put("MinSize", 3);
expectedAttributesValue.put("MinimumInstances", 3);
expectedAttributesValue.put("Overdrafts", (long) 0);
expectedAttributesValue.put("PoolVersion", 0);
expectedAttributesValue.put("ReplaceAged", true);
expectedAttributesValue.put("ReplaceFlushed", false);
expectedAttributesValue.put("Replaced", (long) 0);
expectedAttributesValue.put("SweepInterval", (long) 10);
// expectedAttributesValue.put("Sweeps", (long) 1);
expectedAttributesValue.put("StrictPooling", true);
final List<MBeanAttributeInfo> actualAttributes = new ArrayList<MBeanAttributeInfo>();
final Map<String, Object> actualAttributesValue = new TreeMap<String, Object>();
for (final MBeanAttributeInfo info : poolMBeanInfo.getAttributes()) {
actualAttributes.add(info);
if (!info.getName().endsWith(".Latest") && !info.getName().endsWith(".LatestTime") && !info.getName().equals("Sweeps")) {
actualAttributesValue.put(info.getName(), server.getAttribute(objectName, info.getName()));
}
}
assertEquals(expectedAttributes, actualAttributes);
assertEquals(expectedAttributesValue, actualAttributesValue);
// Grab pool mbean operations
final MBeanParameterInfo[] operations = { new MBeanParameterInfo("excludeRegex", "java.lang.String", "\"\""), new MBeanParameterInfo("includeRegex", "java.lang.String", "\"\"") };
final List<MBeanOperationInfo> expectedOperations = new ArrayList<MBeanOperationInfo>();
expectedOperations.add(new MBeanOperationInfo("FilterAttributes", "Filters the attributes that show up in the MBeanInfo. The exclude is applied first, then any attributes that match the include are re-added. It may be required to disconnect and reconnect the JMX console to force a refresh of the MBeanInfo", operations, "void", MBeanOperationInfo.UNKNOWN));
expectedOperations.add(new MBeanOperationInfo("flush", "", new MBeanParameterInfo[0], "void", MBeanOperationInfo.UNKNOWN));
final List<MBeanOperationInfo> actualOperations = new ArrayList<MBeanOperationInfo>();
actualOperations.addAll(Arrays.asList(poolMBeanInfo.getOperations()));
assertEquals(expectedOperations, actualOperations);
}
use of javax.management.MBeanParameterInfo in project tomcat by apache.
the class JMXProxyServlet method invokeOperationInternal.
/**
* 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);
}
use of javax.management.MBeanParameterInfo in project jetty.project by eclipse.
the class ObjectMBean method defineOperation.
/* ------------------------------------------------------------ */
/**
* TODO update to new behavior
*
* Define an operation on the managed object. Defines an operation with parameters. Refection is
* used to determine find the method and it's return type. The description of the method is
* found with a call to findDescription on "name(signature)". The name and description of each
* parameter is found with a call to findDescription with "name(signature)[n]", the returned
* description is for the last parameter of the partial signature and is assumed to start with
* the parameter name, followed by a colon.
*
* @param metaData "description" or "impact:description" or "type:impact:description", type is
* the "Object","MBean", "MMBean" or "MObject" to indicate the method is on the object, the MBean or on the
* object but converted to an MBean reference, and impact is either "ACTION","INFO","ACTION_INFO" or "UNKNOWN".
*/
private MBeanOperationInfo defineOperation(Method method, ManagedOperation methodAnnotation) {
String description = methodAnnotation.value();
boolean onMBean = methodAnnotation.proxied();
boolean convert = false;
// determine if we should convert
Class<?> returnType = method.getReturnType();
if (returnType.isArray()) {
if (LOG.isDebugEnabled())
LOG.debug("returnType is array, get component type");
returnType = returnType.getComponentType();
}
if (returnType.isAnnotationPresent(ManagedObject.class)) {
convert = true;
}
String impactName = methodAnnotation.impact();
if (LOG.isDebugEnabled())
LOG.debug("defineOperation {} {}:{}:{}", method.getName(), onMBean, impactName, description);
String signature = method.getName();
try {
// Resolve the impact
int impact = MBeanOperationInfo.UNKNOWN;
if (impactName == null || impactName.equals("UNKNOWN"))
impact = MBeanOperationInfo.UNKNOWN;
else if (impactName.equals("ACTION"))
impact = MBeanOperationInfo.ACTION;
else if (impactName.equals("INFO"))
impact = MBeanOperationInfo.INFO;
else if (impactName.equals("ACTION_INFO"))
impact = MBeanOperationInfo.ACTION_INFO;
else
LOG.warn("Unknown impact '" + impactName + "' for " + signature);
Annotation[][] allParameterAnnotations = method.getParameterAnnotations();
Class<?>[] methodTypes = method.getParameterTypes();
MBeanParameterInfo[] pInfo = new MBeanParameterInfo[allParameterAnnotations.length];
for (int i = 0; i < allParameterAnnotations.length; ++i) {
Annotation[] parameterAnnotations = allParameterAnnotations[i];
for (Annotation anno : parameterAnnotations) {
if (anno instanceof Name) {
Name nameAnnotation = (Name) anno;
pInfo[i] = new MBeanParameterInfo(nameAnnotation.value(), methodTypes[i].getName(), nameAnnotation.description());
}
}
}
signature += "(";
for (int i = 0; i < methodTypes.length; ++i) {
signature += methodTypes[i].getName();
if (i != methodTypes.length - 1) {
signature += ",";
}
}
signature += ")";
Class<?> returnClass = method.getReturnType();
if (LOG.isDebugEnabled())
LOG.debug("Method Cache: " + signature);
if (_methods.containsKey(signature)) {
// we have an operation for this already
return null;
}
_methods.put(signature, method);
if (convert)
_convert.add(signature);
return new MBeanOperationInfo(method.getName(), description, pInfo, returnClass.isPrimitive() ? TypeUtil.toName(returnClass) : (returnClass.getName()), impact);
} catch (Exception e) {
LOG.warn("Operation '" + signature + "'", e);
throw new IllegalArgumentException(e.toString());
}
}
use of javax.management.MBeanParameterInfo in project jetty.project by eclipse.
the class ObjectMBeanTest method testDerivedOperations.
@Test
public void testDerivedOperations() throws Exception {
Derived derived = new Derived();
ObjectMBean mbean = (ObjectMBean) ObjectMBean.mbeanFor(derived);
mbean.setMBeanContainer(container);
container.beanAdded(null, derived);
MBeanInfo info = mbean.getMBeanInfo();
Assert.assertEquals("operation count does not match", 5, info.getOperations().length);
MBeanOperationInfo[] opinfos = info.getOperations();
boolean publish = false;
boolean doodle = false;
boolean good = false;
for (int i = 0; i < opinfos.length; ++i) {
MBeanOperationInfo opinfo = opinfos[i];
if ("publish".equals(opinfo.getName())) {
publish = true;
Assert.assertEquals("description doesn't match", "publish something", opinfo.getDescription());
}
if ("doodle".equals(opinfo.getName())) {
doodle = true;
Assert.assertEquals("description doesn't match", "Doodle something", opinfo.getDescription());
MBeanParameterInfo[] pinfos = opinfo.getSignature();
Assert.assertEquals("parameter description doesn't match", "A description of the argument", pinfos[0].getDescription());
Assert.assertEquals("parameter name doesn't match", "doodle", pinfos[0].getName());
}
// This is a proxied operation on the JMX wrapper
if ("good".equals(opinfo.getName())) {
good = true;
Assert.assertEquals("description does not match", "test of proxy operations", opinfo.getDescription());
Assert.assertEquals("execution contexts wrong", "not bad", mbean.invoke("good", new Object[] {}, new String[] {}));
}
}
Assert.assertTrue("publish operation was not not found", publish);
Assert.assertTrue("doodle operation was not not found", doodle);
Assert.assertTrue("good operation was not not found", good);
}
Aggregations