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.MBeanUtils.java

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

    ObjectName name = null;
    Host host = (Host) context.getParent();
    Service service = ((Engine) host.getParent()).getService();
    String path = context.getPath();
    if (path.length() < 1)
        path = "/";
    name = new ObjectName(domain + ":type=Context,path=" + path + ",host=" + host.getName() + ",service="
            + service.getName());
    return (name);

}

From source file:com.continuent.tungsten.common.jmx.JmxManager.java

public static ObjectName generateMBeanObjectName(Class<?> mbeanClass) throws Exception {
    String className = mbeanClass.getName();
    String type = className;//from   w  w  w .j a  va2s  . co  m
    String domain = "default";

    int lastPeriod = className.lastIndexOf('.');
    if (lastPeriod != -1) {
        domain = className.substring(0, lastPeriod);
        type = className.substring(className.lastIndexOf('.') + 1);
    }

    String name = String.format("%s:type=%s", domain, type);
    ObjectName objName = new ObjectName(name);

    if (logger.isDebugEnabled()) {
        logger.debug("ObjectName is: " + objName.toString());
    }
    return objName;
}

From source file:com.continuent.tungsten.common.jmx.JmxManager.java

public static ObjectName generateMBeanObjectName(String mbeanName, String typeName) throws Exception {
    ObjectName name = new ObjectName(mbeanName + ":type=" + typeName);
    if (logger.isDebugEnabled()) {
        logger.debug("ObjectName is: " + name.toString());
    }/*www  . j  a  va 2  s.c  o  m*/
    return name;
}

From source file:catalina.mbeans.MBeanUtils.java

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

    ObjectName name = null;
    Object container = environment.getNamingResources().getContainer();
    if (container instanceof Server) {
        name = new ObjectName(
                domain + ":type=Environment" + ",resourcetype=Global,name=" + environment.getName());
    } 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=Environment" + ",resourcetype=Context,path=" + path + ",host="
                + host.getName() + ",service=" + service.getName() + ",name=" + environment.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=Environment" + ",resourcetype=HostDefaultContext,host="
                    + host.getName() + ",service=" + service.getName() + ",name=" + environment.getName());
        } else if (container instanceof Engine) {
            Engine engine = (Engine) container;
            Service service = engine.getService();
            name = new ObjectName(domain + ":type=Environment" + ",resourcetype=ServiceDefaultContext,service="
                    + service.getName() + ",name=" + environment.getName());
        }
    }

    return (name);

}

From source file:com.springsource.hq.plugin.tcserver.plugin.appmgmt.TomcatJmxScriptingApplicationManager.java

private boolean isTcRuntime250OrLater(String objectName, String operationName,
        int expected25OrLaterArgumentCount, ConfigResponse config) throws JMException, IOException {
    MBeanServerConnection mBeanServer = mxUtil.getMBeanServer(config.toProperties());
    MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(new ObjectName(objectName));
    for (MBeanOperationInfo operationInfo : mBeanInfo.getOperations()) {
        if (operationInfo.getName().equals(operationName)
                && (expected25OrLaterArgumentCount == operationInfo.getSignature().length)) {
            return true;
        }//from   ww w.  j a v  a  2s  .  c  o  m
    }
    return false;
}

From source file:com.mustardgrain.solr.SolrClient.java

