本文整理汇总了Java中javax.management.AttributeList类的典型用法代码示例。如果您正苦于以下问题:Java AttributeList类的具体用法?Java AttributeList怎么用?Java AttributeList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AttributeList类属于javax.management包,在下文中一共展示了AttributeList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTest
import javax.management.AttributeList; //导入依赖的package包/类
private void doTest(JMXConnector connector) throws IOException,
MalformedObjectNameException, ReflectionException,
InstanceAlreadyExistsException, MBeanRegistrationException,
MBeanException, NotCompliantMBeanException, InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException {
MBeanServerConnection mbsc = connector.getMBeanServerConnection();
ObjectName objName = new ObjectName("com.redhat.test.jmx:type=NameMBean");
System.out.println("DEBUG: Calling createMBean");
mbsc.createMBean(Name.class.getName(), objName);
System.out.println("DEBUG: Calling setAttributes");
AttributeList attList = new AttributeList();
attList.add(new Attribute("FirstName", ANY_NAME));
attList.add(new Attribute("LastName", ANY_NAME));
mbsc.setAttributes(objName, attList);
}
示例2: getAttributes
import javax.management.AttributeList; //导入依赖的package包/类
@Override
public AttributeList getAttributes(String[] attributeNames) {
if (attributeNames == null || attributeNames.length == 0)
throw new IllegalArgumentException();
updateMbeanInfoIfMetricsListChanged();
AttributeList result = new AttributeList(attributeNames.length);
for (String iAttributeName : attributeNames) {
try {
Object value = getAttribute(iAttributeName);
result.add(new Attribute(iAttributeName, value));
} catch (Exception e) {
continue;
}
}
return result;
}
示例3: getAttributes
import javax.management.AttributeList; //导入依赖的package包/类
/**
* Obtain and return the values of several attributes of this MBean.
*
* @param names Names of the requested attributes
*/
@Override
public AttributeList getAttributes(String names[]) {
// Validate the input parameters
if (names == null)
throw new RuntimeOperationsException
(new IllegalArgumentException("Attribute names list is null"),
"Attribute names list is null");
// Prepare our response, eating all exceptions
AttributeList response = new AttributeList();
for (int i = 0; i < names.length; i++) {
try {
response.add(new Attribute(names[i],getAttribute(names[i])));
} catch (Exception e) {
// Not having a particular attribute in the response
// is the indication of a getter problem
}
}
return (response);
}
示例4: setAttributes
import javax.management.AttributeList; //导入依赖的package包/类
/**
* Set the values of several attributes of this MBean.
*
* @param attributes THe names and values to be set
*
* @return The list of attributes that were set and their new values
*/
@Override
public AttributeList setAttributes(AttributeList attributes) {
AttributeList response = new AttributeList();
// Validate the input parameters
if (attributes == null)
return response;
// Prepare and return our response, eating all exceptions
String names[] = new String[attributes.size()];
int n = 0;
Iterator<?> items = attributes.iterator();
while (items.hasNext()) {
Attribute item = (Attribute) items.next();
names[n++] = item.getName();
try {
setAttribute(item);
} catch (Exception e) {
// Ignore all exceptions
}
}
return (getAttributes(names));
}
示例5: getAttributes
import javax.management.AttributeList; //导入依赖的package包/类
/**
* Obtain and return the values of several attributes of this MBean.
*
* @param names
* Names of the requested attributes
*/
@Override
public AttributeList getAttributes(String names[]) {
// Validate the input parameters
if (names == null)
throw new RuntimeOperationsException(new IllegalArgumentException("Attribute names list is null"),
"Attribute names list is null");
// Prepare our response, eating all exceptions
AttributeList response = new AttributeList();
for (int i = 0; i < names.length; i++) {
try {
response.add(new Attribute(names[i], getAttribute(names[i])));
} catch (Exception e) {
// Not having a particular attribute in the response
// is the indication of a getter problem
}
}
return (response);
}
示例6: getAttributes
import javax.management.AttributeList; //导入依赖的package包/类
@Override
public AttributeList getAttributes(String[] attributeNames) {
if (attributeNames == null) {
throw new RuntimeOperationsException(new IllegalArgumentException("attributeNames[] cannot be null"),
"Cannot call getAttributes with null attribute names");
}
AttributeList resultList = new AttributeList();
if (attributeNames.length == 0) {
return resultList;
}
for (String attributeName : attributeNames) {
try {
Object value = getAttribute(attributeName);
resultList.add(new Attribute(attributeName, value));
} catch (Exception e) {
e.printStackTrace();
}
}
return (resultList);
}
示例7: getAttributes
import javax.management.AttributeList; //导入依赖的package包/类
/**
* Obtain and return the values of several attributes of this MBean.
*
* @param names Names of the requested attributes
*/
public AttributeList getAttributes(String names[]) {
// Validate the input parameters
if (names == null)
throw new RuntimeOperationsException
(new IllegalArgumentException("Attribute names list is null"),
"Attribute names list is null");
// Prepare our response, eating all exceptions
AttributeList response = new AttributeList();
for (int i = 0; i < names.length; i++) {
try {
response.add(new Attribute(names[i],getAttribute(names[i])));
} catch (Exception e) {
; // Not having a particular attribute in the response
; // is the indication of a getter problem
}
}
return (response);
}
示例8: testSetAttribute
import javax.management.AttributeList; //导入依赖的package包/类
@Test
public void testSetAttribute() throws Exception {
DynamicMBean proxy = JMX.newMBeanProxy(platformMBeanServer, threadPoolDynamicWrapperON, DynamicMBean.class);
proxy.setAttribute(new Attribute(THREAD_COUNT, newThreadCount));
assertEquals(newThreadCount, proxy.getAttribute(THREAD_COUNT));
assertEquals(newThreadCount, threadPoolConfigBean.getThreadCount());
AttributeList attributeList = new AttributeList();
attributeList.add(new Attribute(THREAD_COUNT, threadCount));
boolean bool = true;
attributeList.add(new Attribute(TRIGGER_NEW_INSTANCE_CREATION, bool));
proxy.setAttributes(attributeList);
assertEquals(threadCount, threadPoolConfigBean.getThreadCount());
assertEquals(bool, threadPoolConfigBean.isTriggerNewInstanceCreation());
}
示例9: getProcessCpuLoad
import javax.management.AttributeList; //导入依赖的package包/类
public static double getProcessCpuLoad(MBeanServerConnection mbs)
throws MalformedObjectNameException, NullPointerException, InstanceNotFoundException,
ReflectionException, IOException {
ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
AttributeList list = mbs.getAttributes(name, new String[]{"ProcessCpuLoad"});
if (list.isEmpty()) {
return 0.0;
}
Attribute att = (Attribute) list.get(0);
Double value = (Double) att.getValue();
// usually takes a couple of seconds before we get real values
if (value == -1.0) {
return 0.0;
}
// returns a percentage value with 1 decimal point precision
return ((int) (value * 1000) / 10.0);
}
示例10: getAttributes
import javax.management.AttributeList; //导入依赖的package包/类
public AttributeList getAttributes(ObjectName name,
String[] attributes)
throws InstanceNotFoundException,
ReflectionException,
IOException {
if (logger.debugOn()) logger.debug("getAttributes",
"name=" + name + ", attributes="
+ strings(attributes));
final ClassLoader old = pushDefaultClassLoader();
try {
return connection.getAttributes(name,
attributes,
delegationSubject);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
return connection.getAttributes(name,
attributes,
delegationSubject);
} finally {
popDefaultClassLoader(old);
}
}
示例11: testReadAttributes
import javax.management.AttributeList; //导入依赖的package包/类
@Test
public void testReadAttributes() throws Exception {
DynamicMBean proxy = JMX.newMBeanProxy(platformMBeanServer, threadPoolDynamicWrapperON, DynamicMBean.class);
assertEquals(threadCount, proxy.getAttribute(THREAD_COUNT));
assertEquals(threadPoolConfigBean.isTriggerNewInstanceCreation(),
proxy.getAttribute(TRIGGER_NEW_INSTANCE_CREATION));
AttributeList attributes = proxy.getAttributes(new String[] { THREAD_COUNT, TRIGGER_NEW_INSTANCE_CREATION });
assertEquals(2, attributes.size());
Attribute threadCountAttr = (Attribute) attributes.get(0);
assertEquals(THREAD_COUNT, threadCountAttr.getName());
assertEquals(threadCount, threadCountAttr.getValue());
Attribute boolTestAttr = (Attribute) attributes.get(1);
assertEquals(TRIGGER_NEW_INSTANCE_CREATION, boolTestAttr.getName());
assertEquals(threadPoolConfigBean.isTriggerNewInstanceCreation(), boolTestAttr.getValue());
MBeanInfo beanInfo = proxy.getMBeanInfo();
assertEquals(2, beanInfo.getAttributes().length);
}
示例12: setAttributes
import javax.management.AttributeList; //导入依赖的package包/类
public AttributeList setAttributes(AttributeList attributes) {
if (attributes == null)
throw new RuntimeOperationsException(new IllegalArgumentException(
LocalizedStrings.MX4JModelMBean_ATTRIBUTE_LIST_CANNOT_BE_NULL.toLocalizedString()));
Logger logger = getLogger();
AttributeList list = new AttributeList();
for (Iterator i = attributes.iterator(); i.hasNext();) {
Attribute attribute = (Attribute) i.next();
String name = attribute.getName();
try {
setAttribute(attribute);
list.add(attribute);
} catch (Exception x) {
if (logger.isEnabledFor(Logger.TRACE))
logger.trace("setAttribute for attribute " + name + " failed", x);
// And go on with the next one
}
}
return list;
}
示例13: getProcessCpuLoad
import javax.management.AttributeList; //导入依赖的package包/类
public static double getProcessCpuLoad() {
double cpuLoad;
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
AttributeList list = mbs.getAttributes(name, new String[] { "ProcessCpuLoad" });
if(list.isEmpty()) {
return Double.NaN;
}
Attribute att = (Attribute) list.get(0);
Double value = (Double) att.getValue();
if(value == -1.0) {
return Double.NaN;
}
cpuLoad = value * 100d;
} catch (InstanceNotFoundException | ReflectionException | MalformedObjectNameException err) {
cpuLoad = Double.NaN;
}
return cpuLoad;
}
示例14: getAttributes
import javax.management.AttributeList; //导入依赖的package包/类
public AttributeList getAttributes(String[] attributeNames)
{
if(attributeNames != null)
{
AttributeList resultList = new AttributeList();
if (attributeNames.length == 0)
return resultList;
// Build the result attribute list
for(int i=0 ; i<attributeNames.length; i++)
{
try
{
Object oValue = getAttribute(attributeNames[i]);
resultList.add(new Attribute(attributeNames[i], oValue));
}
catch (Exception e)
{
}
}
return resultList;
}
return null;
}
示例15: invoke
import javax.management.AttributeList; //导入依赖的package包/类
@Override
public Object invoke(final String actionName, final Object[] params, final String[] signature)
throws MBeanException, ReflectionException {
if ("getAttribute".equals(actionName) && params.length == 1 && signature[0].equals(String.class.getName())) {
try {
return getAttribute((String) params[0]);
} catch (final AttributeNotFoundException e) {
throw new MBeanException(e, "Attribute not found on " + moduleIdentifier);
}
} else if ("getAttributes".equals(actionName) && params.length == 1
&& signature[0].equals(String[].class.getName())) {
return getAttributes((String[]) params[0]);
} else if ("setAttributes".equals(actionName) && params.length == 1
&& signature[0].equals(AttributeList.class.getName())) {
return setAttributes((AttributeList) params[0]);
} else {
LOG.debug("Operation not found {} ", actionName);
throw new UnsupportedOperationException(String.format(
"Operation not found on %s. Method invoke is only supported for getInstance and getAttribute(s) "
+ "method, got actionName %s, params %s, signature %s ",
moduleIdentifier, actionName, params, signature));
}
}