java类javax.management.JMException的实例源码

MBeanRegistry.java 文件源码 项目:fuck_zookeeper 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Unregister the MBean identified by the path.
 * @param path
 * @param bean
 */
private void unregister(String path,ZKMBeanInfo bean) throws JMException {
    if(path==null)
        return;
    if (!bean.isHidden()) {
        try {
            mBeanServer.unregisterMBean(makeObjectName(path, bean));
        } catch (JMException e) {
            LOG.warn("Failed to unregister MBean " + bean.getName());
            throw e;
        }
    }        
}
MBeanRegistry.java 文件源码 项目:fuck_zookeeper 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Unregister MBean.
 * @param bean
 */
public void unregister(ZKMBeanInfo bean) {
    if(bean==null)
        return;
    String path=mapBean2Path.get(bean);
    try {
        unregister(path,bean);
    } catch (JMException e) {
        LOG.warn("Error during unregister", e);
    }
    mapBean2Path.remove(bean);
    mapName2Bean.remove(bean.getName());
}
MBeanRegistry.java 文件源码 项目:fuck_zookeeper 阅读 22 收藏 0 点赞 0 评论 0
/**
 * Unregister all currently registered MBeans
 */
public void unregisterAll() {
    for(Map.Entry<ZKMBeanInfo,String> e: mapBean2Path.entrySet()) {
        try {
            unregister(e.getValue(), e.getKey());
        } catch (JMException e1) {
            LOG.warn("Error during unregister", e1);
        }
    }
    mapBean2Path.clear();
    mapName2Bean.clear();
}
ServerCnxnFactory.java 文件源码 项目:fuck_zookeeper 阅读 24 收藏 0 点赞 0 评论 0
public void registerConnection(ServerCnxn serverCnxn) {
    if (zkServer != null) {
        ConnectionBean jmxConnectionBean = new ConnectionBean(serverCnxn, zkServer);
        try {
            MBeanRegistry.getInstance().register(jmxConnectionBean, zkServer.jmxServerBean);
            connectionBeans.put(serverCnxn, jmxConnectionBean);
        } catch (JMException e) {
            LOG.warn("Could not register connection", e);
        }
    }

}
JmxRegister.java 文件源码 项目:incubator-ratis 阅读 15 收藏 0 点赞 0 评论 0
/** Un-register the previously registered mBean. */
public synchronized boolean unregister() throws JMException {
  if (registeredName == null) {
    return false;
  }
  ManagementFactory.getPlatformMBeanServer().unregisterMBean(registeredName);
  LOG.info("Successfully un-registered JMX Bean with object name " + registeredName);
  registeredName = null;
  return true;
}
MBeanClientInterceptor.java 文件源码 项目:lams 阅读 28 收藏 0 点赞 0 评论 0
private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation)
        throws JMException, IOException {

    String attributeName = JmxUtils.getAttributeName(pd, this.useStrictCasing);
    MBeanAttributeInfo inf = this.allowedAttributes.get(attributeName);
    // If no attribute is returned, we know that it is not defined in the
    // management interface.
    if (inf == null) {
        throw new InvalidInvocationException(
                "Attribute '" + pd.getName() + "' is not exposed on the management interface");
    }
    if (invocation.getMethod().equals(pd.getReadMethod())) {
        if (inf.isReadable()) {
            return this.serverToUse.getAttribute(this.objectName, attributeName);
        }
        else {
            throw new InvalidInvocationException("Attribute '" + attributeName + "' is not readable");
        }
    }
    else if (invocation.getMethod().equals(pd.getWriteMethod())) {
        if (inf.isWritable()) {
            this.serverToUse.setAttribute(this.objectName, new Attribute(attributeName, invocation.getArguments()[0]));
            return null;
        }
        else {
            throw new InvalidInvocationException("Attribute '" + attributeName + "' is not writable");
        }
    }
    else {
        throw new IllegalStateException(
                "Method [" + invocation.getMethod() + "] is neither a bean property getter nor a setter");
    }
}
MBeanRegistrationSupport.java 文件源码 项目:lams 阅读 16 收藏 0 点赞 0 评论 0
/**
 * Actually unregister the specified MBean from the server.
 * @param objectName the suggested ObjectName for the MBean
 */
