Search in sources :

Example 46 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project geode by apache.

the class MX4JModelMBean method findLogger.

private Logger findLogger(Descriptor descriptor) {
    Logger logger = getLogger();
    if (descriptor == null) {
        if (logger.isEnabledFor(Logger.TRACE))
            logger.trace("Can't find MBean logger, descriptor is null");
        return null;
    }
    String log = (String) descriptor.getFieldValue("log");
    String location = (String) descriptor.getFieldValue("logFile");
    if (logger.isEnabledFor(Logger.DEBUG))
        logger.debug("Log fields: log=" + log + ", file=" + location);
    if (log == null || !Boolean.valueOf(log).booleanValue()) {
        if (logger.isEnabledFor(Logger.DEBUG))
            logger.debug("Logging is not supported by this ModelMBean");
        return null;
    }
    // Logger is supported, where log to ?
    if (location == null) {
        // As an extension, see if the field logMBean has been defined
        location = (String) descriptor.getFieldValue("logMBean");
        if (logger.isEnabledFor(Logger.DEBUG))
            logger.debug("Log fields: mbean=" + location);
        if (location == null) {
            if (logger.isEnabledFor(Logger.TRACE))
                logger.trace("Logging is not supported by this ModelMBean");
            return null;
        }
        // It seems that the user wants to delegate a registered mbean to log
        try {
            ObjectName objectName = new ObjectName(location);
            MBeanServer server = getMBeanServer();
            if (server == null)
                throw new MBeanException(new IllegalStateException(LocalizedStrings.MX4JModelMBean_MX4JMODELMBEAN_IS_NOT_REGISTERED.toLocalizedString()));
            if (server.isRegistered(objectName)) {
                MBeanLogger l = new MBeanLogger(server, objectName);
                if (logger.isEnabledFor(Logger.DEBUG))
                    logger.debug("ModelMBean log supported by delegating to this MBean: " + objectName);
                return l;
            }
            return null;
        } catch (MalformedObjectNameException x) {
            // Ah, was not a correct object name
            if (logger.isEnabledFor(Logger.DEBUG))
                logger.debug("Specified logMBean field does not contain a valid ObjectName: " + location);
            return null;
        } catch (MBeanException x) {
            if (logger.isEnabledFor(Logger.DEBUG))
                logger.debug("logMBean field does not specify an MBean that supports logging delegation", x);
            return null;
        }
    } else {
        // User decided to log to a file
        if (logger.isEnabledFor(Logger.DEBUG))
            logger.debug("ModelMBean log supported on file system");
        return new FileLogger(location);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanLogger(mx4j.log.MBeanLogger) MBeanException(javax.management.MBeanException) FileLogger(mx4j.log.FileLogger) Logger(mx4j.log.Logger) FileLogger(mx4j.log.FileLogger) MBeanLogger(mx4j.log.MBeanLogger) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 47 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project geode by apache.

the class MX4JModelMBean method findPersister.

private PersisterMBean findPersister() throws MBeanException, InstanceNotFoundException {
    Logger logger = getLogger();
    ModelMBeanInfo info = getModelMBeanInfo();
    if (info == null) {
        // Not yet initialized
        if (logger.isEnabledFor(Logger.TRACE))
            logger.trace("Can't find persister, ModelMBeanInfo is null");
        return null;
    }
    Descriptor mbeanDescriptor = info.getMBeanDescriptor();
    if (mbeanDescriptor == null) {
        // This is normally should not happen if ModelMBeanInfoSupport is used
        if (logger.isEnabledFor(Logger.TRACE))
            logger.trace("Can't find persister, MBean descriptor is null");
        return null;
    }
    String location = (String) mbeanDescriptor.getFieldValue("persistLocation");
    String name = (String) mbeanDescriptor.getFieldValue("persistName");
    String mbeanName = (String) mbeanDescriptor.getFieldValue("name");
    if (logger.isEnabledFor(Logger.DEBUG))
        logger.debug("Persistence fields: location=" + location + ", name=" + name);
    if (mbeanName == null && name == null) {
        if (logger.isEnabledFor(Logger.DEBUG))
            logger.debug("Persistence is not supported by this ModelMBean");
        return null;
    }
    // Try to see if this mbean should delegate to another mbean
    if (name != null) {
        try {
            ObjectName objectName = new ObjectName(name.trim());
            // OK, a valid object name
            MBeanServer server = getMBeanServer();
            if (server == null)
                throw new MBeanException(new IllegalStateException(LocalizedStrings.MX4JModelMBean_MX4JMODELMBEAN_IS_NOT_REGISTERED.toLocalizedString()));
            if (server.isRegistered(objectName) && server.isInstanceOf(objectName, PersisterMBean.class.getName())) {
                // OK, the given mbean is registered with this mbean server
                PersisterMBean persister = new MBeanPersister(server, objectName);
                if (logger.isEnabledFor(Logger.DEBUG))
                    logger.debug("Persistence is delegated to this MBean: " + objectName);
                return persister;
            } else {
                throw new InstanceNotFoundException(objectName.toString());
            }
        } catch (MalformedObjectNameException ignored) {
            // It does not delegates to another mbean, use default
            if (logger.isEnabledFor(Logger.TRACE))
                logger.trace("Persistence is not delegated to another MBean");
        }
        // Default is serialization to file
        FilePersister persister = new FilePersister(location, name);
        if (logger.isEnabledFor(Logger.DEBUG))
            logger.debug("Persistence is realized through file system in " + persister.getFileName());
        return persister;
    } else {
        // Only location given, use MBean name
        FilePersister persister = new FilePersister(location, mbeanName);
        if (logger.isEnabledFor(Logger.DEBUG))
            logger.debug("Persistence is realized through file system in " + persister.getFileName());
        return persister;
    }
}
Also used : MBeanPersister(mx4j.persist.MBeanPersister) MalformedObjectNameException(javax.management.MalformedObjectNameException) PersisterMBean(mx4j.persist.PersisterMBean) FilePersister(mx4j.persist.FilePersister) InstanceNotFoundException(javax.management.InstanceNotFoundException) Logger(mx4j.log.Logger) FileLogger(mx4j.log.FileLogger) MBeanLogger(mx4j.log.MBeanLogger) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) ObjectName(javax.management.ObjectName) Descriptor(javax.management.Descriptor) MBeanException(javax.management.MBeanException) MBeanServer(javax.management.MBeanServer)

Example 48 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project fabric8 by jboss-fuse.

the class RBACMBeanInvoker method initSecurityMBean.

protected void initSecurityMBean() {
    this.mBeanServer = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectName> mbeans = new HashSet<>();
    try {
        mbeans = mBeanServer.queryNames(new ObjectName("*:type=security,area=jmx,*"), null);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Found JMXSecurity MBeans: {}", mbeans);
        }
    } catch (MalformedObjectNameException e) {
        LOG.error(e.getMessage(), e);
    }
    if (mbeans.isEmpty()) {
        LOG.info("Didn't discover any JMXSecurity MBeans, role based access control is disabled");
        this.securityMBean = null;
        return;
    }
    ObjectName chosen = chooseMBean(mbeans);
    LOG.info("Using MBean [{}] for role based access control", chosen);
    this.securityMBean = chosen;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) ObjectName(javax.management.ObjectName) HashSet(java.util.HashSet)

