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


Java StandardMBean类代码示例

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


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

示例1: adaptMBeanIfPossible

import javax.management.StandardMBean; //导入依赖的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

示例2: createStandardMBean

import javax.management.StandardMBean; //导入依赖的package包/类
/**
 * Instantiates and registers a StandardMBean in the MBean server.
 *
 * @param implementationClassName
 *      The implementation class name of the MBean.
 * @param interfaceClassName
 *      The management interface class name of the MBean.
 * @param isMXBean
 *      If true, the resultant MBean is an MXBean.
 * @param name
 *      The object name of the StandardMBean.
 */
@SuppressWarnings("unchecked")
public void createStandardMBean(
        String implementationClassName,
        String interfaceClassName,
        boolean isMXBean,
        ObjectName name)
        throws Exception {

    Object implementation =
            Class.forName(implementationClassName).newInstance();
    Class<Object> interfaceClass = interfaceClassName == null ? null :
        (Class<Object>)Class.forName(interfaceClassName);

    // Create the StandardMBean
    StandardMBean standardMBean = new StandardMBean(
            implementation,
            interfaceClass,
            isMXBean);

    // Register the StandardMBean
    mbeanServer.registerMBean(standardMBean, name);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:ServerDelegate.java

示例3: main

import javax.management.StandardMBean; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    final Child child = new Child();
    test(child,"Child[MBean]",false);
    final ChildMix childx = new ChildMix();
    test(childx,"ChildMix[MXBean]",true);
    final ChildMixMix childmx = new ChildMixMix();
    test(childmx,"ChildMixMix[MXBean]",false);
    final StandardMBean schild = new StandardMBean(child,ChildMBean.class);
    test(schild,"Child[StandarMBean(Child)]",false);
    final StandardMBean schildx =
            new StandardMBean(childx,ChildMXBean.class,true);
    test(schildx,"ChildMix[StandarMXBean(ChildMix)]",true);
    final StandardMBean schildmx =
            new StandardMBean(childmx,ChildMixMXBean.class,true);
    test(schildmx,"ChildMixMix[StandarMXBean(ChildMixMix)]",true);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:TooManyFooTest.java

示例4: adaptMBeanIfPossible

import javax.management.StandardMBean; //导入依赖的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<Object> ifc = (Class<Object>) 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, ifc, true);
		}
		else {
			ifc = (Class<Object>) 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, ifc);
			}
		}
	}
	return null;
}
 
开发者ID:panguixiang,项目名称:my-spring-cache-redis,代码行数:34,代码来源:MBeanExporter.java

示例5: boot

import javax.management.StandardMBean; //导入依赖的package包/类
/**
 * Start the management service if gemfirexd.system.jmx is true.
 * <P>
 * Starting the service means:
 * <UL>
 * <LI> getting the platform MBeanServer which may require starting it
 * <LI> registering a Version mbean representing the system
 * </UL>
 */
