当前位置: 首页>>代码示例>>Java>>正文


Java DynamicMBean类代码示例

本文整理汇总了Java中javax.management.DynamicMBean的典型用法代码示例。如果您正苦于以下问题:Java DynamicMBean类的具体用法?Java DynamicMBean怎么用?Java DynamicMBean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DynamicMBean类属于javax.management包,在下文中一共展示了DynamicMBean类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: invoke

import javax.management.DynamicMBean; //导入依赖的package包/类
public Object invoke(ObjectName name, String operationName,
                     Object params[], String signature[])
        throws InstanceNotFoundException, MBeanException,
               ReflectionException {

    name = nonDefaultDomain(name);

    DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, operationName, name, "invoke");
    try {
        return instance.invoke(operationName, params, signature);
    } catch (Throwable t) {
        rethrowMaybeMBeanException(t);
        throw new AssertionError();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:DefaultMBeanServerInterceptor.java

示例2: createMBean

import javax.management.DynamicMBean; //导入依赖的package包/类
/**
 * Create, register, and return an MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment The ContextEnvironment to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public static DynamicMBean createMBean(ContextEnvironment environment)
    throws Exception {

    String mname = createManagedName(environment);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(environment);
    ObjectName oname = createObjectName(domain, environment);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:30,代码来源:MBeanUtils.java

示例3: createMBean

import javax.management.DynamicMBean; //导入依赖的package包/类
/**
 * Create, register, and return an MBean for this <code>Role</code> object.
 *
 * @param role
 *            The Role to be managed
 *
 * @exception Exception
 *                if an MBean cannot be created or registered
 */
static DynamicMBean createMBean(Role role) throws Exception {

	String mname = createManagedName(role);
	ManagedBean managed = registry.findManagedBean(mname);
	if (managed == null) {
		Exception e = new Exception("ManagedBean is not found with " + mname);
		throw new MBeanException(e);
	}
	String domain = managed.getDomain();
	if (domain == null)
		domain = mserver.getDefaultDomain();
	DynamicMBean mbean = managed.createMBean(role);
	ObjectName oname = createObjectName(domain, role);
	if (mserver.isRegistered(oname)) {
		mserver.unregisterMBean(oname);
	}
	mserver.registerMBean(mbean, oname);
	return (mbean);

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:30,代码来源:MBeanUtils.java

示例4: adaptMBeanIfPossible

import javax.management.DynamicMBean; //导入依赖的package包/类
/**
 * 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")
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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:MBeanExporter.java

示例5: createMBean

import javax.management.DynamicMBean; //导入依赖的package包/类
/**
 * Create, register, and return an MBean for this
 * <code>Connector</code> object.
 *
 * @param connector The Connector to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
static DynamicMBean createMBean(Connector connector)
    throws Exception {

    String mname = createManagedName(connector);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(connector);
    ObjectName oname = createObjectName(domain, connector);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:MBeanUtils.java

示例6: getNewMBeanClassName

import javax.management.DynamicMBean; //导入依赖的package包/类
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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:DefaultMBeanServerInterceptor.java

示例7: postRegister

import javax.management.DynamicMBean; //导入依赖的package包/类
private static void postRegister(
        ObjectName logicalName, DynamicMBean mbean,
        boolean registrationDone, boolean registerFailed) {

    if (registerFailed && mbean instanceof DynamicMBean2)
        ((DynamicMBean2) mbean).registerFailed();
    try {
        if (mbean instanceof MBeanRegistration)
            ((MBeanRegistration) mbean).postRegister(registrationDone);
    } catch (RuntimeException e) {
        MBEANSERVER_LOGGER.log(Level.DEBUG, "While registering MBean ["+logicalName+
                "]: " + "Exception thrown by postRegister: " +
                "rethrowing <"+e+">, but keeping the MBean registered");
        throw new RuntimeMBeanException(e,
                  "RuntimeException thrown in postRegister method: "+
                  "rethrowing <"+e+">, but keeping the MBean registered");
    } catch (Error er) {
        MBEANSERVER_LOGGER.log(Level.DEBUG, "While registering MBean ["+logicalName+
                "]: " + "Error thrown by postRegister: " +
                "rethrowing <"+er+">, but keeping the MBean registered");
        throw new RuntimeErrorException(er,
                  "Error thrown in postRegister method: "+
                  "rethrowing <"+er+">, but keeping the MBean registered");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:DefaultMBeanServerInterceptor.java

示例8: preRegister

import javax.management.DynamicMBean; //导入依赖的package包/类
private static ObjectName preRegister(
        DynamicMBean mbean, MBeanServer mbs, ObjectName name)
        throws InstanceAlreadyExistsException, MBeanRegistrationException {

    ObjectName newName = null;

    try {
        if (mbean instanceof MBeanRegistration)
            newName = ((MBeanRegistration) mbean).preRegister(mbs, name);
    } catch (Throwable t) {
        throwMBeanRegistrationException(t, "in preRegister method");
    }

    if (newName != null) return newName;
    else return name;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:DefaultMBeanServerInterceptor.java

示例9: postRegister

import javax.management.DynamicMBean; //导入依赖的package包/类
private static void postRegister(
        ObjectName logicalName, DynamicMBean mbean,
        boolean registrationDone, boolean registerFailed) {

    if (registerFailed && mbean instanceof DynamicMBean2)
        ((DynamicMBean2) mbean).registerFailed();
    try {
        if (mbean instanceof MBeanRegistration)
            ((MBeanRegistration) mbean).postRegister(registrationDone);
    } catch (RuntimeException e) {
        MBEANSERVER_LOGGER.fine("While registering MBean ["+logicalName+
                "]: " + "Exception thrown by postRegister: " +
                "rethrowing <"+e+">, but keeping the MBean registered");
        throw new RuntimeMBeanException(e,
                  "RuntimeException thrown in postRegister method: "+
                  "rethrowing <"+e+">, but keeping the MBean registered");
    } catch (Error er) {
        MBEANSERVER_LOGGER.fine("While registering MBean ["+logicalName+
                "]: " + "Error thrown by postRegister: " +
                "rethrowing <"+er+">, but keeping the MBean registered");
        throw new RuntimeErrorException(er,
                  "Error thrown in postRegister method: "+
                  "rethrowing <"+er+">, but keeping the MBean registered");
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:DefaultMBeanServerInterceptor.java

示例10: testReadAttributes

import javax.management.DynamicMBean; //导入依赖的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);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:22,代码来源:AbstractDynamicWrapperTest.java

示例11: getListener

import javax.management.DynamicMBean; //导入依赖的package包/类
private NotificationListener getListener(ObjectName listener)
    throws ListenerNotFoundException {
    // ----------------
    // Get listener object
    // ----------------
    DynamicMBean instance;
    try {
        instance = getMBean(listener);
    } catch (InstanceNotFoundException e) {
        throw EnvHelp.initCause(
                      new ListenerNotFoundException(e.getMessage()), e);
    }

    Object resource = getResource(instance);
    if (!(resource instanceof NotificationListener)) {
        final RuntimeException exc =
            new IllegalArgumentException(listener.getCanonicalName());
        final String msg =
            "MBean " + listener.getCanonicalName() + " does not " +
            "implement " + NotificationListener.class.getName();
        throw new RuntimeOperationsException(exc, msg);
    }
    return (NotificationListener) resource;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:DefaultMBeanServerInterceptor.java

示例12: getListenerWrapper

import javax.management.DynamicMBean; //导入依赖的package包/类
private NotificationListener getListenerWrapper(NotificationListener l,
                                                ObjectName name,
                                                DynamicMBean mbean,
                                                boolean create) {
    Object resource = getResource(mbean);
    ListenerWrapper wrapper = new ListenerWrapper(l, name, resource);
    synchronized (listenerWrappers) {
        WeakReference<ListenerWrapper> ref = listenerWrappers.get(wrapper);
        if (ref != null) {
            NotificationListener existing = ref.get();
            if (existing != null)
                return existing;
        }
        if (create) {
            ref = new WeakReference<ListenerWrapper>(wrapper);
            listenerWrappers.put(wrapper, ref);
            return wrapper;
        } else
            return null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:DefaultMBeanServerInterceptor.java

示例13: getClassLoader

import javax.management.DynamicMBean; //导入依赖的package包/类
/**
 * <p>Return the named {@link java.lang.ClassLoader}.
 * @param loaderName The ObjectName of the ClassLoader.
 * @return The named ClassLoader.
 * @exception InstanceNotFoundException if the named ClassLoader
 * is not found.
 */
public ClassLoader getClassLoader(ObjectName loaderName)
        throws InstanceNotFoundException {

    if (loaderName == null) {
        checkMBeanPermission((String) null, null, null, "getClassLoader");
        return server.getClass().getClassLoader();
    }

    DynamicMBean instance = getMBean(loaderName);
    checkMBeanPermission(instance, null, loaderName, "getClassLoader");

    Object resource = getResource(instance);

    /* Check if the given MBean is a ClassLoader */
    if (!(resource instanceof ClassLoader))
        throw new InstanceNotFoundException(loaderName.toString() +
                                            " is not a classloader");

    return (ClassLoader) resource;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:DefaultMBeanServerInterceptor.java


注:本文中的javax.management.DynamicMBean类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。