Example usage for javax.management MBeanServerInvocationHandler newProxyInstance

List of usage examples for javax.management MBeanServerInvocationHandler newProxyInstance

Introduction

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

Prototype

public static <T> T newProxyInstance(MBeanServerConnection connection, ObjectName objectName,
        Class<T> interfaceClass, boolean notificationBroadcaster) 

Source Link

Document

Return a proxy that implements the given interface by forwarding its methods through the given MBean server to the named MBean.

Usage

From source file:org.apache.qpid.test.utils.JMXTestUtils.java

@SuppressWarnings("static-access")
public ManagedExchange getManagedExchange(String exchangeName) {
    String query = getExchangeObjectName("test", exchangeName);

    Set<ObjectName> objectNames = queryObjects(query);

    _test.assertNotNull("Null ObjectName Set returned", objectNames);
    _test.assertEquals("Incorrect number of exchange with name '" + exchangeName + "' returned", 1,
            objectNames.size());//from ww  w . ja v a 2  s .  co m

    // We have verified we have only one value in objectNames so return an mbean proxy for it
    ObjectName objectName = objectNames.iterator().next();
    _test.getLogger().info("Loading: " + objectName);

    return MBeanServerInvocationHandler.newProxyInstance(_mbsc, objectName, ManagedExchange.class, false);
}

From source file:org.bigmouth.nvwa.utils.jmx.JmxClientTemplate.java

/**
 * MBean?.// w ww .j  a v  a 2s .c  o  m
 */
public <T> T createMBeanProxy(final String mbeanName, final Class<T> mBeanInterface) {
    assertConnected();

    ObjectName objectName = buildObjectName(mbeanName);
    return (T) MBeanServerInvocationHandler.newProxyInstance(connection, objectName, mBeanInterface, false);
}

From source file:org.camid.rulemanager.ServerShellClientMain.java

public static EPServiceProviderJMXMBean ServerShellClientMain() throws Exception {

    log.info("Loading properties");

    log.info("Attach to server via JMX");
    //        JMXServiceURL url = new JMXServiceURL(properties.getProperty(ServerShellConstants.MGMT_SERVICE_URL));
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:5554/server");

    //        String jmxServiceURL = "service:jmx:rmi:///jndi/rmi://localhost:5554/server";
    JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
    ObjectName mBeanName = new ObjectName(ServerShellConstants.MGMT_MBEAN_NAME);
    EPServiceProviderJMXMBean proxy = (EPServiceProviderJMXMBean) MBeanServerInvocationHandler
            .newProxyInstance(mbsc, mBeanName, EPServiceProviderJMXMBean.class, true);

    //        proxy.destroy("sensor1c");
    return proxy;

    // Create statement via JMX
    //           System.out.println("Creating a statement via Java Management Extensions (JMX) MBean Proxy");
    //           proxy.createEPL("select * from sensor(value>20)","filter", "null");
    ////from   www . j a  v  a2s  .co  m
    //
    //        System.out.println("Destroing statement via Java Management Extensions (JMX) MBean Proxy");
    //        proxy.destroy("filterStatement");
    //
    //
    //        System.out.println("Exiting");
    //        System.exit(-1);
}

From source file:org.jboss.remoting.transport.http.HTTPServerInvoker.java

private ThreadPool createThreadPoolProxy(ObjectName objName) {
    ThreadPool pool;//  w  ww  .j a  v a2s  .  com
    MBeanServer server = getMBeanServer();
    if (server != null) {
        ThreadPoolMBean poolMBean = (ThreadPoolMBean) MBeanServerInvocationHandler.newProxyInstance(server,
                objName, ThreadPoolMBean.class, false);
        pool = poolMBean.getInstance();
    } else {
        throw new RuntimeException(
                "Can not register MBean ThreadPool as the ServerInvoker has not been registered with a MBeanServer.");
    }
    return pool;
}

From source file:org.jboss.test.web.test.FormAuthUnitTestCase.java

/** Test that the war which uses <security-domain flushOnSessionInvalidation="true">
 * in the jboss-web.xml does not have any jaas security domain cache entries
 * after the web session has been invalidated.
 */// w w w .  j  a  v  a2s  .c  om
