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:com.atolcd.alfresco.audit.web.scripts.FileServerInfoGet.java

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {

    try {//w w w . jav a2  s . c o  m

        ObjectName fscName = new ObjectName("Alfresco:Name=FileServerConfig");
        MBeanServer mbs = getMBeanServer(fscName);

        // Map that will be passed to the template
        Map<String, Object> model = new HashMap<String, Object>();

        model.put("cifs_enabled", mbs.getAttribute(fscName, "CIFSServerEnabled"));
        model.put("cifs_name", mbs.getAttribute(fscName, "CIFSServerName"));
        model.put("cifs_address", mbs.getAttribute(fscName, "CIFSServerAddress"));
        model.put("ftp_enabled", mbs.getAttribute(fscName, "FTPServerEnabled"));
        model.put("nfs_enabled", mbs.getAttribute(fscName, "NFSServerEnabled"));

        return model;
    } catch (Exception e) {
        throw new WebScriptException("[FileServerInfoGet] Error in executeImpl function");
    }
}

From source file:com.espertech.esper.metrics.jmx.CommonJMXUtil.java

public static void unregisterMbean(MetricName name) {
    ObjectName on;/*from  w  w  w .  jav  a  2 s . co m*/
    try {
        on = new ObjectName(name.getMBeanName());
    } catch (MalformedObjectNameException e) {
        log.error("Failed to obtain object name for '" + name.getMBeanName() + "': " + e.getMessage(), e);
        return;
    }
    unregisterMbean(on);
}

From source file:com.goSmarter.gemfire.claimcheckpattern.CustomMetadataNamingStrategy.java

@Override
public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
    ObjectName objectName = super.getObjectName(managedBean, beanKey);

    if (this.staticNameParts.length() == 0) {
        return objectName;
    }//from   w w  w  .jav a2  s  . c o m
    return new ObjectName(objectName.getCanonicalName() + this.staticNameParts);
}

From source file:com.googlecode.psiprobe.controllers.threads.ListSunThreadsController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    List threads = null;/*from   w  w w.j a  v  a2 s.  c  o m*/
    int executionStackDepth = 1;

    MBeanServer mBeanServer = new Registry().getMBeanServer();
    ObjectName threadingOName = new ObjectName("java.lang:type=Threading");

    long[] deadlockedIds = (long[]) mBeanServer.invoke(threadingOName, "findMonitorDeadlockedThreads", null,
            null);
    long[] allIds = (long[]) mBeanServer.getAttribute(threadingOName, "AllThreadIds");

    if (allIds != null) {
        threads = new ArrayList(allIds.length);

        for (int i = 0; i < allIds.length; i++) {
            CompositeData cd = (CompositeData) mBeanServer.invoke(threadingOName, "getThreadInfo",
                    new Object[] { new Long(allIds[i]), new Integer(executionStackDepth) },
                    new String[] { "long", "int" });

            if (cd != null) {
                SunThread st = new SunThread();
                st.setId(JmxTools.getLongAttr(cd, "threadId"));
                st.setName(JmxTools.getStringAttr(cd, "threadName"));
                st.setState(JmxTools.getStringAttr(cd, "threadState"));
                st.setSuspended(JmxTools.getBooleanAttr(cd, "suspended"));
                st.setInNative(JmxTools.getBooleanAttr(cd, "inNative"));
                st.setLockName(JmxTools.getStringAttr(cd, "lockName"));
                st.setLockOwnerName(JmxTools.getStringAttr(cd, "lockOwnerName"));
                st.setWaitedCount(JmxTools.getLongAttr(cd, "waitedCount"));
                st.setBlockedCount(JmxTools.getLongAttr(cd, "blockedCount"));
                st.setDeadlocked(contains(deadlockedIds, st.getId()));

                CompositeData[] stack = (CompositeData[]) cd.get("stackTrace");
                if (stack.length > 0) {
                    CompositeData cd2 = stack[0];
                    ThreadStackElement tse = new ThreadStackElement();
                    tse.setClassName(JmxTools.getStringAttr(cd2, "className"));
                    tse.setFileName(JmxTools.getStringAttr(cd2, "fileName"));
                    tse.setMethodName(JmxTools.getStringAttr(cd2, "methodName"));
                    tse.setLineNumber(JmxTools.getIntAttr(cd2, "lineNumber", -1));
                    tse.setNativeMethod(JmxTools.getBooleanAttr(cd2, "nativeMethod"));
                    st.setExecutionPoint(tse);
                }

                threads.add(st);
            }
        }
    }
    return new ModelAndView(getViewName(), "threads", threads);
}

