Example usage for javax.management ObjectName ObjectName

List of usage examples for javax.management ObjectName ObjectName

Introduction

In this page you can find the example usage for javax.management ObjectName ObjectName.

Prototype

public ObjectName(String name) throws MalformedObjectNameException 

Source Link

Document

Construct an object name from the given string.

Usage

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Remove an existing Context./*from www  . j a va 2s  .  co m*/
 *
 * @param name MBean Name of the comonent to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeContext(String name) throws Exception {
    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    String serviceName = oname.getKeyProperty("service");
    String hostName = oname.getKeyProperty("host");
    String contextName = getPathStr(oname.getKeyProperty("path"));
    Server server = ServerFactory.getServer();
    Service service = server.findService(serviceName);
    Engine engine = (Engine) service.getContainer();
    Host host = (Host) engine.findChild(hostName);
    Context context = (Context) host.findChild(contextName);

    // Remove this component from its parent component
    host.removeChild(context);

}

From source file:catalina.mbeans.MBeanUtils.java

/**
 * Create an <code>ObjectName</code> for this
 * <code>Server</code> object.
 *
 * @param domain Domain in which this name is to be created
 * @param resources The NamingResources to be named
 *
 * @exception MalformedObjectNameException if a name cannot be created
 *//*from  w  w w.  ja  va  2 s .  c o  m*/