public void testFlushOnSessionInvalidation() throws Exception {
    log.info("+++ testFlushOnSessionInvalidation");
    MBeanServerConnection conn = (MBeanServerConnection) getServer();
    ObjectName name = new ObjectName("jboss.security:service=JaasSecurityManager");
    JaasSecurityManagerServiceMBean secMgrService = (JaasSecurityManagerServiceMBean) MBeanServerInvocationHandler
            .newProxyInstance(conn, name, JaasSecurityManagerServiceMBean.class, false);

    // Access a secured servlet to create a session and jaas cache entry
    doSecureGetWithLogin("form-auth/restricted/SecuredServlet");

    // Validate that the jaas cache has 1 principal
    List principals = secMgrService.getAuthenticationCachePrincipals("jbossweb-form-auth");
    assertTrue("jbossweb-form-auth has one principal", principals.size() == 1);

    // Logout to clear the cache
    doSecureGet("form-auth/Logout");
    principals = secMgrService.getAuthenticationCachePrincipals("jbossweb-form-auth");
    log.info("jbossweb-form-auth principals = " + principals);
    assertTrue("jbossweb-form-auth has no cache principals", principals.size() == 0);
}

From source file:org.red5.server.service.Installer.java

/**
 * Returns the LoaderMBean.//w w w . j  a v a2 s.com
 * @return LoaderMBean
 */
@SuppressWarnings("cast")
public LoaderMBean getLoader() {
    MBeanServer mbs = JMXFactory.getMBeanServer();

    ObjectName oName = JMXFactory.createObjectName("type", "TomcatLoader");

    LoaderMBean proxy = null;
    if (mbs.isRegistered(oName)) {
        proxy = (LoaderMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, oName, LoaderMBean.class,
                true);
        log.debug("Loader was found");
    } else {
        log.warn("Loader not found");
    }
    return proxy;
}

From source file:org.red5.server.service.WarDeployer.java

/**
 * Returns the LoaderMBean.//  ww w  .ja  v a 2s. c  o m
 * @return
 */
public LoaderMBean getLoader() {
    MBeanServer mbs = JMXFactory.getMBeanServer();

    ObjectName oName = JMXFactory.createObjectName("type", "TomcatLoader");

    LoaderMBean proxy = null;
    if (mbs.isRegistered(oName)) {
        proxy = (LoaderMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, oName, LoaderMBean.class,
                true);
        log.debug("Loader was found");
    } else {
        log.warn("Loader not found");
    }
    return proxy;
}

From source file:org.rhq.enterprise.gui.startup.StartupServlet.java

/**
 * Starts the plugin deployer which will effectively ask the plugin deployer to persist information about all
 * detected agent and server plugins.//w  ww .  ja va 2s  . c om
 *
 * Because this will scan and register the initial plugins right now, make sure this is called prior
 * to starting the master plugin container; otherwise, the master PC will not have any plugins to start.
 *
 * @throws ServletException
 */
private void startPluginDeployer() throws ServletException {
    log.info("Starting the agent/server plugin deployer...");

    try {
        PluginDeploymentScannerMBean deployer_mbean;
        MBeanServer mbs = MBeanServerLocator.locateJBoss();
        ObjectName name = PluginDeploymentScannerMBean.OBJECT_NAME;
        Class<?> iface = PluginDeploymentScannerMBean.class;
        deployer_mbean = (PluginDeploymentScannerMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, name,
                iface, false);
        deployer_mbean.startDeployment();
    } catch (Exception e) {
        throw new ServletException("Cannot start the agent/server plugin deployer!", e);
    }
}

From source file:org.rhq.enterprise.gui.startup.StartupServlet.java

/**
 * Installs the JAAS login modules so our users can login.
 *
 * @throws ServletException/*  ww w.j a v  a  2s.  c  o m*/
 */
private void installJaasModules() throws ServletException {
    log.info("Installing JAAS login modules...");

    try {
        CustomJaasDeploymentServiceMBean jaas_mbean;
        MBeanServer mbs = MBeanServerLocator.locateJBoss();
        ObjectName name = CustomJaasDeploymentServiceMBean.OBJECT_NAME;
        Class<?> iface = CustomJaasDeploymentServiceMBean.class;
        jaas_mbean = (CustomJaasDeploymentServiceMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, name,
                iface, false);
        jaas_mbean.installJaasModules();
    } catch (Exception e) {
        throw new ServletException("Cannot install JAAS login modules!", e);
    }
}

From source file:org.rhq.enterprise.installer.ServerInformation.java

private File getDeployDirectory() {
    if (deployDirectory == null) {
        MBeanServer mbs = getMBeanServer();
        ObjectName name = ObjectNameFactory.create("jboss.system:type=ServerConfig");
        Object mbean = MBeanServerInvocationHandler.newProxyInstance(mbs, name, ServerConfig.class, false);

        deployDirectory = new File(((ServerConfig) mbean).getServerHomeDir(), "deploy");
    }//w w  w . ja v a 2s .  com

    return deployDirectory;
}