private static Runnable getStatsRunner(final WeakReference<SolrClient> lbRef) {
    return new Runnable() {

        @Override//from   w w w.  j a  v  a 2  s.  c o  m
        public void run() {
            SolrClient lb = lbRef.get();
            if (lb != null && lb.serverStats != null && LOG.isInfoEnabled()) {
                StringBuilder sb = new StringBuilder();
                sb.append("server responses over past ");
                sb.append(TimeUnit.MILLISECONDS.toMinutes(lb.statsInterval));
                sb.append(" mins (good/timeout/zero found) and cache hit ratio: ");
                boolean appendComma = false;

                for (Map.Entry<String, SolrStats> entry : lb.serverStats.entrySet()) {
                    if (appendComma)
                        sb.append(", ");

                    String server = entry.getKey();
                    SolrStats stats = entry.getValue();
                    String hitRatio = getHitRatio(server);

                    sb.append(server);
                    sb.append(": ");
                    sb.append(stats.getSuccesses());
                    sb.append("/");
                    sb.append(stats.getReadTimeouts());
                    sb.append("/");
                    sb.append(stats.getEmptyResults());
                    sb.append(" ");
                    sb.append(hitRatio);

                    appendComma = true;

                    stats.reset(); // Reset the counters once printed
                }

                LOG.info(sb);
            }
        }

        /**
         * Determines the hit ratio for the query result cache by calling
         * the SolrServer via JMX and reading its MBean containing that
         * information.
         * @param server Server from which to pull information
         * @return String form of hit ratio (either "n/a" or "xx%")
         */

        private String getHitRatio(String server) {
            String hitRatio = "n/a";
            JMXConnector jmxc = null;

            try {
                URL url = new URL(server);
                String domain = url.getPath();

                if (domain.startsWith("/"))
                    domain = domain.substring(1);

                ObjectName name = new ObjectName(
                        domain + ":id=org.apache.solr.search.LRUCache,type=queryResultCache");
                JMXServiceURL jmxUrl = new JMXServiceURL(
                        "service:jmx:rmi:///jndi/rmi://" + url.getHost() + ":7199/jmxrmi");
                jmxc = JMXConnectorFactory.connect(jmxUrl, null);
                MBeanServerConnection con = jmxc.getMBeanServerConnection();

                Object result = con.getAttribute(name, "hitratio");
                hitRatio = (int) (Float.parseFloat(String.valueOf(result)) * 100.0f) + "%";
            } catch (Exception e) {
                LOG.error(getNestedErrorMessages(e));
            } finally {
                if (jmxc != null) {
                    try {
                        jmxc.close();
                    } catch (Exception e) {
                        LOG.error(getNestedErrorMessages(e));
                    }
                }
            }

            return hitRatio;
        }

    };
}

From source file:catalina.mbeans.MBeanFactory.java

/**
  * Create a new StandardContext./*from ww w .j  a  v a  2 s .  co  m*/
  *
  * @param parent MBean Name of the associated parent component
  * @param path The context path for this Context
  * @param docBase Document base directory (or WAR) for this Context
  *
  * @exception Exception if an MBean cannot be created or registered
  */
public String createStandardContext(String parent, String path, String docBase) throws Exception {

    // Create a new StandardContext instance
    StandardContext context = new StandardContext();
    path = getPathStr(path);
    context.setPath(path);
    context.setDocBase(docBase);
    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    Host host = (Host) engine.findChild(pname.getKeyProperty("host"));

    // Add context to the host
    host.addChild(context);

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("StandardContext");

    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), context);
    return (oname.toString());

}

From source file:com.spotify.reaper.cassandra.JmxProxy.java

public ColumnFamilyStoreMBeanIterator(MBeanServerConnection mbeanServerConn)
        throws MalformedObjectNameException, NullPointerException, IOException {
    ObjectName query = new ObjectName("org.apache.cassandra.db:type=ColumnFamilies,*");
    resIter = mbeanServerConn.queryNames(query, null).iterator();
    this.mbeanServerConn = mbeanServerConn;
}

From source file:catalina.mbeans.MBeanFactory.java

/**
  * Create a new StandardEngine.//ww  w. j  av a2 s .co  m
  *
  * @param parent MBean Name of the associated parent component
  * @param name Unique name of this Engine
  * @param defaultHost Default hostname of this Engine
  *
  * @exception Exception if an MBean cannot be created or registered
  */
public String createStandardEngine(String parent, String name, String defaultHost) throws Exception {

    // Create a new StandardEngine instance
    StandardEngine engine = new StandardEngine();
    engine.setName(name);
    engine.setDefaultHost(defaultHost);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("name"));
    service.setContainer(engine);

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("StandardEngine");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), engine);
    return (oname.toString());

}