use of javax.management.AttributeNotFoundException in project jackrabbit-oak by apache.
the class HybridIndexTest method getOpenFileCount.
private static long getOpenFileCount() throws Exception {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("java.lang:type=OperatingSystem");
Long val = null;
try {
val = (Long) server.getAttribute(name, "OpenFileDescriptorCount");
} catch (AttributeNotFoundException e) {
// This attribute is only present if the os is unix i.e. when UnixOperatingSystemMXBean
// is the mbean in use. If running on windows the test would be assumed to be true
assumeNoException(e);
}
// dumpOpenFilePaths();
return val;
}
use of javax.management.AttributeNotFoundException in project com.revolsys.open by revolsys.
the class JmxService method getAttribute.
/**
* Get the value for the attribute for an object on a server.
*
* @param mapWriter The writer to write the attributes to.
* @param serverId The name of the server.
* @param objectId The name of the object.
* @param attributeId The name of the attribute.
* @return The attribute value.
*/
public Object getAttribute(final String serverId, final String objectId, final String attributeId) {
if (hasAttribute(serverId, objectId, attributeId)) {
final MBeanServerConnection connection = getConnection(serverId);
try {
final ObjectName objectName = getObjectName(serverId, objectId);
final Object object = connection.getAttribute(objectName, attributeId);
return object;
} catch (final InstanceNotFoundException e) {
return "Unavailable";
} catch (final MalformedObjectNameException e) {
throw new IllegalArgumentException("MBean name not valid " + serverId + " " + objectId);
} catch (final AttributeNotFoundException e) {
throw new IllegalArgumentException("MBean attribute not found " + serverId + " " + objectId + "." + attributeId);
} catch (final Throwable e) {
return Exceptions.throwUncheckedException(e);
}
} else {
throw new IllegalArgumentException("Attribute not configured " + serverId + " " + objectId + "." + attributeId);
}
}
use of javax.management.AttributeNotFoundException in project jmeter-plugins by undera.
the class JMXMonSampler method generateSamples.
public void generateSamples(JMXMonSampleGenerator collector) {
try {
if (hasFailed && !canRetry) {
return;
}
// Construct the fully qualified name of the bean.
ObjectName beanName = new ObjectName(objectName);
MBeanServerConnection activeRemote = null;
if (remote == null) {
activeRemote = pool.getConnection(url.getStringValue(), connectionAttributes);
if (activeRemote == null) {
hasFailed = true;
}
} else {
activeRemote = remote;
}
final double val;
if (activeRemote != null) {
Object o = activeRemote.getAttribute(beanName, attribute);
if (o instanceof CompositeDataSupport) {
if (key == null || "".equals(key)) {
log.error("Got composite object from JMX, but no key specified ");
return;
}
CompositeDataSupport cds = (CompositeDataSupport) o;
// log.info("CDS: " + cds.toString());
val = Double.parseDouble(cds.get(key).toString());
} else {
if (key != null && !key.equals("")) {
log.error("key specified, but didnt get composite object from JMX. Will continue anyway.");
}
val = Double.parseDouble(o.toString());
}
} else {
val = 0;
}
if (sampleDeltaValue) {
if (!Double.isNaN(oldValue)) {
collector.generateSample(val - oldValue, metricName);
}
oldValue = val;
} else {
collector.generateSample(val, metricName);
}
} catch (MalformedURLException ex) {
log.error(ex.getMessage());
} catch (ConnectException ex) {
log.warn("Connection lost", ex);
pool.notifyConnectionDirty(url.getStringValue());
if (sampleDeltaValue) {
if (!Double.isNaN(oldValue)) {
collector.generateSample(0 - oldValue, metricName);
}
oldValue = 0;
} else {
collector.generateSample(0, metricName);
}
} catch (IOException ex) {
log.error(ex.getMessage());
} catch (ReflectionException ex) {
log.error(ex.getMessage());
} catch (MalformedObjectNameException ex) {
log.error(ex.getMessage());
} catch (NullPointerException ex) {
log.error(ex.getMessage());
} catch (MBeanException ex) {
log.error(ex.getMessage());
} catch (AttributeNotFoundException ex) {
log.error(ex.getMessage());
} catch (InstanceNotFoundException ex) {
log.error(ex.getMessage());
}
}
use of javax.management.AttributeNotFoundException in project jspwiki by apache.
the class SimpleMBean method setAttribute.
public void setAttribute(Attribute attr) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
Method m;
String mname = "set" + StringUtils.capitalize(attr.getName());
m = findGetterSetter(getClass(), mname, attr.getValue().getClass());
if (m == null)
throw new AttributeNotFoundException(attr.getName());
Object[] args = { attr.getValue() };
try {
m.invoke(this, args);
} catch (IllegalArgumentException e) {
throw new InvalidAttributeValueException("Faulty argument: " + e.getMessage());
} catch (IllegalAccessException e) {
throw new ReflectionException(e, "Cannot access attribute " + e.getMessage());
} catch (InvocationTargetException e) {
throw new ReflectionException(e, "Cannot invoke attribute " + e.getMessage());
}
}
use of javax.management.AttributeNotFoundException in project jspwiki by apache.
the class SimpleMBean method setAttributes.
public AttributeList setAttributes(AttributeList arg0) {
AttributeList result = new AttributeList();
for (Iterator<Object> i = arg0.iterator(); i.hasNext(); ) {
Attribute attr = (Attribute) i.next();
//
try {
setAttribute(attr);
result.add(attr);
} catch (AttributeNotFoundException e) {
// TODO Auto-generated catch block
LOG.error(e.getMessage(), e);
} catch (InvalidAttributeValueException e) {
// TODO Auto-generated catch block
LOG.error(e.getMessage(), e);
} catch (MBeanException e) {
// TODO Auto-generated catch block
LOG.error(e.getMessage(), e);
} catch (ReflectionException e) {
// TODO Auto-generated catch block
LOG.error(e.getMessage(), e);
}
}
return result;
}
Aggregations