RMI definitions and MBEAN access from jsp files
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Elisabeth_Bachler
Posted On:   Tuesday, July 19, 2005 10:35 AM

Hello, I am quite new to JMX so please forgive me if it is a simple question. I am using the jmx version that comes with tomcat-5.5.9 (jmx_1_2_1) I have a server on a machine (with a RMI connector defined). I need to create a client (jsp) to remotly access the operations defined in the MBEAN. My questions are: How can I call the rmi connector? Once the connection is created, how can I call the mbean?. I normally call the mbeans as java bean (using: .. but I have never done anything remotly so I don't know how to do it. Once the connection is not needed, how can I "disconnect"? Sorry if those are trivial questions but    More>>

Hello,

I am quite new to JMX so please forgive me if it is a simple question.


I am using the jmx version that comes with tomcat-5.5.9 (jmx_1_2_1)


I have a server on a machine (with a RMI connector defined).

I need to create a client (jsp) to remotly access the operations defined in the MBEAN.


My questions are:

  • How can I call the rmi connector?

  • Once the connection is created, how can I call the mbean?. I normally call the mbeans as java bean (using: .. but I have never done anything remotly so I don't know how to do it.

  • Once the connection is not needed, how can I "disconnect"?



  • Sorry if those are trivial questions but the answers are quite important to me. I always find complicated examples on the web but really nothing related to what I need to do.


    Please, help!

       <<Less

    Re: RMI definitions and MBEAN access from jsp files

    Posted By:   Elisabeth_Bachler  
    Posted On:   Friday, July 22, 2005 07:24 AM

    I have managed to connect to the RMI Server but now I cannot set/get the attributes of the MBEAN!!!


    I swear the whole .jsp file worked several time (I even sent notifications!!)... but for some unknown reasons nothing works now!!


    Please, help!


    Here is the info I have so far:


  • Server up and running

  • LOG OUTPUT:


    Create an RMI connector client and connect it to the RMI connector server


    Get an MBeanServerConnection


    Put proxy into scope


    Domains:
    Domain[0]=JMImplementation


    Bean count=1


    Add notification listener....



  • INDEX.JSP








    <%@page errorPage="errorPage.jsp" %>


    <%@page language="java" %>


    <%@page import="java.util.*" %>


    <%@page import="java.io.*" %>


    <%@page import="javax.servlet.*, javax.servlet.http.*"%>


    <%@page import="javax.servlet.http.HttpServletRequest"%>


    <%@page import="javax.management.Attribute"%>


    <%@page import="javax.management.MBeanServerConnection"%>


    <%@page import="javax.management.MBeanServerInvocationHandler"%>


    <%@page import="javax.management.ObjectName"%>


    <%@page import="javax.management.remote.JMXConnector"%>


    <%@page import="javax.management.remote.JMXConnectorFactory"%>


    <%@page import="javax.management.remote.JMXServiceURL"%>


    <%@page import="util.SimpleStandardMBean"%>


    <%@page import="util.*"%>


    <%


    // Create an RMI Connector client and connect it to the RMI connector server


    //--------------------------------------------------------------------------


    JMXConnector jmxc = null;


    boolean connect=true;


    try


    {


    System.out.println("
    Create an RMI connector client and " +
    "connect it to the RMI connector server");
    JMXServiceURL url = new JMXServiceURL(
    "service:jmx:rmi:///jndi/rmi://localhost:9999/server"

    );


    jmxc = JMXConnectorFactory.connect(url,null);


    }


    catch (Exception e)


    {


    System.out.println("No se puede conectar al servidor...");


    e.printStackTrace();


    connect=false;


    }


    if (connect)


    {


    // Get an MBeanServerConnection


    //-----------------------------


    System.out.println("
    Get an MBeanServerConnection");


    ObjectName mbeanName = new ObjectName


    ("MBean:type=SimpleStandard");


    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();


    SimpleStandardMBean mbean = (SimpleStandardMBean)
    MBeanServerInvocationHandler.newProxyInstance (mbsc,mbeanName, SimpleStandardMBean.class,true);


    // put the proxy into the scope, e.g.: request scope


    System.out.println("
    Put proxy into scope");


    request.setAttribute("mbean", mbean);


    // Get domain from MBeanServer


    //---------------------------


    System.out.println("
    Domains:");


    String domains[] = mbsc.getDomains();


    for (int i=0; i

    {


    System.out.println(" Domain["+i+"]="+domains[i]);


    }


    // Get MBean count


    //----------------


    System.out.println("
    Bean count="+mbsc.getMBeanCount());


    // Add notification listener on SimpleStandard MBean


    //--------------------------------------------------


    ClientListener listener = new ClientListener();


    System.out.println("
    Add notification listener....");


    mbsc.addNotificationListener(mbeanName, listener, null, null);


    // Invoke the reset method


    //-----------------------


    System.out.println("
    Invoke reset() in SimpleStandardMBean...");


    mbsc.invoke(mbeanName,"reset", null,null);


    // Sleep for 2 seconds in order to receive the notification before removing


    // the notification listener


    //----------------------------------------------------------------------------


    System.out.println("
    Waiting for notification....");


    Thread.sleep(2000);


    // GET THE STATE


    //--------------


    String string = mbean.getState();


    System.out.println("string="+string);


    %>











    <%


    // Remove notification listener on SImpleStandard MBean


    //-----------------------------------------------------


    System.out.println("
    Remove notification listener on SImpleStandard MBean...");


    mbsc.removeNotificationListener(mbeanName, listener);


    // Unregister SimpleStandard MBean


    //--------------------------------


    System.out.println("
    Unregister SimpleStandard MBean...");


    mbsc.unregisterMBean(mbeanName);


    // Close MBeanServer connection


    //--------------------------


    System.out.println("
    Close MBean Server connection...");


    jmxc.close();


    }


    else


    {


    %>


    CONEXIÓN IMPOSIBLE CON SERVIDOR


    <%


    }


    %>


  • About | Sitemap | Contact