类javax.management.NotCompliantMBeanException源码实例Demo

下面列出了怎么用javax.management.NotCompliantMBeanException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jdk8u-jdk   文件: MBeanServerAccessController.java
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className, ObjectName name)
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name);
    }
}
 
源代码2 项目: tlaplus   文件: AbstractBucketStatistics.java
/**
 * @param aTitle
 *            A title for console pretty printing
 * @param pkg
 *            A package name for this statistics, e.g. tlc2.tool.liveness
 *            for stats are from classes in the liveness package.
 * @param name
 *            The (class) name of the source of the statistics.
 */
public AbstractBucketStatistics(final String aTitle, final String pkg, final String name) {
	this(aTitle);
	try {
		//TODO unregister somehow
		new BucketStatisticsMXWrapper(this, name, pkg);
	} catch (NotCompliantMBeanException e) {
		// not expected to happen would cause JMX to be broken, hence just log and
		// continue
		MP.printWarning(
				EC.GENERAL,
				"Failed to create MBean wrapper for BucketStatistics. No statistics/metrics will be avaiable.",
				e);
		TLCStandardMBean.getNullTLCStandardMBean();
	}
}
 
源代码3 项目: openjdk-8-source   文件: ManagementFactory.java
/**
 * Registers a DynamicMBean.
 */
private static void addDynamicMBean(final MBeanServer mbs,
                                    final DynamicMBean dmbean,
                                    final ObjectName on) {
    try {
        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
            @Override
            public Void run() throws InstanceAlreadyExistsException,
                                     MBeanRegistrationException,
                                     NotCompliantMBeanException {
                mbs.registerMBean(dmbean, on);
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
        throw new RuntimeException(e.getException());
    }
}
 
private static String getNewMBeanClassName(Object mbeanToRegister)
        throws NotCompliantMBeanException {
    if (mbeanToRegister instanceof DynamicMBean) {
        DynamicMBean mbean = (DynamicMBean) mbeanToRegister;
        final String name;
        try {
            name = mbean.getMBeanInfo().getClassName();
        } catch (Exception e) {
            // Includes case where getMBeanInfo() returns null
            NotCompliantMBeanException ncmbe =
                new NotCompliantMBeanException("Bad getMBeanInfo()");
            ncmbe.initCause(e);
            throw ncmbe;
        }
        if (name == null) {
            final String msg = "MBeanInfo has null class name";
            throw new NotCompliantMBeanException(msg);
        }
        return name;
    } else
        return mbeanToRegister.getClass().getName();
}
 
源代码5 项目: jdk8u-dev-jdk   文件: RoleInfo.java
/**
 * Constructor.
 *
 * @param roleName  name of the role
 * @param mbeanClassName  name of the class of MBean(s) expected to
 * be referenced in corresponding role.  If an MBean <em>M</em> is in
 * this role, then the MBean server must return true for
 * {@link MBeanServer#isInstanceOf isInstanceOf(M, mbeanClassName)}.
 *
 * <P>IsReadable and IsWritable defaulted to true.
 * <P>Minimum and maximum degrees defaulted to 1.
 * <P>Description of role defaulted to null.
 *
 * @exception IllegalArgumentException  if null parameter
 * @exception ClassNotFoundException As of JMX 1.2, this exception
 * can no longer be thrown.  It is retained in the declaration of
 * this class for compatibility with existing code.
 * @exception NotCompliantMBeanException As of JMX 1.2, this
 * exception can no longer be thrown.  It is retained in the
 * declaration of this class for compatibility with existing code.
  */
public RoleInfo(String roleName,
                String mbeanClassName)
throws IllegalArgumentException,
       ClassNotFoundException,
       NotCompliantMBeanException {

    try {
        init(roleName,
             mbeanClassName,
             true,
             true,
             1,
             1,
             null);
    } catch (InvalidRoleInfoException exc) {
        // OK : Can never happen as the minimum
        //      degree equals the maximum degree.
    }

    return;
}
 
public ObjectInstance createMBean(String className, ObjectName name,
                                  Object[] params, String[] signature)
    throws ReflectionException, InstanceAlreadyExistsException,
           MBeanRegistrationException, MBeanException,
           NotCompliantMBeanException  {

    try {
        return createMBean(className, name, null, true,
                           params, signature);
    } catch (InstanceNotFoundException e) {
        /* Can only happen if loaderName doesn't exist, but we just
           passed null, so we shouldn't get this exception.  */
        throw EnvHelp.initCause(
            new IllegalArgumentException("Unexpected exception: " + e), e);
    }
}
 
源代码7 项目: jdk8u_jdk   文件: DefaultMBeanServerInterceptor.java
public ObjectInstance registerMBean(Object object, ObjectName name)
    throws InstanceAlreadyExistsException, MBeanRegistrationException,
    NotCompliantMBeanException  {

    // ------------------------------
    // ------------------------------
    Class<?> theClass = object.getClass();

    Introspector.checkCompliance(theClass);

    final String infoClassName = getNewMBeanClassName(object);

    checkMBeanPermission(infoClassName, null, name, "registerMBean");
    checkMBeanTrustPermission(theClass);

    return registerObject(infoClassName, object, name);
}
 
源代码8 项目: jdk8u60   文件: MBeanSupport.java
<T> MBeanSupport(T resource, Class<T> mbeanInterfaceType)
        throws NotCompliantMBeanException {
    if (mbeanInterfaceType == null)
        throw new NotCompliantMBeanException("Null MBean interface");
    if (!mbeanInterfaceType.isInstance(resource)) {
        final String msg =
            "Resource class " + resource.getClass().getName() +
            " is not an instance of " + mbeanInterfaceType.getName();
        throw new NotCompliantMBeanException(msg);
    }
    ReflectUtil.checkPackageAccess(mbeanInterfaceType);
    this.resource = resource;
    MBeanIntrospector<M> introspector = getMBeanIntrospector();
    this.perInterface = introspector.getPerInterface(mbeanInterfaceType);
    this.mbeanInfo = introspector.getMBeanInfo(resource, perInterface);
}
 
源代码9 项目: jdk8u-jdk   文件: MBeanTest.java
private static void testNonCompliant(Class<?> iface, Object bean) throws Exception {
    try {
        System.out.println("Registering a non-compliant MBean " +
                            iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=NonCompliant");

        mbs.registerMBean(bean, on);

        fail("Registered a non-compliant MBean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            success("MBean not registered");
        } else {
            throw e;
        }
    }
}
 
源代码10 项目: openjdk-jdk9   文件: MBeanFallbackTest.java
private static void testPrivate(Class<?> iface, Object bean) throws Exception {
    try {
        System.out.println("Registering a private MBean " +
                            iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=Compliant");

        mbs.registerMBean(bean, on);
        success("Registered a private MBean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("MBean not registered");
        } else {
            throw e;
        }
    }
}
 
源代码11 项目: openjdk-8   文件: MBeanServerAccessController.java
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className, ObjectName name)
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name);
    }
}
 
