Search in sources :

Example 76 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project jdk8u_jdk by JetBrains.

the class MBeanAnalyzer method initMaps.

// Introspect the mbeanInterface and initialize this object's maps.
//
private void initMaps(Class<?> mbeanType, MBeanIntrospector<M> introspector) throws Exception {
    final List<Method> methods1 = introspector.getMethods(mbeanType);
    final List<Method> methods = eliminateCovariantMethods(methods1);
    /* Run through the methods to detect inconsistencies and to enable
           us to give getter and setter together to visitAttribute. */
    for (Method m : methods) {
        final String name = m.getName();
        final int nParams = m.getParameterTypes().length;
        final M cm = introspector.mFrom(m);
        String attrName = "";
        if (name.startsWith("get"))
            attrName = name.substring(3);
        else if (name.startsWith("is") && m.getReturnType() == boolean.class)
            attrName = name.substring(2);
        if (attrName.length() != 0 && nParams == 0 && m.getReturnType() != void.class) {
            // It's a getter
            // Check we don't have both isX and getX
            AttrMethods<M> am = attrMap.get(attrName);
            if (am == null)
                am = new AttrMethods<M>();
            else {
                if (am.getter != null) {
                    final String msg = "Attribute " + attrName + " has more than one getter";
                    throw new NotCompliantMBeanException(msg);
                }
            }
            am.getter = cm;
            attrMap.put(attrName, am);
        } else if (name.startsWith("set") && name.length() > 3 && nParams == 1 && m.getReturnType() == void.class) {
            // It's a setter
            attrName = name.substring(3);
            AttrMethods<M> am = attrMap.get(attrName);
            if (am == null)
                am = new AttrMethods<M>();
            else if (am.setter != null) {
                final String msg = "Attribute " + attrName + " has more than one setter";
                throw new NotCompliantMBeanException(msg);
            }
            am.setter = cm;
            attrMap.put(attrName, am);
        } else {
            // It's an operation
            List<M> cms = opMap.get(name);
            if (cms == null)
                cms = newList();
            cms.add(cm);
            opMap.put(name, cms);
        }
    }
    /* Check that getters and setters are consistent. */
    for (Map.Entry<String, AttrMethods<M>> entry : attrMap.entrySet()) {
        AttrMethods<M> am = entry.getValue();
        if (!introspector.consistent(am.getter, am.setter)) {
            final String msg = "Getter and setter for " + entry.getKey() + " have inconsistent types";
            throw new NotCompliantMBeanException(msg);
        }
    }
}
Also used : NotCompliantMBeanException(javax.management.NotCompliantMBeanException) List(java.util.List) Method(java.lang.reflect.Method) Map(java.util.Map)

Example 77 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project smscgateway by RestComm.

the class HttpUsersManagement method registerHttpUserMbean.

