Java Code Examples for javax.management.MBeanServerConnection.isRegistered()

The following are Jave code examples for showing how to use isRegistered() of the javax.management.MBeanServerConnection class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: sstable-adaptor   File: ThreadPoolMetrics.java   View Source Code Vote up 5 votes
public static Object getJmxMetric(MBeanServerConnection mbeanServerConn, String jmxPath, String poolName, String metricName)
{
    String name = String.format("org.apache.cassandra.metrics:type=ThreadPools,path=%s,scope=%s,name=%s", jmxPath, poolName, metricName);

    try
    {
        ObjectName oName = new ObjectName(name);
        if (!mbeanServerConn.isRegistered(oName))
        {
            return "N/A";
        }

        switch (metricName)
        {
            case "ActiveTasks":
            case "PendingTasks":
            case "CompletedTasks":
                return JMX.newMBeanProxy(mbeanServerConn, oName, JmxReporter.JmxGaugeMBean.class).getValue();
            case "TotalBlockedTasks":
            case "CurrentlyBlockedTasks":
                return JMX.newMBeanProxy(mbeanServerConn, oName, JmxReporter.JmxCounterMBean.class).getCount();
            default:
                throw new AssertionError("Unknown metric name " + metricName);
        }
    }
    catch (Exception e)
    {
        throw new RuntimeException("Error reading: " + name, e);
    }
}
 
Example 2
Project: OpenJSharp   File: AMXGlassfish.java   View Source Code Vote up 5 votes
/**
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;
}
 
Example 3
Project: jdk8u-jdk   File: MXBeanInteropTest1.java   View Source Code Vote up 5 votes
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 ;
}
 
Example 4
Project: openjdk-jdk10   File: MXBeanInteropTest1.java   View Source Code Vote up 5 votes
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 ;
}
 
Example 5
Project: openjdk-jdk10   File: AMXGlassfish.java   View Source Code Vote up 5 votes
/**
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;
}
 
Example 6
Project: openjdk-jdk10   File: MBeanListener.java   View Source Code Vote up 5 votes
private boolean isRegistered( final MBeanServerConnection conn, final ObjectName objectName )
{
    try
    {
        return conn.isRegistered(objectName);
    }
    catch (final Exception e)
    {
        throw new RuntimeException(e);
    }
}
 
Example 7
Project: OpenJSharp   File: MBeanListener.java   View Source Code Vote up 4 votes
private boolean isRegistered( final MBeanServerConnection conn, final ObjectName objectName )
{
    try
    {
        return conn.isRegistered(objectName);
    }
    catch (final Exception e)
    {
        throw new RuntimeException(e);
    }
}