public static ObjectName createObjectName(String domain, NamingResources resources)
        throws MalformedObjectNameException {

    ObjectName name = null;
    Object container = resources.getContainer();
    if (container instanceof Server) {
        name = new ObjectName(domain + ":type=NamingResources" + ",resourcetype=Global");
    } else if (container instanceof Context) {
        String path = ((Context) container).getPath();
        if (path.length() < 1)
            path = "/";
        Host host = (Host) ((Context) container).getParent();
        Engine engine = (Engine) host.getParent();
        Service service = engine.getService();
        name = new ObjectName(domain + ":type=NamingResources" + ",resourcetype=Context,path=" + path + ",host="
                + host.getName() + ",service=" + service.getName());
    } else if (container instanceof DefaultContext) {
        container = ((DefaultContext) container).getParent();
        if (container instanceof Host) {
            Host host = (Host) container;
            Service service = ((Engine) host.getParent()).getService();
            name = new ObjectName(domain + ":type=NamingResources" + ",resourcetype=HostDefaultContext,host="
                    + host.getName() + ",service=" + service.getName());
        } else if (container instanceof Engine) {
            Engine engine = (Engine) container;
            Service service = engine.getService();
            name = new ObjectName(domain + ":type=NamingResources" + ",resourcetype=ServiceDefaultContext"
                    + ",service=" + service.getName());
        }
    }

    return (name);

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Remove an existing Host./* w w  w.  j  a  va  2  s. c  om*/
 *
 * @param name MBean Name of the comonent to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeHost(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    String serviceName = oname.getKeyProperty("service");
    String hostName = oname.getKeyProperty("host");
    Server server = ServerFactory.getServer();
    Service service = server.findService(serviceName);
    Engine engine = (Engine) service.getContainer();
    Host host = (Host) engine.findChild(hostName);

    // Remove this component from its parent component
    engine.removeChild(host);

}

From source file:com.app.server.EJBDeployer.java

public void setRarDeployerName(String rarDeployerName) {
    try {/*from w  w w . j  a va2s .c om*/
        this.rarDeployerName = new ObjectName(rarDeployerName);
    } catch (Exception e) {
        log.error("Error in creatnig object name " + rarDeployerName, e);
        // TODO Auto-generated catch block
        //e.printStackTrace();
    }

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Remove an existing Logger./*from   w w w  .  j  a v  a  2  s .c  om*/
 *
 * @param name MBean Name of the comonent to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeLogger(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    String serviceName = oname.getKeyProperty("service");
    String hostName = oname.getKeyProperty("host");

    String path = oname.getKeyProperty("path");
    Server server = ServerFactory.getServer();
    Service service = server.findService(serviceName);
    StandardEngine engine = (StandardEngine) service.getContainer();
    if (hostName == null) { // if logger's container is Engine
        Logger logger = engine.getLogger();
        Container container = logger.getContainer();
        if (container instanceof StandardEngine) {
            String sname = ((StandardEngine) container).getService().getName();
            if (sname.equals(serviceName)) {
                engine.setLogger(null);
            }
        }
    } else if (path == null) { // if logger's container is Host
        StandardHost host = (StandardHost) engine.findChild(hostName);
        Logger logger = host.getLogger();
        Container container = logger.getContainer();
        if (container instanceof StandardHost) {
            String hn = ((StandardHost) container).getName();
            StandardEngine se = (StandardEngine) ((StandardHost) container).getParent();
            String sname = se.getService().getName();
            if (sname.equals(serviceName) && hn.equals(hostName)) {
                host.setLogger(null);
            }
        }
    } else { // logger's container is Context
        StandardHost host = (StandardHost) engine.findChild(hostName);
        path = getPathStr(path);
        StandardContext context = (StandardContext) host.findChild(path);
        Logger logger = context.getLogger();
        Container container = logger.getContainer();
        if (container instanceof StandardContext) {
            String pathName = ((StandardContext) container).getName();
            StandardHost sh = (StandardHost) ((StandardContext) container).getParent();
            String hn = sh.getName();
            ;
            StandardEngine se = (StandardEngine) sh.getParent();
            String sname = se.getService().getName();
            if ((sname.equals(serviceName) && hn.equals(hostName)) && pathName.equals(path)) {
                context.setLogger(null);
            }
        }
    }
}

From source file:catalina.mbeans.MBeanUtils.java

/**
 * Create an <code>ObjectName</code> for this
 * <code>MBeanFactory</code> object.
 *
 * @param domain Domain in which this name is to be created
 * @param factory The MBeanFactory to be named
 *
 * @exception MalformedObjectNameException if a name cannot be created
 *//* w  w w .  ja  va 2  s . co  m*/
public static ObjectName createObjectName(String domain, MBeanFactory factory)
        throws MalformedObjectNameException {

    ObjectName name = new ObjectName(domain + ":type=MBeanFactory");

    return (name);

}

From source file:de.acosix.alfresco.mtsupport.repo.sync.TenantAwareChainingUserRegistrySynchronizer.java

protected void logPluginConfig(final String id) {
    try {//from  www . j a  v  a  2s.c  o  m
        final StringBuilder nameBuff = new StringBuilder(200)
                .append("Alfresco:Type=Configuration,Category=Authentication,id1=managed,id2=")
                .append(URLDecoder.decode(id, "UTF-8"));
        final ObjectName name = new ObjectName(nameBuff.toString());
        if (this.mbeanServer != null && this.mbeanServer.isRegistered(name)) {
            final MBeanInfo info = this.mbeanServer.getMBeanInfo(name);
            final MBeanAttributeInfo[] attributes = info.getAttributes();
            LOGGER.debug("{} attributes:", id);
            for (final MBeanAttributeInfo attribute : attributes) {
                final Object value = this.mbeanServer.getAttribute(name, attribute.getName());
                LOGGER.debug("{} = {}", attribute.getName(), value);
            }
        }
    } catch (final MalformedObjectNameException | InstanceNotFoundException | IntrospectionException
            | AttributeNotFoundException | ReflectionException | MBeanException | IOException e) {
        LOGGER.warn("Exception during logging", e);
    }
}

From source file:catalina.mbeans.MBeanUtils.java

/**
 * Create an <code>ObjectName</code> for this
 * <code>Realm</code> object.
 *
 * @param domain Domain in which this name is to be created
 * @param realm The Realm to be named/*  ww  w .  j ava2s . c  o m*/
 *
 * @exception MalformedObjectNameException if a name cannot be created
 */
public static ObjectName createObjectName(String domain, Realm realm) throws MalformedObjectNameException {

    ObjectName name = null;
    Container container = realm.getContainer();

    if (container instanceof Engine) {
        Service service = ((Engine) container).getService();
        name = new ObjectName(domain + ":type=Realm,service=" + service.getName());
    } else if (container instanceof Host) {
        Engine engine = (Engine) container.getParent();
        Service service = engine.getService();
        name = new ObjectName(
                domain + ":type=Realm,host=" + container.getName() + ",service=" + service.getName());
    } else if (container instanceof Context) {
        String path = ((Context) container).getPath();
        if (path.length() < 1) {
            path = "/";
        }
        Host host = (Host) container.getParent();
        Engine engine = (Engine) host.getParent();
        Service service = engine.getService();
        name = new ObjectName(domain + ":type=Realm,path=" + path + ",host=" + host.getName() + ",service="
                + service.getName());
    }

    return (name);

}

From source file:azkaban.webapp.AzkabanWebServer.java

private void registerMbean(String name, Object mbean) {
    Class<?> mbeanClass = mbean.getClass();
    ObjectName mbeanName;//from w  ww .  j  av a 2s.  c  o  m
    try {
        mbeanName = new ObjectName(mbeanClass.getName() + ":name=" + name);
        mbeanServer.registerMBean(mbean, mbeanName);
        logger.info("Bean " + mbeanClass.getCanonicalName() + " registered.");
        registeredMBeans.add(mbeanName);
    } catch (Exception e) {
        logger.error("Error registering mbean " + mbeanClass.getCanonicalName(), e);
    }
}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Remove an existing Loader.//from w  w  w  . j  a  v  a2  s  .c  o m
 *
 * @param name MBean Name of the comonent to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeLoader(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    String type = oname.getKeyProperty("type");
    String serviceName = oname.getKeyProperty("service");
    Server server = ServerFactory.getServer();
    Service service = server.findService(serviceName);
    Engine engine = (Engine) service.getContainer();
    String hostName = oname.getKeyProperty("host");
    if ((type != null) && (type.equals("Loader"))) {
        String contextName = getPathStr(oname.getKeyProperty("path"));
        Host host = (Host) engine.findChild(hostName);
        Context context = (Context) host.findChild(contextName);
        // Remove this component from its parent component
        context.setLoader(null);
    } else if ((type != null) && (type.equals("DefaultLoader"))) {
        DefaultContext defaultContext = null;
        if (hostName == null) {
            defaultContext = engine.getDefaultContext();
        } else {
            Host host = (Host) engine.findChild(hostName);
            defaultContext = host.getDefaultContext();
        }
        if (defaultContext != null) {
            // Remove this component from its parent component
            defaultContext.setLoader(null);
        }
    }

}