From source file:net.testdriven.psiprobe.controllers.threads.ListSunThreadsController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    List<SunThread> threads = null;
    int executionStackDepth = 1;

    MBeanServer mBeanServer = new Registry().getMBeanServer();
    ObjectName threadingOName = new ObjectName("java.lang:type=Threading");

    long[] deadlockedIds = (long[]) mBeanServer.invoke(threadingOName, "findMonitorDeadlockedThreads", null,
            null);/*from  w  ww.j  a v a 2 s .  c om*/
    long[] allIds = (long[]) mBeanServer.getAttribute(threadingOName, "AllThreadIds");

    if (allIds != null) {
        threads = new ArrayList<>(allIds.length);

        for (long allId : allIds) {
            CompositeData cd = (CompositeData) mBeanServer.invoke(threadingOName, "getThreadInfo",
                    new Object[] { allId, executionStackDepth }, new String[] { "long", "int" });

            if (cd != null) {
                SunThread st = new SunThread();
                st.setId(JmxTools.getLongAttr(cd, "threadId"));
                st.setName(JmxTools.getStringAttr(cd, "threadName"));
                st.setState(JmxTools.getStringAttr(cd, "threadState"));
                st.setSuspended(JmxTools.getBooleanAttr(cd, "suspended"));
                st.setInNative(JmxTools.getBooleanAttr(cd, "inNative"));
                st.setLockName(JmxTools.getStringAttr(cd, "lockName"));
                st.setLockOwnerName(JmxTools.getStringAttr(cd, "lockOwnerName"));
                st.setWaitedCount(JmxTools.getLongAttr(cd, "waitedCount"));
                st.setBlockedCount(JmxTools.getLongAttr(cd, "blockedCount"));
                st.setDeadlocked(contains(deadlockedIds, st.getId()));

                CompositeData[] stack = (CompositeData[]) cd.get("stackTrace");
                if (stack.length > 0) {
                    CompositeData cd2 = stack[0];
                    ThreadStackElement tse = new ThreadStackElement();
                    tse.setClassName(JmxTools.getStringAttr(cd2, "className"));
                    tse.setFileName(JmxTools.getStringAttr(cd2, "fileName"));
                    tse.setMethodName(JmxTools.getStringAttr(cd2, "methodName"));
                    tse.setLineNumber(JmxTools.getIntAttr(cd2, "lineNumber", -1));
                    tse.setNativeMethod(JmxTools.getBooleanAttr(cd2, "nativeMethod"));
                    st.setExecutionPoint(tse);
                }

                threads.add(st);
            }
        }
    }
    return new ModelAndView(getViewName(), "threads", threads);
}

From source file:psiprobe.controllers.threads.ListSunThreadsController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    List<SunThread> threads = null;
    int executionStackDepth = 1;

    MBeanServer mbeanServer = new Registry().getMBeanServer();
    ObjectName threadingOName = new ObjectName("java.lang:type=Threading");

    long[] deadlockedIds = (long[]) mbeanServer.invoke(threadingOName, "findMonitorDeadlockedThreads", null,
            null);//  w  w  w. j  a va 2 s .  c  om
    long[] allIds = (long[]) mbeanServer.getAttribute(threadingOName, "AllThreadIds");

    if (allIds != null) {
        threads = new ArrayList<>(allIds.length);

        for (long id : allIds) {
            CompositeData cd = (CompositeData) mbeanServer.invoke(threadingOName, "getThreadInfo",
                    new Object[] { id, executionStackDepth }, new String[] { "long", "int" });

            if (cd != null) {
                SunThread st = new SunThread();
                st.setId(JmxTools.getLongAttr(cd, "threadId"));
                st.setName(JmxTools.getStringAttr(cd, "threadName"));
                st.setState(JmxTools.getStringAttr(cd, "threadState"));
                st.setSuspended(JmxTools.getBooleanAttr(cd, "suspended"));
                st.setInNative(JmxTools.getBooleanAttr(cd, "inNative"));
                st.setLockName(JmxTools.getStringAttr(cd, "lockName"));
                st.setLockOwnerName(JmxTools.getStringAttr(cd, "lockOwnerName"));
                st.setWaitedCount(JmxTools.getLongAttr(cd, "waitedCount"));
                st.setBlockedCount(JmxTools.getLongAttr(cd, "blockedCount"));
                st.setDeadlocked(contains(deadlockedIds, st.getId()));

                CompositeData[] stack = (CompositeData[]) cd.get("stackTrace");
                if (stack.length > 0) {
                    CompositeData cd2 = stack[0];
                    ThreadStackElement tse = new ThreadStackElement();
                    tse.setClassName(JmxTools.getStringAttr(cd2, "className"));
                    tse.setFileName(JmxTools.getStringAttr(cd2, "fileName"));
                    tse.setMethodName(JmxTools.getStringAttr(cd2, "methodName"));
                    tse.setLineNumber(JmxTools.getIntAttr(cd2, "lineNumber", -1));
                    tse.setNativeMethod(JmxTools.getBooleanAttr(cd2, "nativeMethod"));
                    st.setExecutionPoint(tse);
                }

                threads.add(st);
            }
        }
    }
    return new ModelAndView(getViewName(), "threads", threads);
}