源代码12 项目: openjdk-jdk9   文件: MBeanTest.java
private static void testCompliant(Class<?> iface, Object bean) throws Exception {
    try {
        System.out.println("Registering a compliant MBean " +
                            iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=Compliant");

        mbs.registerMBean(bean, on);
        success("Registered a compliant MBean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("MBean not registered");
        } else {
            throw e;
        }
    }
}
 
private static String getNewMBeanClassName(Object mbeanToRegister)
        throws NotCompliantMBeanException {
    if (mbeanToRegister instanceof DynamicMBean) {
        DynamicMBean mbean = (DynamicMBean) mbeanToRegister;
        final String name;
        try {
            name = mbean.getMBeanInfo().getClassName();
        } catch (Exception e) {
            // Includes case where getMBeanInfo() returns null
            NotCompliantMBeanException ncmbe =
                new NotCompliantMBeanException("Bad getMBeanInfo()");
            ncmbe.initCause(e);
            throw ncmbe;
        }
        if (name == null) {
            final String msg = "MBeanInfo has null class name";
            throw new NotCompliantMBeanException(msg);
        }
        return name;
    } else
        return mbeanToRegister.getClass().getName();
}
 
源代码14 项目: openjdk-8-source   文件: MBeanTest.java
private static void testCompliant(Class<?> iface, Object bean) throws Exception {
    try {
        System.out.println("Registering a compliant MBean " +
                            iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=Compliant");

        mbs.registerMBean(bean, on);
        success("Registered a compliant MBean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("MBean not registered");
        } else {
            throw e;
        }
    }
}
 
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className, ObjectName name,
                                  Object params[], String signature[])
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className,
                                                     params,
                                                     signature);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name,
                                            params, signature);
    }
}
 
源代码16 项目: openjdk-jdk8u-backup   文件: ManagementFactory.java
/**
 * Registers a DynamicMBean.
 */
