本文整理匯總了Java中javax.management.MBeanInfo.getAttributes方法的典型用法代碼示例。如果您正苦於以下問題:Java MBeanInfo.getAttributes方法的具體用法?Java MBeanInfo.getAttributes怎麽用?Java MBeanInfo.getAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.management.MBeanInfo
的用法示例。
在下文中一共展示了MBeanInfo.getAttributes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fetchKafkaMetrics
import javax.management.MBeanInfo; //導入方法依賴的package包/類
private static void fetchKafkaMetrics(String host, String jmxPort, String metric)
throws Exception {
Map<String, String[]> env = new HashMap<>();
JMXServiceURL address = new JMXServiceURL(
"service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":" + jmxPort + "/jmxrmi");
JMXConnector connector = JMXConnectorFactory.connect(address, env);
MBeanServerConnection mbs = connector.getMBeanServerConnection();
ObjectName name = ObjectName.getInstance(metric);
MBeanInfo beanInfo = mbs.getMBeanInfo(name);
for (MBeanAttributeInfo attributeInfo : beanInfo.getAttributes()) {
Object obj = mbs.getAttribute(name, attributeInfo.getName());
System.out.println(" attributeName = " + attributeInfo.getName() + " " + obj.toString());
}
}
示例2: getType
import javax.management.MBeanInfo; //導入方法依賴的package包/類
/** Get the type of an attribute of the object, from the metadata.
*
* @param oname
* @param attName
* @return null if metadata about the attribute is not found
* @since 1.1
*/
public String getType( ObjectName oname, String attName )
{
String type=null;
MBeanInfo info=null;
try {
info=server.getMBeanInfo(oname);
} catch (Exception e) {
log.info( "Can't find metadata for object" + oname );
return null;
}
MBeanAttributeInfo attInfo[]=info.getAttributes();
for( int i=0; i<attInfo.length; i++ ) {
if( attName.equals(attInfo[i].getName())) {
type=attInfo[i].getType();
return type;
}
}
return null;
}
示例3: getMBeanInfo
import javax.management.MBeanInfo; //導入方法依賴的package包/類
/**
* Return the MBeanInfo for the given resource, based on the given
* per-interface data.
*/
final MBeanInfo getMBeanInfo(Object resource, PerInterface<M> perInterface) {
MBeanInfo mbi =
getClassMBeanInfo(resource.getClass(), perInterface);
MBeanNotificationInfo[] notifs = findNotifications(resource);
if (notifs == null || notifs.length == 0)
return mbi;
else {
return new MBeanInfo(mbi.getClassName(),
mbi.getDescription(),
mbi.getAttributes(),
mbi.getConstructors(),
mbi.getOperations(),
notifs,
mbi.getDescriptor());
}
}
示例4: printMBeanInfo
import javax.management.MBeanInfo; //導入方法依賴的package包/類
private void printMBeanInfo(MBeanInfo mbInfo) {
System.out.println("Description " + mbInfo.getDescription());
for (MBeanConstructorInfo ctor : mbInfo.getConstructors()) {
System.out.println("Constructor " + ctor.getName());
}
for (MBeanAttributeInfo att : mbInfo.getAttributes()) {
System.out.println("Attribute " + att.getName()
+ " [" + att.getType() + "]");
}
for (MBeanOperationInfo oper : mbInfo.getOperations()) {
System.out.println("Operation " + oper.getName());
}
for (MBeanNotificationInfo notif : mbInfo.getNotifications()) {
System.out.println("Notification " + notif.getName());
}
}
示例5: check
import javax.management.MBeanInfo; //導入方法依賴的package包/類
private static void check(MBeanServer mbs, ObjectName on) throws Exception {
MBeanInfo mbi = mbs.getMBeanInfo(on);
// check the MBean itself
check(mbi);
// check attributes
MBeanAttributeInfo[] attrs = mbi.getAttributes();
for (MBeanAttributeInfo attr : attrs) {
check(attr);
if (attr.getName().equals("ReadOnly"))
check("@Full", attr.getDescriptor(), expectedFullDescriptor);
}
// check operations
MBeanOperationInfo[] ops = mbi.getOperations();
for (MBeanOperationInfo op : ops) {
check(op);
check(op.getSignature());
}
MBeanConstructorInfo[] constrs = mbi.getConstructors();
for (MBeanConstructorInfo constr : constrs) {
check(constr);
check(constr.getSignature());
}
}
示例6: run
import javax.management.MBeanInfo; //導入方法依賴的package包/類
@Override
public void run() {
try {
// This will trigger updateJmxCache().
MBeanInfo info = sa.getMBeanInfo();
final String key = src.getKey();
for (MBeanAttributeInfo mBeanAttributeInfo : info.getAttributes()) {
// Found the new key, update the metric source and move on.
if (mBeanAttributeInfo.getName().equals(key)) {
LOG.info("found key/val=" + cnt + "/" + cnt);
cnt++;
src.setKV("key" + cnt, cnt);
return;
}
}
LOG.error("key=" + key + " not found. Stopping now.");
hasError.set(true);
} catch (Exception e) {
// catch other errors
hasError.set(true);
LOG.error(e.getStackTrace());
} finally {
if (hasError.get()) {
future.cancel(false);
}
}
}
示例7: getMBeanAttributeType
import javax.management.MBeanInfo; //導入方法依賴的package包/類
/**
* Get MBean Attriute from Mbean Server
* @param jmxServerConnection
* @param name
* @param attribute
* @return The type
* @throws Exception
*/
protected String getMBeanAttributeType(
MBeanServerConnection jmxServerConnection,
String name,
String attribute) throws Exception {
ObjectName oname = new ObjectName(name);
String mattrType = null;
MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
MBeanAttributeInfo attrs[] = minfo.getAttributes();
if (attrs != null) {
for (int i = 0; mattrType == null && i < attrs.length; i++) {
if (attribute.equals(attrs[i].getName()))
mattrType = attrs[i].getType();
}
}
return mattrType;
}
示例8: printAttrs
import javax.management.MBeanInfo; //導入方法依賴的package包/類
private static void printAttrs(
MBeanServerConnection mbsc1, Class<? extends Exception> expectX)
throws Exception {
Set<ObjectName> names = mbsc1.queryNames(null, null);
for (ObjectName name : names) {
System.out.println(name + ":");
MBeanInfo mbi = mbsc1.getMBeanInfo(name);
MBeanAttributeInfo[] mbais = mbi.getAttributes();
for (MBeanAttributeInfo mbai : mbais) {
String attr = mbai.getName();
Object value;
try {
value = mbsc1.getAttribute(name, attr);
} catch (Exception e) {
if (expectX != null && expectX.isInstance(e))
value = "<" + e + ">";
else
throw e;
}
String s = " " + attr + " = " + value;
if (s.length() > 80)
s = s.substring(0, 77) + "...";
System.out.println(s);
}
}
}
示例9: getMBeanInfo
import javax.management.MBeanInfo; //導入方法依賴的package包/類
@Override
public MBeanInfo getMBeanInfo() {
MBeanInfo mbi = super.getMBeanInfo();
Class<?> resourceClass = getResource().getClass();
if (StandardMBeanIntrospector.isDefinitelyImmutableInfo(resourceClass))
return mbi;
return new MBeanInfo(mbi.getClassName(), mbi.getDescription(),
mbi.getAttributes(), mbi.getConstructors(),
mbi.getOperations(),
MBeanIntrospector.findNotifications(getResource()),
mbi.getDescriptor());
}
示例10: getOperationContext
import javax.management.MBeanInfo; //導入方法依賴的package包/類
private ResourcePermission getOperationContext(ObjectName objectName, String featureName,
boolean isOp) throws InstanceNotFoundException, ReflectionException {
MBeanInfo beanInfo = null;
try {
beanInfo = mbs.getMBeanInfo(objectName);
} catch (IntrospectionException e) {
throw new GemFireSecurityException("error getting beanInfo of " + objectName, e);
}
// If there is no annotation defined either in the class level or method level, we should
// consider this operation/attribute freely accessible
ResourcePermission result = null;
// find the context in the beanInfo if defined in the class level
result = getOperationContext(beanInfo.getDescriptor(), result);
MBeanFeatureInfo[] featureInfos = null;
if (isOp) {
featureInfos = beanInfo.getOperations();
} else {
featureInfos = beanInfo.getAttributes();
}
// still look into the attributes/operations to see if it's defined in the method level
for (MBeanFeatureInfo info : featureInfos) {
if (info.getName().equals(featureName)) {
// found the featureInfo of this method on the bean
result = getOperationContext(info.getDescriptor(), result);
break;
}
}
return result;
}
示例11: getMBeanAttributeType
import javax.management.MBeanInfo; //導入方法依賴的package包/類
/**
* Get MBean Attribute from Mbean Server
* @param jmxServerConnection
* @param name
* @param attribute
* @return The type
* @throws Exception
*/
protected String getMBeanAttributeType(
MBeanServerConnection jmxServerConnection,
String name,
String attribute) throws Exception {
ObjectName oname = new ObjectName(name);
String mattrType = null;
MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
MBeanAttributeInfo attrs[] = minfo.getAttributes();
for (int i = 0; mattrType == null && i < attrs.length; i++) {
if (attribute.equals(attrs[i].getName()))
mattrType = attrs[i].getType();
}
return mattrType;
}
示例12: testMXBean
import javax.management.MBeanInfo; //導入方法依賴的package包/類
private static void testMXBean(MBeanServer mbs, ObjectName on)
throws Exception {
MBeanInfo mbi = mbs.getMBeanInfo(on);
MBeanAttributeInfo[] attrs = mbi.getAttributes();
int nattrs = attrs.length;
if (mbi.getAttributes().length != 1)
failure("wrong number of attributes: " + attrs);
else {
MBeanAttributeInfo mbai = attrs[0];
if (mbai.getName().equals("Ints")
&& mbai.isReadable() && !mbai.isWritable()
&& mbai.getDescriptor().getFieldValue("openType")
.equals(new ArrayType<int[]>(SimpleType.INTEGER, true))
&& attrs[0].getType().equals("[I"))
success("MBeanAttributeInfo");
else
failure("MBeanAttributeInfo: " + mbai);
}
int[] ints = (int[]) mbs.getAttribute(on, "Ints");
if (equal(ints, new int[] {1, 2, 3}, null))
success("getAttribute");
else
failure("getAttribute: " + Arrays.toString(ints));
ExplicitMXBean proxy =
JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class);
int[] pints = proxy.getInts();
if (equal(pints, new int[] {1, 2, 3}, null))
success("getAttribute through proxy");
else
failure("getAttribute through proxy: " + Arrays.toString(pints));
}
示例13: getMBeanAttributeType
import javax.management.MBeanInfo; //導入方法依賴的package包/類
/**
* Get MBean Attribute from Mbean Server
*
* @param jmxServerConnection
* @param name
* @param attribute
* @return The type
* @throws Exception
*/
protected String getMBeanAttributeType(MBeanServerConnection jmxServerConnection, String name, String attribute)
throws Exception {
ObjectName oname = new ObjectName(name);
String mattrType = null;
MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
MBeanAttributeInfo attrs[] = minfo.getAttributes();
for (int i = 0; mattrType == null && i < attrs.length; i++) {
if (attribute.equals(attrs[i].getName()))
mattrType = attrs[i].getType();
}
return mattrType;
}
示例14: getAttribute
import javax.management.MBeanInfo; //導入方法依賴的package包/類
Object getAttribute(MBeanServerConnection mbsc,
ObjectName object,
String attribute)
throws AttributeNotFoundException,
InstanceNotFoundException,
MBeanException,
ReflectionException,
IOException {
// Check for "ObservedAttribute" replacement.
// This could happen if a thread A called setObservedAttribute()
// while other thread B was in the middle of the monitor() method
// and received the old observed attribute value.
//
final boolean lookupMBeanInfo;
synchronized (this) {
if (!isActive())
throw new IllegalArgumentException(
"The monitor has been stopped");
if (!attribute.equals(getObservedAttribute()))
throw new IllegalArgumentException(
"The observed attribute has been changed");
lookupMBeanInfo =
(firstAttribute == null && attribute.indexOf('.') != -1);
}
// Look up MBeanInfo if needed
//
final MBeanInfo mbi;
if (lookupMBeanInfo) {
try {
mbi = mbsc.getMBeanInfo(object);
} catch (IntrospectionException e) {
throw new IllegalArgumentException(e);
}
} else {
mbi = null;
}
// Check for complex type attribute
//
final String fa;
synchronized (this) {
if (!isActive())
throw new IllegalArgumentException(
"The monitor has been stopped");
if (!attribute.equals(getObservedAttribute()))
throw new IllegalArgumentException(
"The observed attribute has been changed");
if (firstAttribute == null) {
if (attribute.indexOf('.') != -1) {
MBeanAttributeInfo mbaiArray[] = mbi.getAttributes();
for (MBeanAttributeInfo mbai : mbaiArray) {
if (attribute.equals(mbai.getName())) {
firstAttribute = attribute;
break;
}
}
if (firstAttribute == null) {
String tokens[] = attribute.split("\\.", -1);
firstAttribute = tokens[0];
for (int i = 1; i < tokens.length; i++)
remainingAttributes.add(tokens[i]);
isComplexTypeAttribute = true;
}
} else {
firstAttribute = attribute;
}
}
fa = firstAttribute;
}
return mbsc.getAttribute(object, fa);
}
示例15: main
import javax.management.MBeanInfo; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException,
MalformedObjectNameException, InstanceNotFoundException,
AttributeNotFoundException, InvalidAttributeValueException,
MBeanException, ReflectionException, IntrospectionException {
String domainName = "MyMBean";
int rmiPort = 1099;
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:"+rmiPort+"/"+domainName);
// 可以類比HelloAgent.java中的那句:
// JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
JMXConnector jmxc = JMXConnectorFactory.connect(url);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
//print domains
System.out.println("Domains:------------------");
String domains[] = mbsc.getDomains();
for(int i=0;i<domains.length;i++){
System.out.println("\tDomain["+i+"] = "+domains[i]);
}
//MBean count
System.out.println("MBean count = "+mbsc.getMBeanCount());
//process attribute
ObjectName mBeanName = new ObjectName(domainName+":name=HelloWorld");
mbsc.setAttribute(mBeanName, new Attribute("Name","zzh"));//注意這裏是Name而不是name
System.out.println("Name = "+mbsc.getAttribute(mBeanName, "Name"));
//接下去是執行Hello中的printHello方法,分別通過代理和rmi的方式執行
//via proxy
HelloMBean proxy = MBeanServerInvocationHandler.newProxyInstance(mbsc, mBeanName, HelloMBean.class, false);
proxy.printHello();
proxy.printHello("jizhi boy");
//via rmi
mbsc.invoke(mBeanName, "printHello", null, null);
mbsc.invoke(mBeanName, "printHello", new String[]{"jizhi gril"}, new String[]{String.class.getName()});
//get mbean information
MBeanInfo info = mbsc.getMBeanInfo(mBeanName);
System.out.println("Hello Class: "+info.getClassName());
for(int i=0;i<info.getAttributes().length;i++){
System.out.println("Hello Attribute:"+info.getAttributes()[i].getName());
}
for(int i=0;i<info.getOperations().length;i++){
System.out.println("Hello Operation:"+info.getOperations()[i].getName());
}
//ObjectName of MBean
System.out.println("all ObjectName:--------------");
Set<ObjectInstance> set = mbsc.queryMBeans(null, null);
for(Iterator<ObjectInstance> it = set.iterator();it.hasNext();){
ObjectInstance oi = it.next();
System.out.println("\t"+oi.getObjectName());
}
jmxc.close();
}