public synchronized void boot(boolean create, Properties properties)
        throws StandardException {
    
    registeredMbeans = new HashMap<ObjectName,StandardMBean>();
    
    systemIdentifier =
        Monitor.getMonitor().getUUIDFactory().createUUID().toString();
    
    findServer();
         
    myManagementBean = (ObjectName) registerMBean(this,
            ManagementMBean.class,
            "type=Management");
    myManagementServer = mbeanServer;
    
    registerMBean(
            new Version(
                    Monitor.getMonitor().getEngineVersion(),
                    SystemPermission.ENGINE),
            VersionMBean.class,
            "type=Version,jar=gemfirexd.jar");
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:32,代码来源:JMXManagementService.java

示例6: serviceStart

import javax.management.StandardMBean; //导入依赖的package包/类
@Override
protected void serviceStart() throws Exception {
  String uuid = UUID.randomUUID().toString();
  tmpDir = Paths.get(SYSTEM_TMP, LOCALIZATION_DIR).toFile();
  if (!tmpDir.exists()) {
    tmpDir.mkdir();
  }
  tmpDir.setExecutable(false, false);
  tmpDir.setExecutable(true);
  // Writable only to the owner
  tmpDir.setWritable(false, false);
  tmpDir.setWritable(true);
  // Readable by none
  tmpDir.setReadable(false, false);
  
  materializeDir = Paths.get(tmpDir.getAbsolutePath(), uuid);
  // Random materialization directory should have the default umask
  materializeDir.toFile().mkdir();
  LOG.debug("Initialized at dir: " + materializeDir.toString());

  StandardMBean mbean = new StandardMBean(this, CertificateLocalizationMBean.class);
  mbeanObjectName = MBeans.register(serviceName, "CertificateLocalizer", mbean);
  
  super.serviceStart();
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:26,代码来源:CertificateLocalizationService.java

示例7: start

import javax.management.StandardMBean; //导入依赖的package包/类
@Override
public void start(final ModuleContext context) throws Exception {
    MBeanServer server = ServiceLocator.getRequiredService(context, MBeanServer.class);
    ModuleStateA moduleState = new ModuleStateA() {

        @Override
        public String getResourceIdentity() {
            return context.getModule().getIdentity().getCanonicalForm();
        }

        @Override
        public String getModuleState() {
            return context.getModule().getState().toString();
        }
    };
    StandardMBean mbean = new StandardMBean(moduleState, ModuleStateA.class);
    server.registerMBean(mbean, getObjectName(context.getModule()));
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:19,代码来源:ModuleActivatorA.java

示例8: registerJMX

import javax.management.StandardMBean; //导入依赖的package包/类
protected void registerJMX() {
    // register with jmx
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {
        String cName = this.getClass().getName();
        if (cName.indexOf('.') != -1) {
            cName = cName.substring(cName.lastIndexOf('.')).replaceFirst("[\\.]", "");
        }
        oName = new ObjectName(String.format("org.red5.server:type=%s,name=%s", cName, name));
        // don't reregister
        if (!mbs.isRegistered(oName)) {
            mbs.registerMBean(new StandardMBean(this, ScopeMXBean.class, true), oName);
        }
    } catch (Exception e) {
        log.warn("Error on jmx registration", e);
    }
}
 
开发者ID:Red5,项目名称:red5-server-common,代码行数:18,代码来源:Scope.java

示例9: registerJMX

import javax.management.StandardMBean; //导入依赖的package包/类
protected void registerJMX() {
    // register with jmx
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {
        String cName = this.getClass().getName();
        if (cName.indexOf('.') != -1) {
            cName = cName.substring(cName.lastIndexOf('.')).replaceFirst("[\\.]", "");
        }
        String hostStr = host;
        int port = 1935;
        if (host != null && host.indexOf(":") > -1) {
            String[] arr = host.split(":");
            hostStr = arr[0];
            port = Integer.parseInt(arr[1]);
        }
        // Create a new mbean for this instance
        oName = new ObjectName(String.format("org.red5.server:type=%s,connectionType=%s,host=%s,port=%d,clientId=%s", cName, type, hostStr, port, client.getId()));
        if (!mbs.isRegistered(oName)) {
            mbs.registerMBean(new StandardMBean(this, RTMPMinaConnectionMXBean.class, true), oName);
        } else {
            log.debug("Connection is already registered in JMX");
        }
    } catch (Exception e) {
        log.warn("Error on jmx registration", e);
    }
}
 
开发者ID:Red5,项目名称:red5-server-common,代码行数:27,代码来源:RTMPMinaConnection.java

示例10: testProxy

import javax.management.StandardMBean; //导入依赖的package包/类
public void testProxy() throws Exception {
    ObjectName n = new ObjectName("foo:id=" + UUID.randomUUID().toString());
    Impl s = new Impl();
    server.registerMBean(new StandardMBean(s, Ifc1.class), n);

    Ifc1 s1 = MBeanUtils.createProxy(getClass().getClassLoader(), n, Ifc1.class);
    assertNotNull(s1);
    assertEquals(s.foo, s1.getfoo());
    assertEquals(s.bar, s1.getBar());
    assertEquals("ab", s1.cat("a", "b"));

    Ifc1 s2 = MBeanUtils.createProxy(getClass().getClassLoader(), n, Ifc1.class);
    assertNotNull(s2);
    assertEquals(s.foo, s2.getfoo());
    assertEquals(s.bar, s2.getBar());
    assertEquals("ab", s2.cat("a", "b"));
}
 
开发者ID:addthis,项目名称:basis,代码行数:18,代码来源:MBeanUtilsTest.java

示例11: registerNewMBean

import javax.management.StandardMBean; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public static boolean registerNewMBean(Class clazz, Class interfaceClass) {
    boolean status = false;
    try {
        String cName = clazz.getName();
        if (cName.indexOf('.') != -1) {
            cName = cName.substring(cName.lastIndexOf('.')).replaceFirst("[\\.]", "");
        }
        log.debug("Register name: {}", cName);
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        mbs.registerMBean(new StandardMBean(Class.forName(clazz.getName()).newInstance(), interfaceClass), new ObjectName("org.red5.server:type=" + cName));
        status = true;
    } catch (Exception e) {
        log.error("Could not register the {} MBean", clazz.getName(), e);
    }
    return status;
}
 
开发者ID:Red5,项目名称:red5-server,代码行数:18,代码来源:JMXUtil.java

示例12: registerNewMBean

import javax.management.StandardMBean; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public static boolean registerNewMBean(Class clazz, Class interfaceClass) {
	boolean status = false;
	try {
		String cName = clazz.getName();
		if (cName.indexOf('.') != -1) {
			cName = cName.substring(cName.lastIndexOf('.')).replaceFirst("[\\.]", "");
		}
		log.debug("Register name: {}", cName);
		MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
		mbs.registerMBean(new StandardMBean(Class.forName(clazz.getName()).newInstance(), interfaceClass), new ObjectName("org.red5.server:type=" + cName));
		status = true;
	} catch (Exception e) {
		log.error("Could not register the {} MBean", clazz.getName(), e);
	}
	return status;
}
 
开发者ID:cwpenhale,项目名称:red5-mobileconsole,代码行数:18,代码来源:JMXUtil.java

示例13: registerJMX

import javax.management.StandardMBean; //导入依赖的package包/类
protected void registerJMX() {
	// register with jmx
	MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
	try {
		String cName = this.getClass().getName();
		if (cName.indexOf('.') != -1) {
			cName = cName.substring(cName.lastIndexOf('.')).replaceFirst("[\\.]", "");
		}
		oName = new ObjectName(String.format("org.red5.server:type=%s,name=%s", cName, name));
		// don't reregister
		if (!mbs.isRegistered(oName)) {
			mbs.registerMBean(new StandardMBean(this, ScopeMXBean.class, true), oName);
		}
	} catch (Exception e) {
		log.warn("Error on jmx registration", e);
	}
}
 
开发者ID:cwpenhale,项目名称:red5-mobileconsole,代码行数:18,代码来源:Scope.java

示例14: registerJMX

import javax.management.StandardMBean; //导入依赖的package包/类
protected void registerJMX() {
	// register with jmx
	MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
	try {
		String cName = this.getClass().getName();
		if (cName.indexOf('.') != -1) {
			cName = cName.substring(cName.lastIndexOf('.')).replaceFirst("[\\.]", "");
		}
		String hostStr = host;
		int port = 1935;
		if (host != null && host.indexOf(":") > -1) {
			String[] arr = host.split(":");
			hostStr = arr[0];
			port = Integer.parseInt(arr[1]);
		}
		// Create a new mbean for this instance
		oName = new ObjectName(String.format("org.red5.server:type=%s,connectionType=%s,host=%s,port=%d,clientId=%s", cName, type, hostStr, port, client.getId()));
		if (!mbs.isRegistered(oName)) {
			mbs.registerMBean(new StandardMBean(this, RTMPMinaConnectionMXBean.class, true), oName);
		} else {
			log.debug("Connection is already registered in JMX");
		}
	} catch (Exception e) {
		log.warn("Error on jmx registration", e);
	}
}
 
开发者ID:cwpenhale,项目名称:red5-mobileconsole,代码行数:27,代码来源:RTMPMinaConnection.java

示例15: registerOrGetJmxBean

import javax.management.StandardMBean; //导入依赖的package包/类
private RedisThrottlerJmxBean registerOrGetJmxBean() {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {
        synchronized (jmxBeanReferenceCountByName) {

            // Get the reference count for the JMX bean.
            Integer jmxBeanReferenceCount = jmxBeanReferenceCountByName.get(jmxBeanName);
            if (jmxBeanReferenceCount == null) {
                jmxBeanReferenceCount = 0;
            }

            // Create or get the JMX bean.
            RedisThrottlerJmxBean jmxBean;
            try {
                jmxBean = new RedisThrottlerInternalJmxBean();
                StandardMBean jmxBeanWrapper = new StandardMBean(jmxBean, RedisThrottlerJmxBean.class);
                mbs.registerMBean(jmxBeanWrapper, jmxBeanName);
            } catch (InstanceAlreadyExistsException ignored) {
                jmxBean = JMX.newMBeanProxy(mbs, jmxBeanName, RedisThrottlerJmxBean.class);
            }

            // Increment the reference count and return the JMX bean.
            jmxBeanReferenceCountByName.put(jmxBeanName, jmxBeanReferenceCount + 1);
            return jmxBean;

        }
    } catch (Throwable error) {
        String message = String.format("failed accessing the JMX bean (jmxBeanName=%s)", jmxBeanName);
        throw new RuntimeException(message, error);
    }
}
 
开发者ID:vy,项目名称:log4j2-redis-appender,代码行数:32,代码来源:RedisThrottler.java


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