From source file:com.custardsource.maven.plugins.jmx.Invoke.java

@Override
public Object execute(MBeanServerConnection connection) throws Exception {
    ObjectName name = new ObjectName(objectName);
    int len = parameters == null ? 0 : parameters.length;
    String[] signature = new String[len];
    Object[] arguments = new Object[len];

    ConvertUtilsBean converter = new ConvertUtilsBean();

    for (int i = 0; i < len; i++) {
        signature[i] = parameters[i].getType();
        arguments[i] = converter.convert(parameters[i].getValue(),
                ClassUtils.getClass(parameters[i].getType()));
        if (signature[i].equals("java.lang.String") && arguments[i] == null) {
            arguments[i] = "";
        }/*from   w  w  w .  j  a va  2s  .  c  o  m*/
    }
    return connection.invoke(name, operation, arguments, signature);
}

From source file:Main.java

/**
 * /*from  www  .jav a  2s.  c  o  m*/
 * @param mBean
 * @param type
 * @param name
 * @param otherParams
 *            comma-separated string containing additional parameters for
 *            the MBean server
 */
public static ObjectName registerMBean(Object mBean, String type, String name, String otherParams) {
    try {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName objName = new ObjectName(
                "enkive:type=" + type + ",name=" + name + (otherParams == null ? "" : "," + otherParams));
        server.registerMBean(mBean, objName);
        return objName;
    } catch (InstanceAlreadyExistsException e) {
        if (LOGGER.isWarnEnabled()) {
            LOGGER.warn("tried to re-register mbean", e);
        }
    } catch (MBeanRegistrationException e) {
        LOGGER.error("could not register mbean", e);
    } catch (NotCompliantMBeanException e) {
        LOGGER.error("noncompliant mbean", e);
    } catch (MalformedObjectNameException e) {
        LOGGER.error("noncompliant mbean name", e);
    }

    return null;
}

From source file:com.atolcd.alfresco.audit.web.scripts.RuntimeInfoGet.java

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {

    try {//from ww  w . j a v  a2  s.c  om

        // Map that will be passed to the template
        Map<String, Object> model = new HashMap<String, Object>();

        ObjectName runtimeName = new ObjectName("Alfresco:Name=Runtime");
        MBeanServer mbs = getMBeanServer(runtimeName);

        model.put("FreeMemory", (Long) mbs.getAttribute(runtimeName, "FreeMemory") / 1024 / 1024);
        model.put("MaxMemory", (Long) mbs.getAttribute(runtimeName, "MaxMemory") / 1024 / 1024);
        model.put("TotalMemory", (Long) mbs.getAttribute(runtimeName, "TotalMemory") / 1024 / 1024);

        return model;
    } catch (Exception e) {
        throw new WebScriptException("[RuntimeInfosGet] Error in executeImpl function : \n" + e.getMessage());
    }

}

From source file:fr.xebia.springframework.jdbc.ManagedBasicDataSource.java

@Override
public ObjectName getObjectName() throws MalformedObjectNameException {
    if (objectName == null) {
        objectName = new ObjectName("javax.sql:type=DataSource,name=" + beanName);
    }/*from   w  w  w.j  a  va2  s  .c  o m*/
    return objectName;
}