private void processAttribute(MBeanServer server,
Node descN, String objectName ) {
String attName=DomUtil.getAttribute(descN, "name");
String value=DomUtil.getAttribute(descN, "value");
String type=null; // DomUtil.getAttribute(descN, "type");
if( value==null ) {
// The value may be specified as CDATA
value=DomUtil.getContent(descN);
}
try {
if( log.isDebugEnabled())
log.debug("Set attribute " + objectName + " " + attName +
" " + value);
ObjectName oname=new ObjectName(objectName);
// find the type
type=registry.getType( oname, attName );
if( type==null ) {
log.info("Can't find attribute " + objectName + " " + attName );
} else {
Object valueO=registry.convertValue( type, value);
server.setAttribute(oname, new Attribute(attName, valueO));
}
} catch( Exception ex) {
log.error("Error processing attribute " + objectName + " " +
attName + " " + value, ex);
}
}
java类javax.management.Attribute的实例源码
MbeansSource.java 文件源码
项目:tomcat7
阅读 27
收藏 0
点赞 0
评论 0
MergeEditConfigStrategy.java 文件源码
项目:hashsdn-controller
阅读 21
收藏 0
点赞 0
评论 0
@Override
@SuppressWarnings("IllegalCatch")
void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on,
ServiceRegistryWrapper services) throws ConfigHandlingException {
for (Entry<String, AttributeConfigElement> configAttributeEntry : configuration.entrySet()) {
try {
AttributeConfigElement ace = configAttributeEntry.getValue();
if (!ace.getResolvedValue().isPresent()) {
LOG.debug("Skipping attribute {} for {}", configAttributeEntry.getKey(), on);
continue;
}
Object toBeMergedIn = ace.getResolvedValue().get();
// Get the existing values so we can merge the new values with them.
Attribute currentAttribute = ta.getAttribute(on, ace.getJmxName());
Object oldValue = currentAttribute != null ? currentAttribute.getValue() : null;
// Merge value with currentValue
toBeMergedIn = merge(oldValue, toBeMergedIn);
ta.setAttribute(on, ace.getJmxName(), new Attribute(ace.getJmxName(), toBeMergedIn));
LOG.debug("Attribute {} set to {} for {}", configAttributeEntry.getKey(), toBeMergedIn, on);
} catch (RuntimeException e) {
LOG.error("Error while merging object names of {}", on, e);
throw new ConfigHandlingException(String.format("Unable to set attributes for %s, "
+ "Error with attribute %s : %s ",
on,
configAttributeEntry.getKey(),
configAttributeEntry.getValue()),
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.OPERATION_FAILED,
DocumentedException.ErrorSeverity.ERROR);
}
}
}
JMXPollUtil.java 文件源码
项目:flume-release-1.7.0
阅读 23
收藏 0
点赞 0
评论 0
public static Map<String, Map<String, String>> getAllMBeans() {
Map<String, Map<String, String>> mbeanMap = Maps.newHashMap();
Set<ObjectInstance> queryMBeans = null;
try {
queryMBeans = mbeanServer.queryMBeans(null, null);
} catch (Exception ex) {
LOG.error("Could not get Mbeans for monitoring", ex);
Throwables.propagate(ex);
}
for (ObjectInstance obj : queryMBeans) {
try {
if (!obj.getObjectName().toString().startsWith("org.apache.flume")) {
continue;
}
MBeanAttributeInfo[] attrs = mbeanServer.getMBeanInfo(obj.getObjectName()).getAttributes();
String[] strAtts = new String[attrs.length];
for (int i = 0; i < strAtts.length; i++) {
strAtts[i] = attrs[i].getName();
}
AttributeList attrList = mbeanServer.getAttributes(obj.getObjectName(), strAtts);
String component = obj.getObjectName().toString().substring(
obj.getObjectName().toString().indexOf('=') + 1);
Map<String, String> attrMap = Maps.newHashMap();
for (Object attr : attrList) {
Attribute localAttr = (Attribute) attr;
if (localAttr.getName().equalsIgnoreCase("type")) {
component = localAttr.getValue() + "." + component;
}
attrMap.put(localAttr.getName(), localAttr.getValue().toString());
}
mbeanMap.put(component, attrMap);
} catch (Exception e) {
LOG.error("Unable to poll JMX for metrics.", e);
}
}
return mbeanMap;
}
MBeanClientInterceptor.java 文件源码
项目:lams
阅读 35
收藏 0
点赞 0
评论 0
private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation)
throws JMException, IOException {
String attributeName = JmxUtils.getAttributeName(pd, this.useStrictCasing);
MBeanAttributeInfo inf = this.allowedAttributes.get(attributeName);
// If no attribute is returned, we know that it is not defined in the
// management interface.
if (inf == null) {
throw new InvalidInvocationException(
"Attribute '" + pd.getName() + "' is not exposed on the management interface");
}
if (invocation.getMethod().equals(pd.getReadMethod())) {
if (inf.isReadable()) {
return this.serverToUse.getAttribute(this.objectName, attributeName);
}
else {
throw new InvalidInvocationException("Attribute '" + attributeName + "' is not readable");
}
}
else if (invocation.getMethod().equals(pd.getWriteMethod())) {
if (inf.isWritable()) {
this.serverToUse.setAttribute(this.objectName, new Attribute(attributeName, invocation.getArguments()[0]));
return null;
}
else {
throw new InvalidInvocationException("Attribute '" + attributeName + "' is not writable");
}
}
else {
throw new IllegalStateException(
"Method [" + invocation.getMethod() + "] is neither a bean property getter nor a setter");
}
}
JMXProxyServlet.java 文件源码
项目:lams
阅读 28
收藏 0
点赞 0
评论 0
public void setAttribute( PrintWriter writer,
String onameStr, String att, String val )
{
try {
ObjectName oname=new ObjectName( onameStr );
String type=registry.getType(oname, att);
Object valueObj=registry.convertValue(type, val );
mBeanServer.setAttribute( oname, new Attribute(att, valueObj));
writer.println("OK - Attribute set");
} catch( Exception ex ) {
writer.println("Error - " + ex.toString());
}
}
MbeansSource.java 文件源码
项目:lazycat
阅读 22
收藏 0
点赞 0
评论 0
private void processAttribute(MBeanServer server, Node descN, String objectName) {
String attName = DomUtil.getAttribute(descN, "name");
String value = DomUtil.getAttribute(descN, "value");
String type = null; // DomUtil.getAttribute(descN, "type");
if (value == null) {
// The value may be specified as CDATA
value = DomUtil.getContent(descN);
}
try {
if (log.isDebugEnabled())
log.debug("Set attribute " + objectName + " " + attName + " " + value);
ObjectName oname = new ObjectName(objectName);
// find the type
type = registry.getType(oname, attName);
if (type == null) {
log.info("Can't find attribute " + objectName + " " + attName);
} else {
Object valueO = registry.convertValue(type, value);
server.setAttribute(oname, new Attribute(attName, valueO));
}
} catch (Exception ex) {
log.error("Error processing attribute " + objectName + " " + attName + " " + value, ex);
}
}
MbeansSource.java 文件源码
项目:lams
阅读 21
收藏 0
点赞 0
评论 0
private void processAttribute(MBeanServer server,
Node descN, String objectName ) {
String attName=DomUtil.getAttribute(descN, "name");
String value=DomUtil.getAttribute(descN, "value");
String type=null; // DomUtil.getAttribute(descN, "type");
if( value==null ) {
// The value may be specified as CDATA
value=DomUtil.getContent(descN);
}
try {
if( log.isDebugEnabled())
log.debug("Set attribute " + objectName + " " + attName +
" " + value);
ObjectName oname=new ObjectName(objectName);
// find the type
if( type==null )
type=registry.getType( oname, attName );
if( type==null ) {
log.info("Can't find attribute " + objectName + " " + attName );
} else {
Object valueO=registry.convertValue( type, value);
server.setAttribute(oname, new Attribute(attName, valueO));
}
} catch( Exception ex) {
log.error("Error processing attribute " + objectName + " " +
attName + " " + value, ex);
}
}
MBeanServerDelegateImpl.java 文件源码
项目:openjdk-jdk10
阅读 29
收藏 0
点赞 0
评论 0
/**
* Makes it possible to get the values of several attributes of
* the MBeanServerDelegate.
*
* @param attributes A list of the attributes to be retrieved.
*
* @return The list of attributes retrieved.
*
*/
public AttributeList getAttributes(String[] attributes) {
// If attributes is null, the get all attributes.
//
final String[] attn = (attributes==null?attributeNames:attributes);
// Prepare the result list.
//
final int len = attn.length;
final AttributeList list = new AttributeList(len);
// Get each requested attribute.
//
for (int i=0;i<len;i++) {
try {
final Attribute a =
new Attribute(attn[i],getAttribute(attn[i]));
list.add(a);
} catch (Exception x) {
// Skip the attribute that couldn't be obtained.
//
if (MBEANSERVER_LOGGER.isLoggable(Level.TRACE)) {
MBEANSERVER_LOGGER.log(Level.TRACE,
"Attribute " + attn[i] + " not found");
}
}
}
// Finally return the result.
//
return list;
}
MBeanServerDelegateImpl.java 文件源码
项目:OpenJSharp
阅读 38
收藏 0
点赞 0
评论 0
/**
* This method always fail since all MBeanServerDelegateMBean attributes
* are read-only.
*
* @param attribute The identification of the attribute to
* be set and the value it is to be set to.
*
* @exception AttributeNotFoundException
*/
public void setAttribute(Attribute attribute)
throws AttributeNotFoundException, InvalidAttributeValueException,
MBeanException, ReflectionException {
// Now we will always fail:
// Either because the attribute is null or because it is not
// accessible (or does not exist).
//
final String attname = (attribute==null?null:attribute.getName());
if (attname == null) {
final RuntimeException r =
new IllegalArgumentException("Attribute name cannot be null");
throw new RuntimeOperationsException(r,
"Exception occurred trying to invoke the setter on the MBean");
}
// This is a hack: we call getAttribute in order to generate an
// AttributeNotFoundException if the attribute does not exist.
//
Object val = getAttribute(attname);
// If we reach this point, we know that the requested attribute
// exists. However, since all attributes are read-only, we throw
// an AttributeNotFoundException.
//
throw new AttributeNotFoundException(attname + " not accessible");
}
MBeanServerDelegateImpl.java 文件源码
项目:OpenJSharp
阅读 32
收藏 0
点赞 0
评论 0
/**
* Makes it possible to get the values of several attributes of
* the MBeanServerDelegate.
*
* @param attributes A list of the attributes to be retrieved.
*
* @return The list of attributes retrieved.
*
*/
public AttributeList getAttributes(String[] attributes) {
// If attributes is null, the get all attributes.
//
final String[] attn = (attributes==null?attributeNames:attributes);
// Prepare the result list.
//
final int len = attn.length;
final AttributeList list = new AttributeList(len);
// Get each requested attribute.
//
for (int i=0;i<len;i++) {
try {
final Attribute a =
new Attribute(attn[i],getAttribute(attn[i]));
list.add(a);
} catch (Exception x) {
// Skip the attribute that couldn't be obtained.
//
if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
MBEANSERVER_LOGGER.logp(Level.FINEST,
MBeanServerDelegateImpl.class.getName(),
"getAttributes",
"Attribute " + attn[i] + " not found");
}
}
}
// Finally return the result.
//
return list;
}