private static void addDynamicMBean(final MBeanServer mbs,
                                    final DynamicMBean dmbean,
                                    final ObjectName on) {
    try {
        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
            @Override
            public Void run() throws InstanceAlreadyExistsException,
                                     MBeanRegistrationException,
                                     NotCompliantMBeanException {
                mbs.registerMBean(dmbean, on);
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
        throw new RuntimeException(e.getException());
    }
}
 
private static String getNewMBeanClassName(Object mbeanToRegister)
        throws NotCompliantMBeanException {
    if (mbeanToRegister instanceof DynamicMBean) {
        DynamicMBean mbean = (DynamicMBean) mbeanToRegister;
        final String name;
        try {
            name = mbean.getMBeanInfo().getClassName();
        } catch (Exception e) {
            // Includes case where getMBeanInfo() returns null
            NotCompliantMBeanException ncmbe =
                new NotCompliantMBeanException("Bad getMBeanInfo()");
            ncmbe.initCause(e);
            throw ncmbe;
        }
        if (name == null) {
            final String msg = "MBeanInfo has null class name";
            throw new NotCompliantMBeanException(msg);
        }
        return name;
    } else
        return mbeanToRegister.getClass().getName();
}
 
源代码18 项目: jdk8u-dev-jdk   文件: MBeanFallbackTest.java
private static void testPrivate(Class<?> iface, Object bean) throws Exception {
    try {
        System.out.println("Registering a private MBean " +
                            iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=Compliant");

        mbs.registerMBean(bean, on);
        success("Registered a private MBean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("MBean not registered");
        } else {
            throw e;
        }
    }
}
 
源代码19 项目: TencentKona-8   文件: ManagementFactory.java
/**
 * Registers a DynamicMBean.
 */
private static void addDynamicMBean(final MBeanServer mbs,
                                    final DynamicMBean dmbean,
                                    final ObjectName on) {
    try {
        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
            @Override
            public Void run() throws InstanceAlreadyExistsException,
                                     MBeanRegistrationException,
                                     NotCompliantMBeanException {
                mbs.registerMBean(dmbean, on);
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
        throw new RuntimeException(e.getException());
    }
}
 
源代码20 项目: dragonwell8_jdk   文件: ManagementFactory.java
/**
 * Registers a DynamicMBean.
 */
private static void addDynamicMBean(final MBeanServer mbs,
                                    final DynamicMBean dmbean,
                                    final ObjectName on) {
    try {
        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
            @Override
            public Void run() throws InstanceAlreadyExistsException,
                                     MBeanRegistrationException,
                                     NotCompliantMBeanException {
                mbs.registerMBean(dmbean, on);
                return null;
            }
        });
    } catch (PrivilegedActionException e) {
        throw new RuntimeException(e.getException());
    }
}
 
源代码21 项目: openjdk-8   文件: MBeanTest.java
private static void testNonCompliant(Class<?> iface, Object bean) throws Exception {
    try {
        System.out.println("Registering a non-compliant MBean " +
                            iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=NonCompliant");

        mbs.registerMBean(bean, on);

        fail("Registered a non-compliant MBean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            success("MBean not registered");
        } else {
            throw e;
        }
    }
}
 
源代码22 项目: jdk8u60   文件: DefaultMBeanServerInterceptor.java
public ObjectInstance registerMBean(Object object, ObjectName name)
    throws InstanceAlreadyExistsException, MBeanRegistrationException,
    NotCompliantMBeanException  {

    // ------------------------------
    // ------------------------------
    Class<?> theClass = object.getClass();

    Introspector.checkCompliance(theClass);

    final String infoClassName = getNewMBeanClassName(object);

    checkMBeanPermission(infoClassName, null, name, "registerMBean");
    checkMBeanTrustPermission(theClass);

    return registerObject(infoClassName, object, name);
}
 
源代码23 项目: openjdk-jdk8u   文件: JMXProxyFallbackTest.java
private static void testPrivate(Class<?> iface) throws Exception {
    try {
        System.out.println("Creating a proxy for private M(X)Bean " +
                            iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=Proxy");

        JMX.newMBeanProxy(mbs, on, iface);
        success("Created a proxy for private M(X)Bean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("Proxy not created");
        } else {
            throw e;
        }
    }
}
 
public static void main(String[] args) throws MalformedObjectNameException, InterruptedException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
    //Get the MBean server
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    //register the MBean
    SystemConfig mBean = new SystemConfig(DEFAULT_NO_THREADS, DEFAULT_SCHEMA);
    ObjectName name = new ObjectName("net.aimeizi.jmx.example:type=SystemConfig");
    mbs.registerMBean(mBean, name);
    do{
        Thread.sleep(3000);
        System.out.println("Thread Count="+mBean.getThreadCount()+":::Schema Name="+mBean.getSchemaName());
    }while(mBean.getThreadCount() !=0);
     
}
 
源代码25 项目: brooklyn-server   文件: JmxService.java
public StandardEmitterMBean registerMBean(List<String> notifications, String name) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, MalformedObjectNameException, NullPointerException {
    String[] types = notifications.toArray(new String[0]);
    MBeanNotificationInfo info = new MBeanNotificationInfo(types, Notification.class.getName(), "Notification");
    NotificationEmitter emitter = new NotificationBroadcasterSupport(info);
    StandardEmitterMBean mbean = new StandardEmitterMBean(emitter, NotificationEmitter.class, emitter);
    server.registerMBean(mbean, new ObjectName(name));
    return mbean;
}
 
源代码26 项目: spring-analysis-note   文件: MBeanExporter.java
/**
 * Build an adapted MBean for the given bean instance, if possible.
 * <p>The default implementation builds a JMX 1.2 StandardMBean
 * for the target's MBean/MXBean interface in case of an AOP proxy,
 * delegating the interface's management operations to the proxy.
 * @param bean the original bean instance
 * @return the adapted MBean, or {@code null} if not possible
 */
@SuppressWarnings("unchecked")
@Nullable
protected DynamicMBean adaptMBeanIfPossible(Object bean) throws JMException {
	Class<?> targetClass = AopUtils.getTargetClass(bean);
	if (targetClass != bean.getClass()) {
		Class<?> ifc = JmxUtils.getMXBeanInterface(targetClass);
		if (ifc != null) {
			if (!ifc.isInstance(bean)) {
				throw new NotCompliantMBeanException("Managed bean [" + bean +
						"] has a target class with an MXBean interface but does not expose it in the proxy");
			}
			return new StandardMBean(bean, ((Class<Object>) ifc), true);
		}
		else {
			ifc = JmxUtils.getMBeanInterface(targetClass);
			if (ifc != null) {
				if (!ifc.isInstance(bean)) {
					throw new NotCompliantMBeanException("Managed bean [" + bean +
							"] has a target class with an MBean interface but does not expose it in the proxy");
				}
				return new StandardMBean(bean, ((Class<Object>) ifc));
			}
		}
	}
	return null;
}
 
源代码27 项目: jdk8u60   文件: JMXProxyTest.java
private static void testCompliant(Class<?> iface, boolean isMx) throws Exception {
    try {
        System.out.println("Creating a proxy for compliant " +
                           (isMx ? "MXBean" : "MBean") + " " +
                           iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=Proxy");

        if (isMx) {
            JMX.newMXBeanProxy(mbs, on, iface);
        } else {
            JMX.newMBeanProxy(mbs, on, iface);
        }
        success("Created a proxy for compliant " +
                (isMx ? "MXBean" : "MBean") + " - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("Proxy not created");
        } else {
            throw e;
        }
    }
}
 
源代码28 项目: openjdk-8-source   文件: OldMBeanServerTest.java
public ObjectInstance createMBean(
        String className, ObjectName name, ObjectName loaderName)
throws ReflectionException, InstanceAlreadyExistsException,
        MBeanRegistrationException, MBeanException,
        NotCompliantMBeanException, InstanceNotFoundException {
    return createMBean(className, name, loaderName, null, null);
}
 
源代码29 项目: openjdk-8-source   文件: RMIConnector.java
public ObjectInstance createMBean(String className,
        ObjectName name,
        ObjectName loaderName)
        throws ReflectionException,
        InstanceAlreadyExistsException,
        MBeanRegistrationException,
        MBeanException,
        NotCompliantMBeanException,
        InstanceNotFoundException,
        IOException {

    if (logger.debugOn())
        logger.debug("createMBean(String,ObjectName,ObjectName)",
                "className=" + className + ", name="
                + name + ", loaderName="
                + loaderName + ")");

    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.createMBean(className,
                name,
                loaderName,
                delegationSubject);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.createMBean(className,
                name,
                loaderName,
                delegationSubject);

    } finally {
        popDefaultClassLoader(old);
    }
}
 
源代码30 项目: jdk8u_jdk   文件: DefaultMBeanServerInterceptor.java
public ObjectInstance createMBean(String className, ObjectName name)
    throws ReflectionException, InstanceAlreadyExistsException,
           MBeanRegistrationException, MBeanException,
           NotCompliantMBeanException {

    return createMBean(className, name, (Object[]) null, (String[]) null);

}
 
 类所在包
 类方法
 同包方法