Example 49 with MalformedObjectNameException

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

the class MProcManagement method registerMProcRuleMbean.

private void registerMProcRuleMbean(MProcRuleMBean mProcRule) {
    try {
        ObjectName esmeObjNname = new ObjectName(SmscManagement.JMX_DOMAIN + ":layer=MProcRule,name=" + mProcRule.getId());
        StandardMBean esmeMxBean = new StandardMBean(mProcRule, MProcRuleMBean.class, true);
        if (this.mbeanServer != null)
            this.mbeanServer.registerMBean(esmeMxBean, esmeObjNname);
    } catch (InstanceAlreadyExistsException e) {
        logger.error(String.format("Error while registering MBean for MProcRule %d", mProcRule.getId()), e);
    } catch (MBeanRegistrationException e) {
        logger.error(String.format("Error while registering MBean for MProcRule %d", mProcRule.getId()), e);
    } catch (NotCompliantMBeanException e) {
        logger.error(String.format("Error while registering MBean for MProcRule %d", mProcRule.getId()), e);
    } catch (MalformedObjectNameException e) {
        logger.error(String.format("Error while registering MBean for MProcRule %d", mProcRule.getId()), 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 50 with MalformedObjectNameException

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

the class SipManagement method registerSipMbean.

private void registerSipMbean(Sip esme) {
    try {
        ObjectName esmeObjNname = new ObjectName(SmscManagement.JMX_DOMAIN + ":layer=Sip,name=" + esme.getName());
        StandardMBean esmeMxBean = new StandardMBean(esme, SipMBean.class, true);
        if (this.mbeanServer != null)
            this.mbeanServer.registerMBean(esmeMxBean, esmeObjNname);
    } catch (InstanceAlreadyExistsException e) {
        logger.error(String.format("Error while registering MBean for SIP %s", esme.getName()), e);
    } catch (MBeanRegistrationException e) {
        logger.error(String.format("Error while registering MBean for SIP %s", esme.getName()), e);
    } catch (NotCompliantMBeanException e) {
        logger.error(String.format("Error while registering MBean for SIP %s", esme.getName()), e);
    } catch (MalformedObjectNameException e) {
        logger.error(String.format("Error while registering MBean for SIP %s", esme.getName()), 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)

Aggregations

MalformedObjectNameException (javax.management.MalformedObjectNameException)309 ObjectName (javax.management.ObjectName)285 InstanceNotFoundException (javax.management.InstanceNotFoundException)88 MBeanServer (javax.management.MBeanServer)80 MBeanRegistrationException (javax.management.MBeanRegistrationException)75 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)63 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)59 IOException (java.io.IOException)53 ArrayList (java.util.ArrayList)45 ReflectionException (javax.management.ReflectionException)30 MBeanException (javax.management.MBeanException)23 Test (org.testng.annotations.Test)23 CompositeData (javax.management.openmbean.CompositeData)18 Notification (javax.management.Notification)15 MBeanInfo (javax.management.MBeanInfo)14 AttributeNotFoundException (javax.management.AttributeNotFoundException)13 HashMap (java.util.HashMap)11 Map (java.util.Map)11 IntrospectionException (javax.management.IntrospectionException)11 MalformedURLException (java.net.MalformedURLException)10