protected void doUnregister(ObjectName objectName) {
    boolean actuallyUnregistered = false;

    synchronized (this.registeredBeans) {
        if (this.registeredBeans.remove(objectName)) {
            try {
                // MBean might already have been unregistered by an external process
                if (this.server.isRegistered(objectName)) {
                    this.server.unregisterMBean(objectName);
                    actuallyUnregistered = true;
                }
                else {
                    if (logger.isWarnEnabled()) {
                        logger.warn("Could not unregister MBean [" + objectName + "] as said MBean " +
                                "is not registered (perhaps already unregistered by an external process)");
                    }
                }
            }
            catch (JMException ex) {
                if (logger.isErrorEnabled()) {
                    logger.error("Could not unregister MBean [" + objectName + "]", ex);
                }
            }
        }
    }

    if (actuallyUnregistered) {
        onUnregister(objectName);
    }
}
MBeanExporter.java 文件源码 项目:lams 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Registers an existing MBean or an MBean adapter for a plain bean
 * with the {@code MBeanServer}.
 * @param bean the bean to register, either an MBean or a plain bean
 * @param beanKey the key associated with this bean in the beans map
 * @return the {@code ObjectName} under which the bean was registered
 * with the {@code MBeanServer}
 */
private ObjectName registerBeanInstance(Object bean, String beanKey) throws JMException {
    ObjectName objectName = getObjectName(bean, beanKey);
    Object mbeanToExpose = null;
    if (isMBean(bean.getClass())) {
        mbeanToExpose = bean;
    }
    else {
        DynamicMBean adaptedBean = adaptMBeanIfPossible(bean);
        if (adaptedBean != null) {
            mbeanToExpose = adaptedBean;
        }
    }
    if (mbeanToExpose != null) {
        if (logger.isInfoEnabled()) {
            logger.info("Located MBean '" + beanKey + "': registering with JMX server as MBean [" +
                    objectName + "]");
        }
        doRegister(mbeanToExpose, objectName);
    }
    else {
        if (logger.isInfoEnabled()) {
            logger.info("Located managed bean '" + beanKey + "': registering with JMX server as MBean [" +
                    objectName + "]");
        }
        ModelMBean mbean = createAndConfigureMBean(bean, beanKey);
        doRegister(mbean, objectName);
        injectNotificationPublisherIfNecessary(bean, mbean, objectName);
    }
    return objectName;
}
MBeanExporter.java 文件源码 项目:lams 阅读 24 收藏 0 点赞 0 评论 0
/**
 * Gets the {@code ModelMBeanInfo} for the bean with the supplied key
 * and of the supplied type.
 */
private ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws JMException {
    ModelMBeanInfo info = this.assembler.getMBeanInfo(managedBean, beanKey);
    if (logger.isWarnEnabled() && ObjectUtils.isEmpty(info.getAttributes()) &&
            ObjectUtils.isEmpty(info.getOperations())) {
        logger.warn("Bean with key '" + beanKey +
                "' has been registered as an MBean but has no exposed attributes or operations");
    }
    return info;
}
QuickFixJClientAutoConfiguration.java 文件源码 项目:quickfixj-spring-boot-starter 阅读 16 收藏 0 点赞 0 评论 0
@Bean
@ConditionalOnProperty(prefix = "quickfixj.client", name = "jmx-enabled", havingValue = "true")
@ConditionalOnClass(JmxExporter.class)
@ConditionalOnSingleCandidate(Initiator.class)
@ConditionalOnMissingBean(name = "clientInitiatorMBean")
public ObjectName clientInitiatorMBean(Initiator clientInitiator) {
    try {
        JmxExporter exporter = new JmxExporter();
        return exporter.register(clientInitiator);
    } catch (JMException e) {
        throw new ConfigurationException(e.getMessage(), e);
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号