本文整理汇总了Java中javax.management.MBeanServerConnection.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java MBeanServerConnection.getAttribute方法的具体用法?Java MBeanServerConnection.getAttribute怎么用?Java MBeanServerConnection.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.MBeanServerConnection
的用法示例。
在下文中一共展示了MBeanServerConnection.getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FlagJMXProxy
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
public FlagJMXProxy(final ObjectName source, final MBeanServerConnection mbsc, final String flagName) throws MalformedObjectNameException {
ObjectName name = PogamutJMX.getObjectName(source, flagName, PogamutJMX.FLAGS_SUBTYPE);
try {
listener = new NotificationListener() {
@Override
public void handleNotification(Notification notification, Object handback) {
if (notification.getSource().equals(source) && notification.getType().equals(flagName)) {
setFlag((T) notification.getUserData());
}
}
};
// get current value of the flag
T val = (T) mbsc.getAttribute(name, "Flag");
setFlag(val);
/* NOTE filters are send over RMI to the server !!! it is better to
handle filtering in the listener itself.
NotificationFilter nf = new NotificationFilter() {
@Override
public boolean isNotificationEnabled(Notification notification) {
return notification.getSource().equals(source) && notification.getType().equals(flagName);
}
};
*/
mbsc.addNotificationListener(name, listener, null, mbsc);
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
示例2: printMBeanInfo
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* Dumps the details of a single MBean.
*
* @param connection
* the server connection (or server itself)
* @param objectName
* the object name
* @param out
* PrintWriter to write the output to
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws JMException
* Signals a JMX error
*/
private static void printMBeanInfo(MBeanServerConnection connection, ObjectName objectName, PrintWriter out)
throws IOException, JMException
{
Map<String, Object> attributes = new TreeMap<String, Object>();
MBeanInfo info = connection.getMBeanInfo(objectName);
attributes.put("** Object Name", objectName.toString());
attributes.put("** Object Type", info.getClassName());
for (MBeanAttributeInfo element : info.getAttributes())
{
Object value;
if (element.isReadable())
{
try
{
value = connection.getAttribute(objectName, element.getName());
}
catch (Exception e)
{
value = JmxDumpUtil.PROTECTED_VALUE;
}
}
else
{
value = JmxDumpUtil.PROTECTED_VALUE;
}
attributes.put(element.getName(), value);
}
if (objectName.getCanonicalName().equals("Alfresco:Name=SystemProperties"))
{
String osName = (String) attributes.get(OS_NAME);
if (osName != null && osName.toLowerCase().startsWith("linux"))
{
attributes.put(OS_NAME, updateOSNameAttributeForLinux(osName));
}
}
tabulate(JmxDumpUtil.NAME_HEADER, JmxDumpUtil.VALUE_HEADER, attributes, out, 0);
}
示例3: jmxGet
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* @param jmxServerConnection
* @param name
* @return The value of the given named attribute
* @throws Exception
*/
protected String jmxGet(MBeanServerConnection jmxServerConnection,String name) throws Exception {
String error = null;
if(isEcho()) {
handleOutput("MBean " + name + " get attribute " + attribute );
}
Object result = jmxServerConnection.getAttribute(
new ObjectName(name), attribute);
if (result != null) {
echoResult(attribute,result);
createProperty(result);
} else
error = "Attribute " + attribute + " is empty";
return error;
}
示例4: doGetRequest
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
protected int doGetRequest(MBeanServerConnection mbsc,
ObjectName on,
boolean expectedException) {
int errorCount = 0;
try {
Utils.debug(Utils.DEBUG_STANDARD,
"ClientSide::doGetRequest: Get attributes of the MBean") ;
mbsc.getAttribute(on, "Attribute");
if (expectedException) {
System.out.println("ClientSide::doGetRequest: " +
"(ERROR) Get did not fail with expected SecurityException");
errorCount++;
} else {
System.out.println("ClientSide::doGetRequest: (OK) Get succeed") ;
}
} catch(Exception e) {
Utils.printThrowable(e, true) ;
if (expectedException) {
if (e instanceof java.lang.SecurityException) {
System.out.println("ClientSide::doGetRequest: " +
"(OK) Get failed with expected SecurityException") ;
} else {
System.out.println("ClientSide::doGetRequest: " +
"(ERROR) Get failed with " +
e.getClass() + " instead of expected SecurityException");
errorCount++;
}
} else {
System.out.println("ClientSide::doGetRequest: (ERROR) Get failed");
errorCount++;
}
}
return errorCount;
}
示例5: jmxGet
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* @param jmxServerConnection
* @param name
* @return The value of the given named attribute
* @throws Exception
*/
protected String jmxGet(MBeanServerConnection jmxServerConnection, String name) throws Exception {
String error = null;
if (isEcho()) {
handleOutput("MBean " + name + " get attribute " + attribute);
}
Object result = jmxServerConnection.getAttribute(new ObjectName(name), attribute);
if (result != null) {
echoResult(attribute, result);
createProperty(result);
} else
error = "Attribute " + attribute + " is empty";
return error;
}
示例6: printAttrs
import javax.management.MBeanServerConnection; //导入方法依赖的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);
}
}
}
示例7: receiveLogEventThroughJMX
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
@Test
public void receiveLogEventThroughJMX()
throws InstanceAlreadyExistsException, MBeanRegistrationException,
NotCompliantMBeanException, MalformedObjectNameException,
PogamutException, MalformedURLException, IOException,
InterruptedException, MBeanException, InstanceNotFoundException,
AttributeNotFoundException, ReflectionException {
final String testMsg = "TEST LOG MESSAGE FROM receiveLogEventThroughJMX()";
ObjectName parentName = PogamutJMX.getObjectName("testDomain", "root", "test");
// export the log on the MBean server
ILogCategories logCategories = new LogCategories();
String testLogCategoryNameStr = "testLogCategory";
LogCategory testLog = logCategories.getCategory(testLogCategoryNameStr);
JMXLogCategories jmxLogCategories = new JMXLogCategories(
logCategories,
Pogamut.getPlatform().getMBeanServer(),
parentName
);
// connect through RMI and get the proxy
MBeanServerConnection mbsc = Pogamut.getPlatform().getMBeanServerConnection();
ObjectName logCatsName = jmxLogCategories.getJMXLogCategoriesName();
// get the name of all log category names
String[] catNames = (String[]) mbsc.getAttribute(logCatsName, "CategoryNames");
boolean found = false;
for (String catName : catNames) {
if (catName.equals(testLogCategoryNameStr)) {
found = true;
break;
}
}
Assert.assertTrue(testLogCategoryNameStr + " must be among exported log category names", found);
// get the object name for the test log category
ObjectName testCategoryName =
(ObjectName)
mbsc.invoke(
logCatsName,
"getJMXLogCategoryName",
new Object[]{ testLogCategoryNameStr },
new String[] { "java.lang.String" }
);
// add the listener
mbsc.addNotificationListener(testCategoryName,
new NotificationListener() {
public void handleNotification(Notification notification,
Object handback) {
receivedMessage = notification.getMessage();
messageReceivedLatch.countDown();
}
}, null, this
);
// send log event
if (testLog.isLoggable(Level.INFO)) testLog.info(testMsg);
// wait
messageReceivedLatch.await(30000, TimeUnit.MILLISECONDS);
// compare
assertTrue("Received message must contain testMsg", receivedMessage.contains(testMsg));
System.out.println("---/// TEST OK ///---");
Pogamut.getPlatform().close();
}
示例8: collectCustomMbean
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private Object collectCustomMbean (
ServiceMeter serviceMeter,
ServiceCollectionResults jmxResults,
MBeanServerConnection mbeanConn )
throws Exception {
Object jmxResultObject = 0;
String mbeanNameCustom = serviceMeter.getMbeanName();
if ( mbeanNameCustom.contains( "__CONTEXT__" ) ) {
// Some servlet metrics require version string in name
// logger.info("****** version: " +
// jmxResults.getInstanceConfig().getMavenVersion());
String version = jmxResults
.getServiceInstance()
.getMavenVersion();
if ( jmxResults
.getServiceInstance()
.isScmDeployed() ) {
version = jmxResults
.getServiceInstance()
.getScmVersion();
version = version.split( " " )[0]; // first word of
// scm
// scmVersion=3.5.6-SNAPSHOT
// Source build
// by ...
}
// WARNING: version must be updated when testing.
String serviceContext = "//localhost/" + jmxResults
.getServiceInstance()
.getContext();
if ( !jmxResults.getServiceInstance().isSpringBoot() ) {
serviceContext += "##" + version;
}
mbeanNameCustom = mbeanNameCustom.replaceAll( "__CONTEXT__", serviceContext );
logger.debug( "Using custom name: {} ", mbeanNameCustom );
}
String mbeanAttributeName = serviceMeter.getMbeanAttribute();
if ( mbeanAttributeName.equals( "SystemCpuLoad" ) ) {
// Reuse already collected values (load is stateful)
jmxResultObject = new Long( totalCpuArray.get( 0 ).asInt() );
} else if ( mbeanAttributeName.equals( "ProcessCpuLoad" ) ) {
// Reuse already collected values
jmxResultObject = new Long( jmxResults.getCpuPercent() );
} else if ( serviceMeter.getCollectionId().equalsIgnoreCase( ServiceAlertsEnum.JAVA_HEARTBEAT )
&& !isPublishSummaryAndPerformHeartBeat() && !isTestHeartBeat() ) {
// special case to avoid double heartbeats
// reUse collected value from earlier interval.
jmxResultObject = new Long( jmxResults.getServiceInstance().getJmxHeartbeatMs() );
} else {
logger.debug( "Collecting mbean: {}, attribute: {}", mbeanNameCustom, mbeanAttributeName );
jmxResultObject = mbeanConn.getAttribute( new ObjectName( mbeanNameCustom ),
mbeanAttributeName );
}
logger.debug( "Result for {} is: {}", mbeanAttributeName, jmxResultObject );
return jmxResultObject;
}
示例9: doBasicMXBeanTest
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private final int doBasicMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0 ;
System.out.println("---- doBasicMXBeanTest") ;
try {
ObjectName objName =
new ObjectName("sqe:type=BasicMXBean") ;
mbsc.createMBean(BASIC_MXBEAN_CLASS_NAME, objName);
MBeanInfo mbInfo = mbsc.getMBeanInfo(objName);
printMBeanInfo(mbInfo);
System.out.println("---- OK\n") ;
System.out.println("getMBeanInfo\t\t"
+ mbInfo);
System.out.println("---- OK\n") ;
System.out.println("Check mxbean field in the MBeanInfo");
String mxbeanField =
(String)mbInfo.getDescriptor().getFieldValue(JMX.MXBEAN_FIELD);
if ( mxbeanField == null || ! mxbeanField.equals("true")) {
System.out.println("---- ERROR : Improper mxbean field value "
+ mxbeanField);
errorCount++;
}
System.out.println("---- OK\n") ;
System.out.println("Set attribute ObjectNameAtt");
Attribute att = new Attribute("ObjectNameAtt", objName);
mbsc.setAttribute(objName, att);
ObjectName value =
(ObjectName)mbsc.getAttribute(objName, "ObjectNameAtt");
if ( ! value.equals(objName) ) {
errorCount++;
System.out.println("---- ERROR : setAttribute failed, got "
+ value
+ " while expecting "
+ objName);
}
System.out.println("---- OK\n") ;
System.out.println("Call operation doNothing");
mbsc.invoke(objName, "doNothing", null, null);
System.out.println("---- OK\n") ;
System.out.println("Call operation getWeather");
Object weather = mbsc.invoke(objName,
"getWeather",
new Object[]{Boolean.TRUE},
new String[]{"boolean"});
System.out.println("Weather is " + weather);
System.out.println("---- OK\n") ;
} catch (Exception e) {
Utils.printThrowable(e, true) ;
errorCount++ ;
System.out.println("---- ERROR\n") ;
}
return errorCount ;
}
示例10: bindAttributes
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* @param jmxServerConnection
* @param resultproperty
* @param pname
* @param oname
*/
protected void bindAttributes(MBeanServerConnection jmxServerConnection, String resultproperty, String pname, ObjectName oname) {
if (jmxServerConnection != null && resultproperty != null
&& pname != null && oname != null ) {
try {
MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
String code = minfo.getClassName();
if ("org.apache.tomcat.util.modeler.BaseModelMBean".equals(code)) {
code = (String) jmxServerConnection.getAttribute(oname,
"modelerType");
}
MBeanAttributeInfo attrs[] = minfo.getAttributes();
Object value = null;
for (int i = 0; i < attrs.length; i++) {
if (!attrs[i].isReadable())
continue;
String attName = attrs[i].getName();
if (attName.indexOf("=") >= 0 || attName.indexOf(":") >= 0
|| attName.indexOf(" ") >= 0) {
continue;
}
try {
value = jmxServerConnection
.getAttribute(oname, attName);
} catch (Throwable t) {
if (isEcho())
handleErrorOutput("Error getting attribute "
+ oname + " " + pname + attName + " "
+ t.toString());
continue;
}
if (value == null)
continue;
if ("modelerType".equals(attName))
continue;
createProperty(pname + attName, value);
}
} catch (Exception e) {
// Ignore
}
}
}
示例11: invoke
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
@Override
Object invoke(MBeanServerConnection mbsc, ObjectName name, Object[] args)
throws Exception {
assert(args == null || args.length == 0);
return mbsc.getAttribute(name, getName());
}
示例12: getAttribute
import javax.management.MBeanServerConnection; //导入方法依赖的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);
}
示例13: checkAuthenticator
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* Make some check about the instance of TestJMXAuthenticator.
* The authenticator is supposed to have set some properties on
* a ServerDelegate MBean.
* We compare the number of times it has been called with the expected value.
* We also check the Principal that has been given to the authenticator
* was not null.
* That method is of use to authentication with the JSR 262.
* @param mbs
* @param expectedAuthenticatorCallCount
* @return The number of errors encountered.
* @throws java.lang.Exception
*/
protected int checkAuthenticator(MBeanServerConnection mbs,
int expectedAuthenticatorCallCount) throws Exception {
int errorCount = 0;
// Ensure the authenticator has been called the right number
// of times.
int callCount =
((Integer) mbs.getAttribute(
new ObjectName(SERVER_DELEGATE_MBEAN_NAME),
"TestJMXAuthenticatorCallCount")).intValue();
if (callCount == expectedAuthenticatorCallCount) {
System.out.println("---- OK Authenticator has been called "
+ expectedAuthenticatorCallCount + " time");
} else {
errorCount++;
System.out.println("---- ERROR Authenticator has been called " + callCount
+ " times in place of " + expectedAuthenticatorCallCount);
}
// Ensure the provider has been called with
// a non null Principal.
String principalString =
(String) mbs.getAttribute(
new ObjectName(SERVER_DELEGATE_MBEAN_NAME),
"TestJMXAuthenticatorPrincipalString");
if (principalString == null) {
errorCount++;
System.out.println("---- ERROR Authenticator has been called"
+ " with a null Principal");
} else {
if (principalString.length() > 0) {
System.out.println("---- OK Authenticator has been called"
+ " with the Principal " + principalString);
} else {
errorCount++;
System.out.println("---- ERROR Authenticator has been called"
+ " with an empty Principal");
}
}
return errorCount;
}
示例14: main
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
int errorCount = 0 ;
String msgTag = "ClientSide::main: ";
try {
// Get a connection to remote mbean server
JMXServiceURL addr = new JMXServiceURL(args[0]);
JMXConnector cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
// ----
System.out.println(msgTag + "Create and register the MBean");
ObjectName objName = new ObjectName("sqe:type=Basic,protocol=rmi") ;
mbsc.createMBean(BASIC_MXBEAN_CLASS_NAME, objName);
System.out.println(msgTag +"---- OK\n") ;
// ----
System.out.println(msgTag +"Get attribute SqeParameterAtt on our MXBean");
Object result = mbsc.getAttribute(objName, "SqeParameterAtt");
System.out.println(msgTag +"(OK) Got result of class "
+ result.getClass().getName());
System.out.println(msgTag +"Received CompositeData is " + result);
System.out.println(msgTag +"---- OK\n") ;
// ----
// We use the value returned by getAttribute to perform the invoke.
System.out.println(msgTag +"Call operation doWeird on our MXBean [1]");
mbsc.invoke(objName, "doWeird",
new Object[]{result},
new String[]{"javax.management.openmbean.CompositeData"});
System.out.println(msgTag +"---- OK\n") ;
// ----
// We build the CompositeData ourselves that time.
System.out.println(msgTag +"Call operation doWeird on our MXBean [2]");
String typeName = "SqeParameter";
String[] itemNames = new String[] {"glop"};
OpenType<?>[] openTypes = new OpenType<?>[] {SimpleType.STRING};
CompositeType rowType = new CompositeType(typeName, typeName,
itemNames, itemNames, openTypes);
Object[] itemValues = {"HECTOR"};
CompositeData data =
new CompositeDataSupport(rowType, itemNames, itemValues);
TabularType tabType = new TabularType(typeName, typeName,
rowType, new String[]{"glop"});
TabularDataSupport tds = new TabularDataSupport(tabType);
tds.put(data);
System.out.println(msgTag +"Source CompositeData is " + data);
mbsc.invoke(objName, "doWeird",
new Object[]{data},
new String[]{"javax.management.openmbean.CompositeData"});
System.out.println(msgTag +"---- OK\n") ;
// ----
System.out.println(msgTag +"Unregister the MBean");
mbsc.unregisterMBean(objName);
System.out.println(msgTag +"---- OK\n") ;
// Terminate the JMX Client
cc.close();
} catch(Exception e) {
Utils.printThrowable(e, true) ;
errorCount++;
throw new RuntimeException(e);
} finally {
System.exit(errorCount);
}
}
示例15: doCaptureMonitorData
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* doCaptureMonitorData
*
* @param mbsc
* @param timeFlag
* @return
* @throws IOException
*/
protected boolean doCaptureMonitorData(MBeanServerConnection mbsc, long timeFlag, MonitorDataFrame mdf)
throws IOException {
boolean needProcessCheck = true;
// get all monitors' MBean
Set<ObjectInstance> monitorMBeans = scanMonitorMBeans(mbsc);
// the monitorMBeans should not be null if connection is all right, still check that in case abnormal issues
if (doNoMBeanAction(monitorMBeans, "Monitor")) {
/**
* if the connection is not available, then the IOException will trigger process checking so if the
* connection is OK but there is no any MBean, we notify that but still return false that means we will not
* run process checking
*/
return false;
}
Iterator<ObjectInstance> iterator = monitorMBeans.iterator();
while (iterator.hasNext()) {
ObjectInstance oi = iterator.next();
try {
// catch monitor data
ObjectName monitorON = oi.getObjectName();
Object oData = mbsc.getAttribute(monitorON, "Data");
if (oData != null) {
needProcessCheck = false;
// add data to MonitorDataFrame
mdf.addData(monitorON.getKeyProperty("id"), oData.toString());
}
}
catch (Exception e) {
log.err(this, "MonitorMBean[" + oi.getObjectName().toString() + "] catch data FAILs", e);
}
}
// add appgroup
mdf.addExt("appgroup", this.getAppGroup());
return needProcessCheck;
}