Jump to content

Talk:Java Management Extensions

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Sharpreetsingh (talk | contribs) at 15:54, 4 April 2011 (On Client Side). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
WikiProject iconJava Stub‑class Low‑importance
WikiProject iconThis article is within the scope of WikiProject Java, a collaborative effort to improve the coverage of Java on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StubThis article has been rated as Stub-class on Wikipedia's content assessment scale.
LowThis article has been rated as Low-importance on the project's importance scale.

Merge proposal (section transfered from old Managed_Bean talk page)

Article is not notable enough for a standalone article, but some content can be saved. --M4gnum0n (talk) 21:39, 13 May 2009 (UTC)[reply]

I doubt it. Rp (talk) 15:13, 16 June 2009 (UTC)[reply]
It's been viewed 1378 times in May. I came to it by looking it up by name. Hidden in another article I would not have found it. Possibly many of the other viewers would not have, either. On the other hand it is not notable in itself. Maybe it would be better in a dictionary? Merge it but put it in the dictionary as well. - KoolerStill (talk) 16:04, 26 June 2009 (UTC)[reply]
The article may be extended. But I am against a merger. When extended, I would even welcome that the Managed Bean part should be transferred in a new article. Sae1962 (talk) 13:10, 23 March 2011 (UTC)[reply]

A Basic Simple Example of Remote Connection Using JMX

If it is felt to add following in Article, following wiki standards. I have masde this simple example for basic understanding how JMX works, because i get bit problem in understanding this. Now it looks simple but once it was not.

On Server Side

MBeans is combination of an Interface and It's Implementation which is given follows:-

1) HelloMBean.java - Consist of INterface.

package jmxtryout;

public interface HelloMBean
{
public String Tryout();
public String add(String x, String y);
public String getName();
}

2) Hello.java (Consist of Implementation of Interface HelloMBean

package jmxtryout;
public class Hello implements HelloMBean
{
public String Tryout()
{
return "Tried It First Time";
}
public String add(String x, String y)
{
return x + y;
}
private String name = "Ranjeet";
public String getName()
{
return this.name;
}
}

3) Main.java -> This contains registering MBeans code and Object is created which will recreated on client side for internal communication

package jmxtryout;
import java.lang.management.ManagementFactory;
import java.util.Scanner;
import javax.management.MBeanServer;
import javax.management.ObjectName;
public class Main {
public static void main(String[] args) throws Exception {
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("HelloMBean:Name=HelloMBean,type=Hello");
HelloMBean mbean = new Hello();
mbs.registerMBean(mbean, name);
System.out.println("Waiting forever...");
Thread.sleep(Long.MAX_VALUE);
} catch (Exception e) {
System.out.println("Exception" + e.getMessage());
}
}
}

Now run server using following:

java -Dcom.sun.management.jmxremote.port=8877 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar DesktopApplication3.jar

On Client Side

here we will create objectName same as of above and will invoke operations and call attribute values as shown below.

package jmxtryoutfetch;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.management.MBeanServerConnection;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import sun.applet.Main;
class Client
{
public static void main(String[] args) {
try
{
JMXServiceURL address = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8877/jmxrmi"); //At Place of Localhost write IP of remote system
JMXConnector connector = JMXConnectorFactory.connect(address);
MBeanServerConnection mbs = connector.getMBeanServerConnection();
ObjectName obj = new ObjectName("HelloMBean:Name=HelloMBean,type=Hello");
System.out.println(mbs.getAttribute(obj, "Name"));
System.out.println(mbs.invoke(obj,"Tryout", new Object[]{},new String[]{}));
System.out.println(mbs.invoke(obj,"add", new Object[]{"Wa +"," taa"},new String[]{"java.lang.String","java.lang.String"}));
}
catch (Exception ex)
{
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

When Program is run it will show the output required.

Thank You