JMX rapid cognition

I. INTRODUCTION

Glossary JMX Java Management Extensions, the Java Management Extensions.

What to do

Management application, to view the device information, see the application resources, monitoring changes in resources

Calls in

Support cross-platform, multi-protocol (soap, http, html, snmp, jconsole)

Second, the historical changes

Drafts JSR No. theme description Whether to enable status the reason Submitters
14 Dec, 1998 3 JMX 1.1和1.2 JMX specification developed for the Web, distributed, dynamic and modular programs, provide management architecture Yes Undo In Java 5.2 version has become the trademark of Oracle Corporation Sun MicrosystemsConsumer & EmbeddedEmbedded System Software Group
30 May,2000 70 JMX adaptation IIOP protocol IIOP protocol specification established based adapter to support CORBA clients to access the JMX agent no Undo Corporate strategy adjustment, not optimistic about JMX application in CORBA client IONA Technologies PlcBen Beazley
27 Jun, 2000 71 JMX-TMN definitions Between the normative Telecommunications Management Network (TMN) and JMX Interoperability no Undo The person in charge should be standardized to withdraw, JSR3 already mentioned this support, but have not been realized Bull S.A. (BullSoft)
21 Aug, 2001 146 JMX support WBem Service Definition provides protocol adapter for WBEM Services no Undo JSR48 WBEN standard service by WBEN Solutions, Inc. presented. The two companies made this specification, a year and a half later, to stop cooperation Sun Microsystems, Inc.
27 Nov, 2001 160 JMX Remote API call The API extends the JMX1.2API, providing remote access to JMX MBean servers. Yes Undo The same reason jsr3 Sun Microsystems,Inc.
21 Sep, 2004 255 JMX 2.0 Update JMX and JMX Remote API. Improve the availability of existing features and add new features. no Undo Corporate strategy adjustment Sun Microsystems,Inc.
07 Dec, 2004 262 JMX to support Web Services connection JMX support the definition of Web Services support for non-Java clients. Yes Undo Corporate strategy adjustment Sun Microsystems,Inc.

JMX technology can be seen completely dominated by the Sun, no new specifications have been proposed after the acquisition. Only the sun actually enabled the company submitted 3,160,262.

Third, the sample code

Specifically management applications, view device information, view the application resource, monitor resource changes, how these achieve it?

Defined interfaces

//接口名必须以MBean结尾
public interface HelloMBean {
    String getName();

    void setName(String name);

    void printHello();
}

Implementation class

//类名必须和接口MBean前的内容相同,即类名+MBean必须等于接口名
public class Hello extends NotificationBroadcasterSupport implements HelloMBean {
    private AtomicLong sequenceNumber = new AtomicLong(1);
    private String name;

    @Override
    public void printHello() {
        System.out.println("你好," + name);
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        String oldName = this.name;
        this.name = name;
        //通知方法
        Notification notification = new AttributeChangeNotification(this,
                sequenceNumber.getAndIncrement(),
                System.currentTimeMillis(),
                AttributeChangeNotification.ATTRIBUTE_CHANGE,
                "Name Change",
                "java.lang.String",
                oldName + "",
                this.name + "");
        super.sendNotification(notification);
    }
}

Main method

public class StandardMBeanMain {
    public static void main(String[] args) throws Exception {
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName objName = new ObjectName("MBeanTest2:type=StandardMBean");
        mBeanServer.registerMBean(new Hello(), objName);
        mBeanServer.addNotificationListener(objName, new HelloListener(), null, null);
        Thread.sleep(60 * 60 * 1000);
    }
}

Listener class

public class HelloListener implements NotificationListener {
    @Override
    public void handleNotification(Notification notification, Object handback) {
        log("SequenceNumber:" + notification.getSequenceNumber());
        log("Type:" + notification.getType());
        log("Message:" + notification.getMessage());
        log("Source:" + notification.getSource());
        log("TimeStamp:" + notification.getTimeStamp());
        log("UserData:" + notification.getUserData());
        log("oldValue:" + ((AttributeChangeNotification)notification).getOldValue());
        log("newValue" + ((AttributeChangeNotification)notification).getNewValue());
        log("attributeName:" + ((AttributeChangeNotification)notification).getAttributeName());
        log("=========" + notification.toString());
    }

    private void log(String message) {
        System.out.println(message);
    }
}

jconsole connection example

ObjectName("MBeanTest2:type=StandardMBean")

View bean attribute information, and support to modify bean properties by the method set

operational support void method invocation

monitor Notificationcontents of the statement

Quote

https://www.jcp.org/en/jsr/detail?id=3
https://www.jcp.org/en/jsr/detail?id=70
https://www.jcp.org/en/jsr/detail?id=71
https://www.jcp.org/en/jsr/detail?id=146
https://www.jcp.org/en/jsr/detail?id=160
https://www.jcp.org/en/jsr/detail?id=255
https://www.jcp.org/en/jsr/detail?id=262

Guess you like

Origin www.cnblogs.com/snifferhu/p/12058166.html
JMX