All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.objectweb.jonas.jmx.oname.JonasObjectName Maven / Gradle / Ivy

/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999-2005 Bull S.A.
 * Contact: [email protected]
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id: JonasObjectName.java 10792 2007-06-29 13:42:08Z danesa $
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas.jmx.oname;

import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

/**
 * A set of static classes used to build the names of proprietary MBeans used in JOnAS and in Joram.
 * @author Bruno Michel
 * @author Guillaume Riviere
 * @author Florent Benoit
 * @author Ludovic Bert
 * @author Miroslav Halas
 * @author Adriana Danes
 */
public class JonasObjectName {

    /**
     * domain name
     */
    private static String domain = null;


    /**
     * Set the domain used by JOnAS server
     * @param domainName the domain to use
     */
    public static void setDomain(String domainName) {
        if (domain != null) {
            throw new IllegalStateException("The setDomain method can be called only once.");
        }
        domain = domainName;
    }

    /**
     * @return the domain name of the JOnAS server.
     */
    public static String getDomain() {
        if (domain == null) {
            throw new IllegalStateException("The domain was not previously set, cannot return it.");
        }
        return domain;
    }

    /**
     * Create ObjectName for the JMX Connector Server which is an MBean inside the target MBeanServer
     * @param protocol used protocol
     * @param connectorName name used to distinguish connector servers using the same protocol
     * @return ObjectName for the JMX Connector Server MBean
     */
    public static ObjectName jmxConnectorServer(String protocol, String connectorName) {
        try {
            return ObjectName.getInstance("connectors:protocol=" + protocol + ",name=" + connectorName);
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * @param domainName domain name
     * @return ObjectName for reconfiguration manager MBean
     */
    public static ObjectName serverConfig(String domainName) {
        try {
            return ObjectName.getInstance(domainName + ":type=management,name=reconfigManager");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * @param domainName the domain name
     * @return ObjectName for an MBean used in the Jetty bases web service implem
     */
    public static ObjectName wwwService(String domainName) {
        try {
            return ObjectName.getInstance(domainName + ":type=webContainer,name=Jetty");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * @param domainName the domain name
     * @return ObjectName for an web services
     */
    public static ObjectName wsService(String domainName) {
        //TODO: Add a proper web service mbean instead.
        try {
            return ObjectName.getInstance(domainName + ":type=WebService,*");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * @param domainName the domain name
     * @return ObjectName for the ejb service MBean
     */
    public static ObjectName ejbService(String domainName) {
        try {
            return ObjectName.getInstance(domainName + ":type=service,name=ejbContainers");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * Return the earService (Jmx).
     * @param domainName the domain name
     * @return the Ear service.
     */
    public static ObjectName earService(String domainName) {
        try {
            return ObjectName.getInstance(domainName + ":type=service,name=ear");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * Return the mailService (Jmx).
     * @param domainName the domain name
     * @return the Mail service.
     */
    public static ObjectName mailService(String domainName) {
        try {
            return ObjectName.getInstance(domainName + ":type=service,name=mail");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * Return the webContainerService MBean ObjectName
     * @param domainName the domain name
     * @return the web container service.
     */
    public static ObjectName webContainerService(String domainName) {
        try {
            return ObjectName.getInstance(domainName + ":type=service,name=webContainers");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * @param domainName the domain name
     * @return ObjectName for dbm service MBean
     */
    public static ObjectName databaseService(String domainName) {
        try {
            return ObjectName.getInstance(domainName + ":type=service,name=database");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * @param domainName the domain name
     * @return ObjectName for resource service MBean
     */
    public static ObjectName resourceService(String domainName) {
        try {
            return ObjectName.getInstance(getDomain() + ":type=service,name=resource");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * @param domainName the domain name
     * @return ObjectName for jtm service MBean
     */
    public static ObjectName transactionService(String domainName) {
        try {
            return ObjectName.getInstance(domainName + ":type=service,name=jtm");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * @param domainName domain name
     * @param filename log configuration file name
     * @return ObjectName for JOnAS logging MBean
     */
    public static ObjectName logService(String domainName, String filename) {
        try {
            return ObjectName.getInstance(domainName + ":type=service,name=log,fname="
                + fileNameForObjectName(filename));
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }
    /**
     * @param domainName domain name
     * @return ObjectName for JOnAS logging MBeans
     */
    public static ObjectName logService(String domainName) {
        try {
            return ObjectName.getInstance(domainName + ":type=service,name=log,*");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }
    /**
     * @return ObjectName for JOnAS logging MBeans
     */
    public static ObjectName logService() {
        try {
            return ObjectName.getInstance("*:type=service,name=log,*");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * Create ObjectName for the LogBuffer MBean
     * @param domainName domain name
     * @param name LogBuffer name
     * @return ObjectName for the LogBuffer MBean
     */
    public static ObjectName logBuffer(String domainName, String name) {
        try {
            return ObjectName.getInstance(domainName + ":type=LogBuffer,name=" + name);
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * Create ObjectName for the LogBuffer MBean
     * @param domainName domain name
     * @param name LogBuffer name
     * @return ObjectName for the LogBuffer MBean
     */
    public static ObjectName logBuffers(String domainName) {
        try {
            return ObjectName.getInstance(domainName + ":type=LogBuffer,*");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }
    /**
     * Construct ObjectName for the discovery service MBean
     * @param domainName the domain name
     * @return ObjectName for the discovery service MBean
     */
    public static ObjectName discoveryService(String domainName) {
        try {
            return ObjectName.getInstance(domainName + ":type=service,name=discovery");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * @param domainName the domain name
     * @return ObjectName for jms service MBean
     */
    public static ObjectName jmsService(String domainName) {
        try {
            return ObjectName.getInstance(domainName + ":type=service,name=jms");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * @param domainName the domain name
     * @return ObjectName for jtm service MBean
     */
    public static ObjectName securityService(String domainName) {
        try {
            return ObjectName.getInstance(domainName + ":type=service,name=security");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * @return ObjectName for jmx service MBean
     */
    public static ObjectName jmxService() {
        try {
            return ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * War MBean ObjectName
     * @param domainName domain name
     * @param filename name of the file containing the war
     * @return War MBean ObjectName
     * @throws MalformedObjectNameException Could not construct ObjectName
     */
    public static ObjectName war(String domainName, String filename)
        throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=war,fname=" + fileNameForObjectName(filename));
    }

    /**
     * Return an objectName for the WorkManager
     * @param domainName domain name
     * @return an objectName for the WorkManager
     */
    public static ObjectName workManager(String domainName) {
        try {
            return ObjectName.getInstance(domainName + ":type=workmanager");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * Return an objectName for a Security memory factory.
     * @param domainName the domain name
     * @param name the name of the security memory factory
     * @return an objectName for the security memory factory.
     * @throws MalformedObjectNameException if the objectname can't be build
     */
    public static ObjectName securityMemoryFactory(String domainName, String name)
        throws MalformedObjectNameException {
        return ObjectName.getInstance(getDomain() + ":type=securityfactory,subtype=memory,name=" + name);
    }

    /**
     * Return an objectName for a Security datasource factory.
     * @param domainName the domain name
     * @param name the name of the security datasource factory
     * @return an objectName for the security datasource factory.
     * @throws MalformedObjectNameException if the objectname can't be build
     */
    public static ObjectName securityDatasourceFactory(String domainName, String name)
        throws MalformedObjectNameException {
        return ObjectName.getInstance(getDomain() + ":type=securityfactory,subtype=datasource,name=" + name);
    }

    /**
     * Return an objectName for a Security ldap factory.
     * @param domainName the domain name
     * @param name the name of the security ldap factory
     * @return an objectName for the security ldap factory.
     * @throws MalformedObjectNameException if the objectname can't be build
     */
    public static ObjectName securityLdapFactory(String domainName, String name)
        throws MalformedObjectNameException {
        return ObjectName.getInstance(getDomain() + ":type=securityfactory,subtype=ldap,name=" + name);
    }

    /**
     * Return an objectName for a user
     * @param resource the name of the resource on which the user depends
     * @param username the name of the user
     * @param domainName the domain name
     * @return an objectName for the user MBean
     * @throws MalformedObjectNameException if the objectname can't be build
     */
    public static ObjectName user(String domainName, String resource, String username)
        throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=security,subtype=users,resource=" + resource
            + ",name=" + username);
    }

    /**
     * Return an objectName for a group
     * @param resource the name of the resource on which the group depends
     * @param groupname the name of the group
     * @param domainName the domain name
     * @return an objectName for the group MBean
     * @throws MalformedObjectNameException if the objectname can't be build
     */
    public static ObjectName group(String domainName, String resource, String groupname)
        throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=security,subtype=groups,resource=" + resource
            + ",name=" + groupname);
    }

    /**
     * Return an objectName for a role
     * @param resource the name of the resource on which the role depends
     * @param rolename the name of the role
     * @param domainName the domain name
     * @return an objectName for the user MBean
     * @throws MalformedObjectNameException if the objectname can't be build
     */
    public static ObjectName role(String domainName, String resource, String rolename)
        throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=security,subtype=roles,resource=" + resource
            + ",name=" + rolename);
    }

    /**
     * ObjectName for all war MBeans in the domain
     * @param domainName domain name
     * @return ObjectName for all war MBeans in the domain
     */
    public static ObjectName allWars(String domainName) {
        try {
            return ObjectName.getInstance(domainName + ":type=war,*");
        } catch (MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    public static String getType(ObjectName obj) {
        return obj.getKeyProperty("type");
    }

    public static String fileNameForObjectName(String fileName) {
        return fileName.replace(':', '|');
    }

    /**
     * Return an objectName for the Security factory name.
     * @param domainName the domain name
     * @return an objectName for the security factory name.
     * @throws MalformedObjectNameException if the objectname can't be build
     */
    public static ObjectName allSecurityFactories(String domainName)
        throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=securityfactory,*");
    }

    /**
     * Return an objectName for all the Security memory factories.
     * @param domainName the domain name
     * @return an objectName for all the security memory factories
     * @throws MalformedObjectNameException if the objectname can't be build
     */
    public static ObjectName allSecurityMemoryFactories(String domainName)
        throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=securityfactory,subtype=memory,*");
    }

    /**
     * Return an objectName for all the Security datasource factories.
     * @param domainName the domain name
     * @return an objectName for all the security datasource factories
     * @throws MalformedObjectNameException if the objectname can't be build
     */
    public static ObjectName allSecurityDatasourceFactories(String domainName)
        throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=securityfactory,subtype=datasource,*");
    }

    /**
     * Return an objectName for all the Security ldap factories.
     * @param domainName the domain name
     * @return an objectName for all the security ldap factories
     * @throws MalformedObjectNameException if the objectname can't be build
     */
    public static ObjectName allSecurityLdapFactories(String domainName)
        throws MalformedObjectNameException {
        return ObjectName.getInstance(JonasObjectName.getDomain() + ":type=securityfactory,subtype=ldap,*");
    }

    /**
     * Return an objectName for all users in a resource.
     * @param domainName the management domain name
     * @param pResource the name of the resource on which the user depends
     * @return an objectName for the user MBean
     * @throws MalformedObjectNameException if the objectname can't be build
     */
    public static ObjectName allUsers(String domainName, String pResource)
        throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=security,subtype=users,resource="
            + pResource + ",*");
    }

    /**
     * Return an objectName for all roles in a resource.
     * @param domainName the management domain name
     * @param pResource the name of the resource on which the role depends
     * @return an objectName for the user MBean
     * @throws MalformedObjectNameException if the objectname can't be build
     */
    public static ObjectName allRoles(String domainName, String pResource)
        throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=security,subtype=roles,resource="
            + pResource + ",*");
    }

    /**
     * Return an objectName for all groups in a resource.
     * @param domainName the management domain name
     * @param pResource the name of the resource on which the group depends
     * @return an objectName for the user MBean
     * @throws MalformedObjectNameException if the objectname can't be build
     */
    public static ObjectName allGroups(String domainName, String pResource)
        throws MalformedObjectNameException {
        return ObjectName.getInstance(JonasObjectName.getDomain() + ":type=security,subtype=groups,resource="
            + pResource + ",*");
    }

    /**
     * A different implementation should allow returning a logical name.
         * This is done currently in the invoke method of ManagementReprImpl/Mx4jManagementReprImpl classes.
     * @return String representation of the ObjectName
     */
    public String toString() {
        return super.toString();
    }

    // Joram integration
    // ------------------
    /**
     * @return ObjectName for the local Joram server
     * @exception MalformedObjectNameException Could not create ObjectName with the given String
     */
    public static ObjectName joramLocalServer() throws MalformedObjectNameException {
        return ObjectName.getInstance("joram:type=JMSlocalServer");
    }

    /**
     * Create ObjectName for a remote Joram server
     * @param id remote server identifier
     * @return ObjectName for a remote Joram server
     * @exception MalformedObjectNameException Could not create ObjectName with the given String
     */
    public static ObjectName joramRemoteServer(String id) throws MalformedObjectNameException {
        return ObjectName.getInstance("joram:type=JMSremoteServer,id=" + id);
    }

    /**
     * Create ObjectName for a Joram managed queue
     * @param name queue name
     * @return ObjectName for a Joram managed queue
     * @exception MalformedObjectNameException Could not create ObjectName with the given String
     */
    public static ObjectName joramQueue(String name) throws MalformedObjectNameException {
        return ObjectName.getInstance("joram:type=JMSqueue,name=" + name);
    }

    /**
     * Create ObjectName for a Joram managed topic
     * @param name topic name
     * @return ObjectName for a Joram managed topic
     * @exception MalformedObjectNameException Could not create ObjectName with the given String
     */
    public static ObjectName joramTopic(String name) throws MalformedObjectNameException {
        return ObjectName.getInstance("joram:type=JMStopic,name=" + name);
    }

    /**
     * @return ObjectName for discovery manager MBean
     * @param domainName the management domain name
     * @exception MalformedObjectNameException Could not create ObjectName with the given String
     */
    public static ObjectName discoveryManager(String domainName) throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=management,name=discoveryManager,server=JOnAS");
    }

    /**
     * @return ObjectName for discovery client MBean
     * @param domainName the management domain name
     * @exception MalformedObjectNameException Could not create ObjectName with the given String
     */
    public static ObjectName discoveryClient(String domainName) throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=management,name=discoveryClient,server=JOnAS");
    }
    /**
     * @return ObjectName for discovery enroller MBean
     * @param domainName the management domain name
     * @exception MalformedObjectNameException Could not create ObjectName with the given String
     */
    public static ObjectName discoveryEnroller(String domainName) throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=management,name=discoveryEnroller,server=JOnAS");
    }

    /**
     * @return ObjectName for ServerProxy MBean
     * @exception MalformedObjectNameException Could not create ObjectName with the given String
     */
    public static ObjectName serverProxy(String domainName, String serverName) throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=ServerProxy,name=" + serverName);
    }

    /**
     * @return ObjectName for ServerProxy MBean
     * @exception MalformedObjectNameException Could not create ObjectName with the given String
     */
    public static ObjectName serverProxys(String domainName) throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=ServerProxy,*");
    }

    /**
     * Build an ObjectName for a Cluster defined by its type and its name.
     * @param name Name of the Cluster
     * @param type Type: JkCluster, TomcatCluster, JoramCluster, EjbHaCluster, CmiCluster, ...
     * @return ObjectName for a Cluster
     * @throws MalformedObjectNameException
     */
    public static ObjectName cluster(String domainName, String name, String type) throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=" + type + ",name=" + name);
    }

    /**
     * Build an ObjectName for a Cluster defined by its type only.
     * @param type Type: JkCluster, TomcatCluster, JoramCluster, EjbHaCluster, CmiCluster, ...
     * @return ObjectName for a Cluster
     * @throws MalformedObjectNameException
     */
    public static ObjectName clusters(String domainName, String type) throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=" + type + ",*");
    }

    /**
     * Build an ObjectName for a ClusterMember.
     * All ClusterMember have the same type, regardless the cluster type.
     * @param name Name of the ClusterMember
     * @param type type of the cluster (ex: JkCluster or TomcatCluster)
     * @param cluster Name of the Cluster
     * @return ObjectName for a ClusterMember
     * @throws MalformedObjectNameException
     */
    public static ObjectName clusterMember(String domainName, String name, String type, String cluster) throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=" + type + "Member,name=" + name + "," + type + "=" + cluster);
    }

    public static ObjectName clusterDaemon(String domainName) throws Exception {
        return ObjectName.getInstance(domainName + ":type=ClusterDaemon");
    }

    /**
     * @param name name of the ClusterDaemon
     * @return
     * @exception MalformedObjectNameException Could not create ObjectName with the given String
     */
    public static ObjectName clusterDaemonProxy(String domainName, String name) throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=ClusterDaemonProxy,name=" + name);
    }

    /**
     * @param name name of the ClusterDaemon
     * @return
     * @exception MalformedObjectNameException Could not create ObjectName with the given String
     */
    public static ObjectName clusterDaemonProxys(String domainName) throws MalformedObjectNameException {
        return ObjectName.getInstance(domainName + ":type=ClusterDaemonProxy,*");
    }

    /**
     * @param domainName the management domain name
     * @return ObjectName for the generic archive configurationMBean
     */
    public static ObjectName ArchiveConfig(String domainName) {
        try {
            return new ObjectName(":type=archiveConfig,name=ArchiveConfigMBean");
        } catch (javax.management.MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }

    /**
     * @param domainName the management domain name
     * @return ObjectName for RAR specific archive configuration MBean
     */
    public static ObjectName RarConfig(String domainName) {
        try {
            return new ObjectName(":type=archiveConfig,name=RarConfigMBean");
        } catch (javax.management.MalformedObjectNameException e) {
            // this should never occur
            return null;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy