Search in sources :

Example 36 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project ACS by ACS-Community.

the class RemoteThreadsClient method getMBean.

/**
	 * Returns an object representing the MBean registered on the remote JVM agent. If the
	 * MBean has not been registered, then it is registered and then retreived.
	 * @return A {@link RemoteThreadsMBean} object representing the MBean registered
	 * on the remote JVM agent.
	 * @throws RemoteThreadsException If:
	 * <ul>
	 * 	<li>The MBean can't be registered on the remote JVM agent</li>
	 * 	<li>A local reference for this MBean can't be get</li>
	 * </ul>
	 */
public RemoteThreadsMBean getMBean() throws RemoteThreadsException {
    if (rtmb == null) {
        try {
            ObjectName remoteThreadsName = new ObjectName("alma.acs.monitoring:type=RemoteThreads");
            if (!remote.isRegistered(remoteThreadsName))
                remote.createMBean("alma.acs.monitoring.RemoteThreads", remoteThreadsName);
            rtmb = JMX.newMBeanProxy(remote, remoteThreadsName, RemoteThreadsMBean.class);
        } catch (MalformedObjectNameException e) {
        // shouldn't get never get here
        } catch (MBeanRegistrationException e) {
            throw new RemoteThreadsException("Can't register the MBean in the remote server", e);
        } catch (Exception e) {
            throw new RemoteThreadsException("Can't get a reference to the remote MBean", e);
        }
    }
    return rtmb;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanRegistrationException(javax.management.MBeanRegistrationException) AgentInitializationException(com.sun.tools.attach.AgentInitializationException) AttachNotSupportedException(com.sun.tools.attach.AttachNotSupportedException) MalformedURLException(java.net.MalformedURLException) AgentLoadException(com.sun.tools.attach.AgentLoadException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 37 with MalformedObjectNameException

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

the class JMXAgentImpl method unregisterMBeans.

/**
     * @see org.apache.aries.jmx.agent.JMXAgent#unregisterMBeans(javax.management.MBeanServer)
     */
public synchronized void unregisterMBeans(final MBeanServer server) {
    for (MBeanHandler mBeanHandler : mbeansHandlers.keySet()) {
        if (mbeansHandlers.get(mBeanHandler) == Boolean.TRUE) {
            try {
                String name = mBeanHandler.getName();
                StandardMBean mbean = mBeanHandler.getMbean();
                if (mbean != null) {
                    logger.log(LogService.LOG_INFO, "Unregistering " + mbean.getMBeanInterface().getName() + " to MBeanServer " + server + " with name " + name);
                    server.unregisterMBean(new ObjectName(name));
                }
            } catch (MBeanRegistrationException e) {
                logger.log(LogService.LOG_ERROR, "Can't unregister MBean", e);
            } catch (InstanceNotFoundException e) {
                logger.log(LogService.LOG_ERROR, "MBean doesn't exist in the repository", e);
            } catch (MalformedObjectNameException e) {
                logger.log(LogService.LOG_ERROR, "Try to unregister with no valid objectname", e);
            } catch (NullPointerException e) {
                logger.log(LogService.LOG_ERROR, "Name of objectname can't be null ", e);
            } catch (Exception e) {
                logger.log(LogService.LOG_ERROR, "Cannot unregister MBean: " + mBeanHandler, e);
            }
        }
    }
    mbeanServers.remove(server);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) StandardMBean(javax.management.StandardMBean) InstanceNotFoundException(javax.management.InstanceNotFoundException) ConfigurationAdminMBeanHandler(org.apache.aries.jmx.cm.ConfigurationAdminMBeanHandler) ProvisioningServiceMBeanHandler(org.apache.aries.jmx.provisioning.ProvisioningServiceMBeanHandler) MBeanHandler(org.apache.aries.jmx.MBeanHandler) PackageStateMBeanHandler(org.apache.aries.jmx.framework.PackageStateMBeanHandler) PermissionAdminMBeanHandler(org.apache.aries.jmx.permissionadmin.PermissionAdminMBeanHandler) BundleStateMBeanHandler(org.apache.aries.jmx.framework.BundleStateMBeanHandler) UserAdminMBeanHandler(org.apache.aries.jmx.useradmin.UserAdminMBeanHandler) FrameworkMBeanHandler(org.apache.aries.jmx.framework.FrameworkMBeanHandler) BundleWiringStateMBeanHandler(org.apache.aries.jmx.framework.wiring.BundleWiringStateMBeanHandler) ServiceStateMBeanHandler(org.apache.aries.jmx.framework.ServiceStateMBeanHandler) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ObjectName(javax.management.ObjectName)

Example 38 with MalformedObjectNameException

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

the class JMXAgentImpl method unregisterMBean.

/**
     * @see org.apache.aries.jmx.agent.JMXAgent#unregisterMBean(org.apache.aries.jmx.MBeanHandler)
     */
public synchronized void unregisterMBean(final MBeanHandler mBeanHandler) {
    for (MBeanServer server : mbeanServers.keySet()) {
        String name = mBeanHandler.getName();
        try {
            logger.log(LogService.LOG_INFO, "Unregistering mbean " + " to MBeanServer " + server + " with name " + name);
            server.unregisterMBean(new ObjectName(name));
        } catch (MBeanRegistrationException e) {
            logger.log(LogService.LOG_ERROR, "Can't register MBean", e);
        } catch (InstanceNotFoundException e) {
            logger.log(LogService.LOG_ERROR, "MBean doesn't exist in the repository", e);
        } catch (MalformedObjectNameException e) {
            logger.log(LogService.LOG_ERROR, "Try to register with no valid objectname, Stopping registration", e);
            return;
        } catch (NullPointerException e) {
            logger.log(LogService.LOG_ERROR, "Name of objectname can't be null, Stopping registration", e);
            return;
        }
    }
    mbeansHandlers.put(mBeanHandler, Boolean.FALSE);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 39 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 40 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)

Aggregations

MalformedObjectNameException (javax.management.MalformedObjectNameException)123 ObjectName (javax.management.ObjectName)115 MBeanServer (javax.management.MBeanServer)34 MBeanRegistrationException (javax.management.MBeanRegistrationException)32 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)27 InstanceNotFoundException (javax.management.InstanceNotFoundException)26 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)25 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)14 MBeanException (javax.management.MBeanException)7 ReflectionException (javax.management.ReflectionException)7 HashMap (java.util.HashMap)6 StandardMBean (javax.management.StandardMBean)5 CacheServiceMBean (org.apache.cassandra.service.CacheServiceMBean)5 Map (java.util.Map)4 HashSet (java.util.HashSet)3 CacheException (javax.cache.CacheException)3 Group (org.apache.catalina.Group)3 User (org.apache.catalina.User)3 NamingResourcesImpl (org.apache.catalina.deploy.NamingResourcesImpl)3