private void registerHttpUserMbean(HttpUser httpUser) {
    try {
        ObjectName httpUserObjNname = new ObjectName(SmscManagement.JMX_DOMAIN + ":layer=HttpUser,name=" + httpUser.getUserName());
        StandardMBean httpUserMxBean = new StandardMBean(httpUser, HttpUserMBean.class, true);
        if (this.mbeanServer != null)
            this.mbeanServer.registerMBean(httpUserMxBean, httpUserObjNname);
    } catch (InstanceAlreadyExistsException e) {
        logger.error(String.format("Error while registering MBean for HttpUser %s", httpUser.getUserName()), e);
    } catch (MBeanRegistrationException e) {
        logger.error(String.format("Error while registering MBean for HttpUser %s", httpUser.getUserName()), e);
    } catch (NotCompliantMBeanException e) {
        logger.error(String.format("Error while registering MBean for HttpUser %s", httpUser.getUserName()), e);
    } catch (MalformedObjectNameException e) {
        logger.error(String.format("Error while registering MBean for HttpUser %s", httpUser.getUserName()), e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 78 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project jspwiki by apache.

the class DefaultAdminBeanManager method reload.

// FIXME: Should unload the beans first.
private void reload() {
    m_allBeans = new ArrayList<AdminBean>();
    try {
        registerAdminBean(new CoreBean(m_engine));
        registerAdminBean(new UserBean(m_engine));
        registerAdminBean(new SearchManagerBean(m_engine));
        registerAdminBean(new PluginBean(m_engine));
        registerAdminBean(new FilterBean(m_engine));
    } catch (NotCompliantMBeanException e) {
        log.error(e.getMessage(), e);
    }
    registerBeans(m_engine.getEditorManager().modules());
    registerBeans(m_engine.getPluginManager().modules());
    registerBeans(m_engine.getFilterManager().modules());
}
Also used : SearchManagerBean(org.apache.wiki.ui.admin.beans.SearchManagerBean) UserBean(org.apache.wiki.ui.admin.beans.UserBean) CoreBean(org.apache.wiki.ui.admin.beans.CoreBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) PluginBean(org.apache.wiki.ui.admin.beans.PluginBean) FilterBean(org.apache.wiki.ui.admin.beans.FilterBean)

Example 79 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project controller by opendaylight.

the class AbstractMXBean method registerMBean.

/**
 * Registers this bean with the platform MBean server with the domain defined by
 * {@link #BASE_JMX_PREFIX}.
 *
 * @return true is successfully registered, false otherwise.
 */
public boolean registerMBean() {
    boolean registered = false;
    try {
        // Object to identify MBean
        final ObjectName mbeanName = this.getMBeanObjectName();
        LOG.debug("Register MBean {}", mbeanName);
        // unregistered if already registered
        if (server.isRegistered(mbeanName)) {
            LOG.debug("MBean {} found to be already registered", mbeanName);
            try {
                unregisterMBean(mbeanName);
            } catch (MBeanRegistrationException | InstanceNotFoundException e) {
                LOG.warn("unregister mbean {} resulted in exception {} ", mbeanName, e);
            }
        }
        server.registerMBean(this, mbeanName);
        registered = true;
        LOG.debug("MBean {} registered successfully", mbeanName.getCanonicalName());
    } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException | MalformedObjectNameException e) {
        LOG.error("registration failed {}", e);
    }
    return registered;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 80 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project wicket by apache.

the class Initializer method init.

@Override
public void init(final org.apache.wicket.Application application) {
    try {
        String name = application.getName();
        String agentId = null;
        try {
            agentId = System.getProperty("wicket.mbean.server.agentid");
        } catch (SecurityException e) {
            // Ignore - we're not allowed to read this property.
            log.warn("not allowed to read property wicket.mbean.server.agentid due to security settings; ignoring");
        }
        if (agentId != null) {
            ArrayList<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(agentId);
            if (!mbeanServers.isEmpty()) {
                // get first
                mbeanServer = mbeanServers.get(0);
            } else {
                log.error("unable to find mbean server with agent id " + agentId);
            }
        }
        if (mbeanServer == null) {
            String impl = null;
            try {
                impl = System.getProperty("wicket.mbean.server.class");
            } catch (SecurityException e) {
                // Ignore - we're not allowed to read this property.
                log.warn("not allowed to read property wicket.mbean.server.class due to security settings; ignoring");
            }
            if (impl != null) {
                ArrayList<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(null);
                if (!mbeanServers.isEmpty()) {
                    for (MBeanServer mbs : mbeanServers) {
                        if (mbs.getClass().getName().equals(impl)) {
                            mbeanServer = mbs;
                            break;
                        }
                    }
                }
                if (mbeanServer == null) {
                    log.error("unable to find mbean server of type '{}'", impl);
                }
            }
        }
        if (mbeanServer == null) {
            mbeanServer = ManagementFactory.getPlatformMBeanServer();
        // never null
        }
        log.info("registering Wicket mbeans with server '{}'", mbeanServer);
        // register top level application object, but first check whether
        // multiple instances of the same application (name) are running and
        // if so adjust the name
        String domain = "org.apache.wicket.app." + name;
        ObjectName appBeanName = new ObjectName(domain + ":type=Application");
        String tempDomain = domain;
        int i = 0;
        while (mbeanServer.isRegistered(appBeanName)) {
            tempDomain = name + "-" + i++;
            appBeanName = new ObjectName(tempDomain + ":type=Application");
        }
        domain = tempDomain;
        Application appBean = new Application(application);
        register(application, appBean, appBeanName);
        register(application, new ApplicationSettings(application), new ObjectName(domain + ":type=Application,name=ApplicationSettings"));
        register(application, new DebugSettings(application), new ObjectName(domain + ":type=Application,name=DebugSettings"));
        register(application, new MarkupSettings(application), new ObjectName(domain + ":type=Application,name=MarkupSettings"));
        register(application, new ResourceSettings(application), new ObjectName(domain + ":type=Application,name=ResourceSettings"));
        register(application, new PageSettings(application), new ObjectName(domain + ":type=Application,name=PageSettings"));
        register(application, new RequestCycleSettings(application), new ObjectName(domain + ":type=Application,name=RequestCycleSettings"));
        register(application, new SecuritySettings(application), new ObjectName(domain + ":type=Application,name=SecuritySettings"));
        register(application, new SessionSettings(application), new ObjectName(domain + ":type=Application,name=SessionSettings"));
        register(application, new StoreSettings(application), new ObjectName(domain + ":type=Application,name=StoreSettings"));
        RequestLogger sessionsBean = new RequestLogger(application);
        ObjectName sessionsBeanName = new ObjectName(domain + ":type=RequestLogger");
        register(application, sessionsBean, sessionsBeanName);
    } catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
        throw new WicketRuntimeException(e);
    }
}
Also used : MarkupSettings(org.apache.wicket.jmx.wrapper.MarkupSettings) MalformedObjectNameException(javax.management.MalformedObjectNameException) RequestCycleSettings(org.apache.wicket.jmx.wrapper.RequestCycleSettings) PageSettings(org.apache.wicket.jmx.wrapper.PageSettings) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) SecuritySettings(org.apache.wicket.jmx.wrapper.SecuritySettings) SessionSettings(org.apache.wicket.jmx.wrapper.SessionSettings) ObjectName(javax.management.ObjectName) DebugSettings(org.apache.wicket.jmx.wrapper.DebugSettings) StoreSettings(org.apache.wicket.jmx.wrapper.StoreSettings) ApplicationSettings(org.apache.wicket.jmx.wrapper.ApplicationSettings) ResourceSettings(org.apache.wicket.jmx.wrapper.ResourceSettings) RequestLogger(org.apache.wicket.jmx.wrapper.RequestLogger) Application(org.apache.wicket.jmx.wrapper.Application) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer)

Aggregations

NotCompliantMBeanException (javax.management.NotCompliantMBeanException)106 ObjectName (javax.management.ObjectName)73 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)71 MBeanRegistrationException (javax.management.MBeanRegistrationException)71 MalformedObjectNameException (javax.management.MalformedObjectNameException)59 MBeanServer (javax.management.MBeanServer)39 InstanceNotFoundException (javax.management.InstanceNotFoundException)23 StandardMBean (javax.management.StandardMBean)20 MBeanException (javax.management.MBeanException)8 ReflectionException (javax.management.ReflectionException)8 IOException (java.io.IOException)7 ObjectInstance (javax.management.ObjectInstance)5 AttributeNotFoundException (javax.management.AttributeNotFoundException)4 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)4 ListenerNotFoundException (javax.management.ListenerNotFoundException)4 Logger (org.apache.aries.jmx.Logger)4 MalformedURLException (java.net.MalformedURLException)3 DynamicMBean (javax.management.DynamicMBean)3 IntrospectionException (javax.management.IntrospectionException)3 JMRuntimeException (javax.management.JMRuntimeException)3