下面列出了javax.management.MBeanServerConnection#isRegistered ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private final int doCompilationMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0 ;
System.out.println("---- CompilationMXBean") ;
try {
ObjectName compilationName =
new ObjectName(ManagementFactory.COMPILATION_MXBEAN_NAME);
if ( mbsc.isRegistered(compilationName) ) {
MBeanInfo mbInfo = mbsc.getMBeanInfo(compilationName);
errorCount += checkNonEmpty(mbInfo);
System.out.println("getMBeanInfo\t\t" + mbInfo);
CompilationMXBean compilation = null ;
compilation =
JMX.newMXBeanProxy(mbsc,
compilationName,
CompilationMXBean.class) ;
System.out.println("getName\t\t"
+ compilation.getName());
boolean supported =
compilation.isCompilationTimeMonitoringSupported() ;
System.out.println("isCompilationTimeMonitoringSupported\t\t"
+ supported);
if ( supported ) {
System.out.println("getTotalCompilationTime\t\t"
+ compilation.getTotalCompilationTime());
}
}
System.out.println("---- OK\n") ;
} catch (Exception e) {
Utils.printThrowable(e, true) ;
errorCount++ ;
System.out.println("---- ERROR\n") ;
}
return errorCount ;
}
/**
* Get the ObjectName for the application
* created ManagementMBean. The MBean will be
* created if it is not already registered.
* @throws Exception
*/
protected ObjectName getApplicationManagementMBean() throws Exception
{
/* prepare the Management mbean, which is (so far) the only MBean that
* can be created/registered from a JMX client, and without knowing the
* system identifier */
final ObjectName mgmtObjName
= new ObjectName("com.pivotal.gemfirexd.internal", "type", "Management");
// create/register the MBean. If the same MBean has already been
// registered with the MBeanServer, that MBean will be referenced.
//ObjectInstance mgmtObj =
final MBeanServerConnection serverConn = getMBeanServerConnection();
if (!serverConn.isRegistered(mgmtObjName))
{
AccessController.doPrivileged(
new PrivilegedExceptionAction<Object>() {
public Object run() throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, ReflectionException, MBeanException, IOException {
serverConn.createMBean(
"com.pivotal.gemfirexd.internal.mbeans.Management",
mgmtObjName);
return null;
}
}
);
}
return mgmtObjName;
}
/**
Ensure that AMX is loaded and ready to use. This method returns only when all
AMX subsystems have been loaded.
It can be called more than once without ill effect, subsequent calls are ignored.
@param conn connection to the MBeanServer
@return the ObjectName of the domain-root MBean
*/
public ObjectName bootAMX(final MBeanServerConnection conn)
throws IOException
{
final ObjectName domainRoot = domainRoot();
if ( !conn.isRegistered( domainRoot ) )
{
// wait for the BootAMXMBean to be available (loads at startup)
final BootAMXCallback callback = new BootAMXCallback(conn);
listenForBootAMX(conn, callback);
callback.await(); // block until the MBean appears
invokeBootAMX(conn);
final WaitForDomainRootListenerCallback drCallback = new WaitForDomainRootListenerCallback(conn);
listenForDomainRoot(conn, drCallback);
drCallback.await();
invokeWaitAMXReady(conn, domainRoot);
}
else
{
invokeWaitAMXReady(conn, domainRoot );
}
return domainRoot;
}
private boolean isRegistered( final MBeanServerConnection conn, final ObjectName objectName )
{
try
{
return conn.isRegistered(objectName);
}
catch (final Exception e)
{
throw new RuntimeException(e);
}
}
/**
Ensure that AMX is loaded and ready to use. This method returns only when all
AMX subsystems have been loaded.
It can be called more than once without ill effect, subsequent calls are ignored.
@param conn connection to the MBeanServer
@return the ObjectName of the domain-root MBean
*/
public ObjectName bootAMX(final MBeanServerConnection conn)
throws IOException
{
final ObjectName domainRoot = domainRoot();
if ( !conn.isRegistered( domainRoot ) )
{
// wait for the BootAMXMBean to be available (loads at startup)
final BootAMXCallback callback = new BootAMXCallback(conn);
listenForBootAMX(conn, callback);
callback.await(); // block until the MBean appears
invokeBootAMX(conn);
final WaitForDomainRootListenerCallback drCallback = new WaitForDomainRootListenerCallback(conn);
listenForDomainRoot(conn, drCallback);
drCallback.await();
invokeWaitAMXReady(conn, domainRoot);
}
else
{
invokeWaitAMXReady(conn, domainRoot );
}
return domainRoot;
}
private boolean isRegistered( final MBeanServerConnection conn, final ObjectName objectName )
{
try
{
return conn.isRegistered(objectName);
}
catch (final Exception e)
{
throw new RuntimeException(e);
}
}
private boolean isRegistered( final MBeanServerConnection conn, final ObjectName objectName )
{
try
{
return conn.isRegistered(objectName);
}
catch (final Exception e)
{
throw new RuntimeException(e);
}
}
/**
Ensure that AMX is loaded and ready to use. This method returns only when all
AMX subsystems have been loaded.
It can be called more than once without ill effect, subsequent calls are ignored.
@param conn connection to the MBeanServer
@return the ObjectName of the domain-root MBean
*/
public ObjectName bootAMX(final MBeanServerConnection conn)
throws IOException
{
final ObjectName domainRoot = domainRoot();
if ( !conn.isRegistered( domainRoot ) )
{
// wait for the BootAMXMBean to be available (loads at startup)
final BootAMXCallback callback = new BootAMXCallback(conn);
listenForBootAMX(conn, callback);
callback.await(); // block until the MBean appears
invokeBootAMX(conn);
final WaitForDomainRootListenerCallback drCallback = new WaitForDomainRootListenerCallback(conn);
listenForDomainRoot(conn, drCallback);
drCallback.await();
invokeWaitAMXReady(conn, domainRoot);
}
else
{
invokeWaitAMXReady(conn, domainRoot );
}
return domainRoot;
}
private boolean isRegistered( final MBeanServerConnection conn, final ObjectName objectName )
{
try
{
return conn.isRegistered(objectName);
}
catch (final Exception e)
{
throw new RuntimeException(e);
}
}
private final int doCompilationMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0 ;
System.out.println("---- CompilationMXBean") ;
try {
ObjectName compilationName =
new ObjectName(ManagementFactory.COMPILATION_MXBEAN_NAME);
if ( mbsc.isRegistered(compilationName) ) {
MBeanInfo mbInfo = mbsc.getMBeanInfo(compilationName);
errorCount += checkNonEmpty(mbInfo);
System.out.println("getMBeanInfo\t\t" + mbInfo);
CompilationMXBean compilation = null ;
compilation =
JMX.newMXBeanProxy(mbsc,
compilationName,
CompilationMXBean.class) ;
System.out.println("getName\t\t"
+ compilation.getName());
boolean supported =
compilation.isCompilationTimeMonitoringSupported() ;
System.out.println("isCompilationTimeMonitoringSupported\t\t"
+ supported);
if ( supported ) {
System.out.println("getTotalCompilationTime\t\t"
+ compilation.getTotalCompilationTime());
}
}
System.out.println("---- OK\n") ;
} catch (Exception e) {
Utils.printThrowable(e, true) ;
errorCount++ ;
System.out.println("---- ERROR\n") ;
}
return errorCount ;
}
/**
Ensure that AMX is loaded and ready to use. This method returns only when all
AMX subsystems have been loaded.
It can be called more than once without ill effect, subsequent calls are ignored.
@param conn connection to the MBeanServer
@return the ObjectName of the domain-root MBean
*/
public ObjectName bootAMX(final MBeanServerConnection conn)
throws IOException
{
final ObjectName domainRoot = domainRoot();
if ( !conn.isRegistered( domainRoot ) )
{
// wait for the BootAMXMBean to be available (loads at startup)
final BootAMXCallback callback = new BootAMXCallback(conn);
listenForBootAMX(conn, callback);
callback.await(); // block until the MBean appears
invokeBootAMX(conn);
final WaitForDomainRootListenerCallback drCallback = new WaitForDomainRootListenerCallback(conn);
listenForDomainRoot(conn, drCallback);
drCallback.await();
invokeWaitAMXReady(conn, domainRoot);
}
else
{
invokeWaitAMXReady(conn, domainRoot );
}
return domainRoot;
}
private boolean isRegistered( final MBeanServerConnection conn, final ObjectName objectName )
{
try
{
return conn.isRegistered(objectName);
}
catch (final Exception e)
{
throw new RuntimeException(e);
}
}
private boolean isRegistered( final MBeanServerConnection conn, final ObjectName objectName )
{
try
{
return conn.isRegistered(objectName);
}
catch (final Exception e)
{
throw new RuntimeException(e);
}
}
/**
Ensure that AMX is loaded and ready to use. This method returns only when all
AMX subsystems have been loaded.
It can be called more than once without ill effect, subsequent calls are ignored.
@param conn connection to the MBeanServer
@return the ObjectName of the domain-root MBean
*/
public ObjectName bootAMX(final MBeanServerConnection conn)
throws IOException
{
final ObjectName domainRoot = domainRoot();
if ( !conn.isRegistered( domainRoot ) )
{
// wait for the BootAMXMBean to be available (loads at startup)
final BootAMXCallback callback = new BootAMXCallback(conn);
listenForBootAMX(conn, callback);
callback.await(); // block until the MBean appears
invokeBootAMX(conn);
final WaitForDomainRootListenerCallback drCallback = new WaitForDomainRootListenerCallback(conn);
listenForDomainRoot(conn, drCallback);
drCallback.await();
invokeWaitAMXReady(conn, domainRoot);
}
else
{
invokeWaitAMXReady(conn, domainRoot );
}
return domainRoot;
}
private boolean isRegistered( final MBeanServerConnection conn, final ObjectName objectName )
{
try
{
return conn.isRegistered(objectName);
}
catch (final Exception e)
{
throw new RuntimeException(e);
}
}
private final int doCompilationMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0 ;
System.out.println("---- CompilationMXBean") ;
try {
ObjectName compilationName =
new ObjectName(ManagementFactory.COMPILATION_MXBEAN_NAME);
if ( mbsc.isRegistered(compilationName) ) {
MBeanInfo mbInfo = mbsc.getMBeanInfo(compilationName);
errorCount += checkNonEmpty(mbInfo);
System.out.println("getMBeanInfo\t\t" + mbInfo);
CompilationMXBean compilation = null ;
compilation =
JMX.newMXBeanProxy(mbsc,
compilationName,
CompilationMXBean.class) ;
System.out.println("getName\t\t"
+ compilation.getName());
boolean supported =
compilation.isCompilationTimeMonitoringSupported() ;
System.out.println("isCompilationTimeMonitoringSupported\t\t"
+ supported);
if ( supported ) {
System.out.println("getTotalCompilationTime\t\t"
+ compilation.getTotalCompilationTime());
}
}
System.out.println("---- OK\n") ;
} catch (Exception e) {
Utils.printThrowable(e, true) ;
errorCount++ ;
System.out.println("---- ERROR\n") ;
}
return errorCount ;
}
/**
Ensure that AMX is loaded and ready to use. This method returns only when all
AMX subsystems have been loaded.
It can be called more than once without ill effect, subsequent calls are ignored.
@param conn connection to the MBeanServer
@return the ObjectName of the domain-root MBean
*/
public ObjectName bootAMX(final MBeanServerConnection conn)
throws IOException
{
final ObjectName domainRoot = domainRoot();
if ( !conn.isRegistered( domainRoot ) )
{
// wait for the BootAMXMBean to be available (loads at startup)
final BootAMXCallback callback = new BootAMXCallback(conn);
listenForBootAMX(conn, callback);
callback.await(); // block until the MBean appears
invokeBootAMX(conn);
final WaitForDomainRootListenerCallback drCallback = new WaitForDomainRootListenerCallback(conn);
listenForDomainRoot(conn, drCallback);
drCallback.await();
invokeWaitAMXReady(conn, domainRoot);
}
else
{
invokeWaitAMXReady(conn, domainRoot );
}
return domainRoot;
}
private boolean isRegistered( final MBeanServerConnection conn, final ObjectName objectName )
{
try
{
return conn.isRegistered(objectName);
}
catch (final Exception e)
{
throw new RuntimeException(e);
}
}
/**
Ensure that AMX is loaded and ready to use. This method returns only when all
AMX subsystems have been loaded.
It can be called more than once without ill effect, subsequent calls are ignored.
@param conn connection to the MBeanServer
@return the ObjectName of the domain-root MBean
*/
public ObjectName bootAMX(final MBeanServerConnection conn)
throws IOException
{
final ObjectName domainRoot = domainRoot();
if ( !conn.isRegistered( domainRoot ) )
{
// wait for the BootAMXMBean to be available (loads at startup)
final BootAMXCallback callback = new BootAMXCallback(conn);
listenForBootAMX(conn, callback);
callback.await(); // block until the MBean appears
invokeBootAMX(conn);
final WaitForDomainRootListenerCallback drCallback = new WaitForDomainRootListenerCallback(conn);
listenForDomainRoot(conn, drCallback);
drCallback.await();
invokeWaitAMXReady(conn, domainRoot);
}
else
{
invokeWaitAMXReady(conn, domainRoot );
}
return domainRoot;
}
private MemoryStatistic collectMemoryStatistics(Map<String, String> options) throws Exception
{
String host = options.get(JMX_HOST_ARG);
String port = options.get(JMX_PORT_ARG);
String user = options.get(JMX_USER_ARG);
String password = options.get(JMX_USER_PASSWORD_ARG);
if (!"".equals(host) && !"".equals(port) && !"".equals(user) && !"".equals(password))
{
Map<String, Object> environment = Collections.<String, Object>singletonMap(JMXConnector.CREDENTIALS, new String[]{user, password});
try(JMXConnector jmxConnector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL("rmi", "", 0, "/jndi/rmi://" + host + ":" + port + "/jmxrmi"), environment))
{
jmxConnector.connect();
final MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection();
final ObjectName memoryMBean = new ObjectName("java.lang:type=Memory");
String gcCollectorMBeanName = options.get(JMX_GARBAGE_COLLECTOR_MBEAN);
if (gcCollectorMBeanName.equals(""))
{
mBeanServerConnection.invoke(memoryMBean, "gc", null, null);
MemoryStatistic memoryStatistics = new MemoryStatistic();
collectMemoryStatistics(memoryStatistics, mBeanServerConnection, memoryMBean);
return memoryStatistics;
}
else
{
ObjectName gcMBean = new ObjectName(gcCollectorMBeanName);
if (mBeanServerConnection.isRegistered(gcMBean))
{
return collectMemoryStatisticsAfterGCNotification(mBeanServerConnection, gcMBean);
}
else
{
Set<ObjectName> existingGCs = mBeanServerConnection.queryNames(new ObjectName("java.lang:type=GarbageCollector,name=*"), null);
throw new IllegalArgumentException("MBean '" +gcCollectorMBeanName + "' does not exists! Registered GC MBeans :" + existingGCs);
}
}
}
}
return null;
}