use of javax.management.AttributeNotFoundException in project ddf by codice.
the class RrdJmxCollector method updateSamples.
/**
* Configures a scheduled threaded executor to poll the metric's MBean periodically and add a
* sample to the RRD file with the metric's current value.
*
* @throws CollectorException
*/
public void updateSamples() throws CollectorException {
LOGGER.trace("ENTERING: updateSamples");
if (executor == null) {
executor = new ScheduledThreadPoolExecutor(1);
}
final Runnable updater = new Runnable() {
public void run() {
Object attr = null;
try {
attr = localMBeanServer.getAttribute(new ObjectName(mbeanName), mbeanAttributeName);
LOGGER.trace("Sampling attribute {} from MBean {}", mbeanAttributeName, mbeanName);
// Cast the metric's sampled value to the appropriate data type
double val = 0;
if (attr instanceof Integer) {
val = (Integer) attr;
} else if (attr instanceof Long) {
val = ((Long) attr).intValue();
} else if (attr instanceof Float) {
val = ((Float) attr);
} else if (attr instanceof Double) {
val = ((Double) attr);
} else {
throw new IllegalArgumentException("Unsupported type " + attr + " for attribute " + mbeanAttributeName);
}
LOGGER.trace("MBean attribute {} has value = {}", mbeanAttributeName, val);
// sample in the RRD file
if (sample == null) {
sample = rrdDb.createSample();
}
try {
long now = System.currentTimeMillis() / MILLIS_PER_SECOND;
long lastUpdateTime = rrdDb.getLastUpdateTime();
// Add metric's sample to RRD file with current timestamp
if (now - rrdDb.getLastUpdateTime() >= minimumUpdateTimeDelta) {
updateSample(now, val);
} else {
LOGGER.debug("Skipping sample update because time between updates is less than {} seconds", minimumUpdateTimeDelta);
sampleSkipCount++;
LOGGER.debug("now = {}, lastUpdateTime = {} (sampleSkipCount = {})", now, lastUpdateTime, sampleSkipCount);
}
} catch (IllegalArgumentException iae) {
LOGGER.info("Dropping sample of datasource {}", rrdDataSourceName, iae);
}
} catch (MalformedObjectNameException | AttributeNotFoundException | InstanceNotFoundException | MBeanException | ReflectionException e) {
LOGGER.info("Problems getting MBean attribute {}", mbeanAttributeName, e);
} catch (IOException e) {
LOGGER.info("Error updating RRD", e);
}
}
};
// Setup threaded scheduler to retrieve this MBean attribute's value
// at the specified sample rate
LOGGER.debug("Setup ScheduledThreadPoolExecutor for MBean {}", mbeanName);
executor.scheduleWithFixedDelay(updater, 0, sampleRate, TimeUnit.SECONDS);
LOGGER.trace("EXITING: updateSamples");
}
use of javax.management.AttributeNotFoundException in project felix by apache.
the class AbstractDynamicMBean method setAttributes.
/**
* Sets the manageable attributes, as specified by the DynamicMBean interface.
*/
public AttributeList setAttributes(AttributeList attributes) {
AttributeList list = new AttributeList();
if (attributes != null) {
for (int i = 0; i < attributes.size(); ++i) {
Attribute attribute = (Attribute) attributes.get(i);
try {
setAttribute(attribute);
list.add(attribute);
} catch (AttributeNotFoundException ignored) {
} catch (InvalidAttributeValueException ignored) {
} catch (MBeanException ignored) {
} catch (ReflectionException ignored) {
}
}
}
return list;
}
use of javax.management.AttributeNotFoundException in project felix by apache.
the class AbstractDynamicMBean method getAttributes.
/**
* Returns the manageable attributes, as specified by the DynamicMBean interface.
*/
public AttributeList getAttributes(String[] attributes) {
AttributeList list = new AttributeList();
if (attributes != null) {
for (int i = 0; i < attributes.length; ++i) {
String attribute = attributes[i];
try {
Object result = getAttribute(attribute);
list.add(new Attribute(attribute, result));
} catch (AttributeNotFoundException ignored) {
} catch (MBeanException ignored) {
} catch (ReflectionException ignored) {
}
}
}
return list;
}
use of javax.management.AttributeNotFoundException in project felix by apache.
the class AbstractDynamicMBean method getAttribute.
/**
* Returns the value of the manageable attribute, as specified by the DynamicMBean interface.
* @see #createMBeanAttributeInfo
*/
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
if (attribute == null)
throw new AttributeNotFoundException("Attribute " + attribute + " not found");
Object resource = null;
MBeanInfo info = null;
synchronized (this) {
resource = getResourceOrThis();
info = getMBeanInfo();
}
MBeanAttributeInfo[] attrs = info.getAttributes();
if (attrs == null || attrs.length == 0)
throw new AttributeNotFoundException("No attributes defined for this MBean");
for (int i = 0; i < attrs.length; ++i) {
MBeanAttributeInfo attr = attrs[i];
if (attr == null)
continue;
if (attribute.equals(attr.getName())) {
if (!attr.isReadable())
throw new ReflectionException(new NoSuchMethodException("No getter defined for attribute: " + attribute));
// Found, invoke via reflection
String prefix = null;
if (attr.isIs())
prefix = "is";
else
prefix = "get";
try {
return invoke(resource, prefix + attr.getName(), new Class[0], new Object[0]);
} catch (InvalidAttributeValueException x) {
throw new ReflectionException(x);
}
}
}
throw new AttributeNotFoundException("Attribute " + attribute + " not found");
}
use of javax.management.AttributeNotFoundException in project Payara by payara.
the class AMXTest method testGetInterfaceName.
public void testGetInterfaceName() throws IOException, JMException {
final Set<ObjectName> all = getQueryMgr().queryAllObjectNameSet();
final MBeanServerConnection conn = Util.getExtra(getDomainRoot()).getConnectionSource().getExistingMBeanServerConnection();
final Set<ObjectName> failedSet = new HashSet<ObjectName>();
for (final ObjectName objectName : all) {
try {
final String value = (String) conn.getAttribute(objectName, AMXAttributes.ATTR_INTERFACE_NAME);
assert (value != null);
value.toString();
} catch (AttributeNotFoundException e) {
warning("Can't get InterfaceName for: " + objectName);
failedSet.add(objectName);
}
}
if (failedSet.size() != 0) {
warning("The following MBeans did not return the Attribute InterfaceName:\n" + CollectionUtil.toString(failedSet, "\n"));
assert (false);
throw new Error();
}
}
Aggregations