Example usage for javax.management MBeanServer invoke

List of usage examples for javax.management MBeanServer invoke

Introduction

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

Prototype

public Object invoke(ObjectName name, String operationName, Object params[], String signature[])
            throws InstanceNotFoundException, MBeanException, ReflectionException;

Source Link

Usage

From source file:be.fedict.trust.service.snmp.SNMPInterceptor.java

public static void setValue(String oid, String service, Long value) {

    LOG.debug("set value of counter oid=" + oid + " @ service=" + service + " to " + value);

    try {//from w w w.j  av a2s . c om
        for (MBeanServer mBeanServer : MBeanServerFactory.findMBeanServer(null)) {
            mBeanServer.invoke(new ObjectName(service), "setValue", new Object[] { oid, value },
                    new String[] { "java.lang.String", "java.lang.Long" });

        }
    } catch (Exception e) {
        LOG.error("Failed to contact SNMP Mbean: " + e.getMessage(), e);
    }
}

From source file:be.fedict.trust.service.snmp.SNMPInterceptor.java

public static void increment(String oid, String service, Long increment) {

    LOG.debug("increment counter oid=" + oid + " @ service=" + service + " with " + increment);

    try {/*from  ww w.  j a  v  a2 s  .  c o m*/
        for (MBeanServer mBeanServer : MBeanServerFactory.findMBeanServer(null)) {
            mBeanServer.invoke(new ObjectName(service), "increment", new Object[] { oid, increment },
                    new String[] { "java.lang.String", "java.lang.Long" });

        }
    } catch (Exception e) {
        LOG.error("Failed to contact SNMP Mbean: " + e.getMessage(), e);
    }

}

From source file:be.fedict.trust.service.snmp.SNMPInterceptor.java

private static Long getValue(String oid, String service) {

    LOG.debug("get value of counter oid=" + oid + " @ service=" + service);

    try {// w  w w . ja  v  a2s.  c om
        for (MBeanServer mBeanServer : MBeanServerFactory.findMBeanServer(null)) {
            return (Long) mBeanServer.invoke(new ObjectName(service), "getValue", new Object[] { oid },
                    new String[] { "java.lang.String" });

        }
    } catch (Exception e) {
        LOG.error("Failed to contact SNMP Mbean: " + e.getMessage(), e);
    }

    return 0L;
}

From source file:com.meltmedia.cadmium.deployer.JBossUtil.java

public static void addVirtualHost(String domain, Logger log) throws InstanceNotFoundException,
        MalformedObjectNameException, ReflectionException, MBeanException, NullPointerException {
    MBeanServer server = MBeanServerLocator.locateJBoss();
    boolean aliasFound = server.isRegistered(new ObjectName("jboss.web:type=Host,host=" + domain));
    if (!aliasFound) {
        log.info("Adding vHost {} to jboss", domain);
        Host host = (Host) server.instantiate("org.apache.catalina.core.StandardHost");
        host.setName(domain);//  w w  w  .  j a  v a 2  s.  c  o m

        server.invoke(new ObjectName("jboss.web:type=Engine"), "addChild", new Object[] { host },
                new String[] { "org.apache.catalina.Container" });
    }
}

From source file:com.googlecode.psiprobe.beans.JBossResourceResolverBean.java

public boolean resetResource(Context context, String resourceName, ContainerWrapperBean containerWrapper)
        throws NamingException {
    try {//from   ww w . j a va 2s. c o m
        ObjectName poolOName = new ObjectName("jboss.jca:service=ManagedConnectionPool,name=" + resourceName);
        MBeanServer server = getMBeanServer();
        if (server != null) {
            try {
                server.invoke(poolOName, "stop", null, null);
                server.invoke(poolOName, "start", null, null);
                return true;
            } catch (Exception e) {
                logger.error("Could not reset resource \"" + resourceName + "\"", e);
            }
        }
        return false;
    } catch (MalformedObjectNameException e) {
        throw new NamingException("Resource name: \"" + resourceName + "\" makes a malformed ObjectName");
    }
}

From source file:net.gcolin.simplerepo.test.AbstractRepoTest.java

protected Object executeOperationJmx(String name, String operation, Object[] arguments, String[] signature)
        throws Exception {
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    ObjectName oname = server.queryNames(new ObjectName(name), null).iterator().next();
    return server.invoke(oname, operation, arguments, signature);
}

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 www. ja  v  a  2  s  .co  m
    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: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 om
    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: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 ww  .  ja  v  a2s. c o  m
    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.app.server.node.NodeServer.java

/**
 * This method implements the node server request
 *//*from   w  ww .j  ava 2  s. com*/
public void run() {
    //deployer.start();
    try {
        ObjectName objName = new ObjectName("com.app.server:type=deployer,service=RMIDeployer");
        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        mbeanServer.createMBean("com.app.server.node.RMIDeployer", objName);
        mbeanServer.invoke(objName, "init", new Object[] { deployerList },
                new String[] { Vector.class.getName() });
        ServerConfig serverConfig = new ServerConfig();
        serverConfig.setRmiregistryport(port + "");
        serverConfig.setCachedir("d:/AppServer/cache");
        mbeanServer.invoke(objName, "init", new Object[] { serviceList, serverConfig, mbeanServer },
                new String[] { Vector.class.getName(), ServerConfig.class.getName(),
                        MBeanServer.class.getName() });
        InetAddress inet = null;
        inet = InetAddress.getLocalHost();
        mbeanServer.invoke(objName, "deploy",
                new Object[] { new URL("file:///D:/AppServer/deploy/rmitest.rmi"), false, null,
                        inet.getHostName() + ":" + port },
                new String[] { URL.class.getName(), boolean.class.getName(), ClassLoader.class.getName(),
                        String.class.getName() });
        //deployer.deploy(new URL("file:///D:/AppServer/deploy/rmitest.rmi"),false,null,inet.getHostName()+":"+port);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}