use of javax.management.MBeanAttributeInfo in project wildfly by wildfly.
the class LogStoreProbeHandler method getMBeanValues.
private Map<String, String> getMBeanValues(MBeanServerConnection cnx, ObjectName on, String... attributeNames) throws InstanceNotFoundException, IOException, ReflectionException, IntrospectionException {
if (attributeNames == null) {
MBeanInfo info = cnx.getMBeanInfo(on);
MBeanAttributeInfo[] attributeArray = info.getAttributes();
int i = 0;
attributeNames = new String[attributeArray.length];
for (MBeanAttributeInfo ai : attributeArray) attributeNames[i++] = ai.getName();
}
AttributeList attributes = cnx.getAttributes(on, attributeNames);
Map<String, String> values = new HashMap<String, String>();
for (javax.management.Attribute attribute : attributes.asList()) {
Object value = attribute.getValue();
values.put(attribute.getName(), value == null ? "" : value.toString());
}
return values;
}
use of javax.management.MBeanAttributeInfo in project jdk8u_jdk by JetBrains.
the class RequiredModelMBean method removeAttributeChangeNotificationListener.
public void removeAttributeChangeNotificationListener(NotificationListener inlistener, String inAttributeName) throws MBeanException, RuntimeOperationsException, ListenerNotFoundException {
if (inlistener == null)
throw new ListenerNotFoundException("Notification listener is null");
final String mth = "removeAttributeChangeNotificationListener(" + "NotificationListener, String)";
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Entry");
}
if (attributeBroadcaster == null)
throw new ListenerNotFoundException("No attribute change notification listeners registered");
MBeanAttributeInfo[] attrInfo = modelMBeanInfo.getAttributes();
boolean found = false;
if ((attrInfo != null) && (attrInfo.length > 0)) {
for (int i = 0; i < attrInfo.length; i++) {
if (attrInfo[i].getName().equals(inAttributeName)) {
found = true;
break;
}
}
}
if ((!found) && (inAttributeName != null)) {
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid attribute name"), "Exception occurred trying to remove " + "attribute change notification listener");
}
/* note: */
/* this may be a problem if the same listener is registered for
multiple attributes with multiple filters and/or handback
objects. It may remove all of them */
attributeBroadcaster.removeNotificationListener(inlistener);
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Exit");
}
}
use of javax.management.MBeanAttributeInfo in project jdk8u_jdk by JetBrains.
the class RequiredModelMBean method addAttributeChangeNotificationListener.
public void addAttributeChangeNotificationListener(NotificationListener inlistener, String inAttributeName, Object inhandback) throws MBeanException, RuntimeOperationsException, IllegalArgumentException {
final String mth = "addAttributeChangeNotificationListener(" + "NotificationListener, String, Object)";
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Entry");
}
if (inlistener == null)
throw new IllegalArgumentException("Listener to be registered must not be null");
if (attributeBroadcaster == null)
attributeBroadcaster = new NotificationBroadcasterSupport();
AttributeChangeNotificationFilter currFilter = new AttributeChangeNotificationFilter();
MBeanAttributeInfo[] attrInfo = modelMBeanInfo.getAttributes();
boolean found = false;
if (inAttributeName == null) {
if ((attrInfo != null) && (attrInfo.length > 0)) {
for (int i = 0; i < attrInfo.length; i++) {
currFilter.enableAttribute(attrInfo[i].getName());
}
}
} else {
if ((attrInfo != null) && (attrInfo.length > 0)) {
for (int i = 0; i < attrInfo.length; i++) {
if (inAttributeName.equals(attrInfo[i].getName())) {
found = true;
currFilter.enableAttribute(inAttributeName);
break;
}
}
}
if (!found) {
throw new RuntimeOperationsException(new IllegalArgumentException("The attribute name does not exist"), "Exception occurred trying to add an " + "AttributeChangeNotification listener");
}
}
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
Vector<String> enabledAttrs = currFilter.getEnabledAttributes();
String s = (enabledAttrs.size() > 1) ? "[" + enabledAttrs.firstElement() + ", ...]" : enabledAttrs.toString();
MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Set attribute change filter to " + s);
}
attributeBroadcaster.addNotificationListener(inlistener, currFilter, inhandback);
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Notification listener added for " + inAttributeName);
MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Exit");
}
}
use of javax.management.MBeanAttributeInfo in project jdk8u_jdk by JetBrains.
the class MXBeanIntrospector method getMBeanAttributeInfo.
@Override
MBeanAttributeInfo getMBeanAttributeInfo(String attributeName, ConvertingMethod getter, ConvertingMethod setter) {
final boolean isReadable = (getter != null);
final boolean isWritable = (setter != null);
final boolean isIs = isReadable && getName(getter).startsWith("is");
final String description = attributeName;
final OpenType<?> openType;
final Type originalType;
if (isReadable) {
openType = getter.getOpenReturnType();
originalType = getter.getGenericReturnType();
} else {
openType = setter.getOpenParameterTypes()[0];
originalType = setter.getGenericParameterTypes()[0];
}
Descriptor descriptor = typeDescriptor(openType, originalType);
if (isReadable) {
descriptor = ImmutableDescriptor.union(descriptor, getter.getDescriptor());
}
if (isWritable) {
descriptor = ImmutableDescriptor.union(descriptor, setter.getDescriptor());
}
final MBeanAttributeInfo ai;
if (canUseOpenInfo(originalType)) {
ai = new OpenMBeanAttributeInfoSupport(attributeName, description, openType, isReadable, isWritable, isIs, descriptor);
} else {
ai = new MBeanAttributeInfo(attributeName, originalTypeString(originalType), description, isReadable, isWritable, isIs, descriptor);
}
return ai;
}
use of javax.management.MBeanAttributeInfo in project tomee by apache.
the class StatelessInvocationStatsTest method testInvocation.
/**
* @throws Exception
*/
public void testInvocation() throws Exception {
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", "0");
statelessContainerInfo.properties.setProperty("MaxSize", "2");
statelessContainerInfo.properties.setProperty("MinSize", "0");
statelessContainerInfo.properties.setProperty("StrictPooling", "true");
statelessContainerInfo.properties.setProperty("IdleTimeout", "0");
assembler.createContainer(statelessContainerInfo);
// Setup the descriptor information
CounterBean.instances.set(0);
final EjbJar ejbJar = new EjbJar("StatsInvocModule");
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
bean.waitSecs();
final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
final ObjectName invocationsName = new ObjectName("openejb.management:J2EEServer=openejb,J2EEApplication=<empty>,EJBModule=StatsInvocModule,StatelessSessionBean=CounterBean,j2eeType=Invocations,name=CounterBean");
// Grab the mbeanInfo and check the expected attributes exist and have the correct return types and parameters
final MBeanInfo invocationsMBeanInfo = server.getMBeanInfo(invocationsName);
for (final MBeanAttributeInfo info : invocationsMBeanInfo.getAttributes()) {
// System.out.println("//" + info.getName() + " " + server.getAttribute(invocationsName, info.getName()));
if (info.getName().equals("waitSecs().GeometricMean") || info.getName().equals("waitSecs().Max") || info.getName().equals("waitSecs().Mean") || info.getName().equals("waitSecs().Min") || info.getName().equals("waitSecs().Percentile01") || info.getName().equals("waitSecs().Percentile10") || info.getName().equals("waitSecs().Percentile25") || info.getName().equals("waitSecs().Percentile50") || info.getName().equals("waitSecs().Percentile75") || info.getName().equals("waitSecs().Percentile90") || info.getName().equals("waitSecs().Percentile99") || info.getName().equals("waitSecs().Sum")) {
final Double actual = (Double) (server.getAttribute(invocationsName, info.getName()));
assertTrue("Expected: " + actual + " >= 999", actual >= 999);
}
}
ejbJar.removeEnterpriseBean("StatsInvocModule");
}
Aggregations