`
kylinsoong
  • 浏览: 239686 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

JMX Architecture & "Hello Word" the JMX way

阅读更多

JMX Architecture Overview:

JMX technology provides a standard API for management and monitoring of resources. As http://kylinsoong.iteye.com/admin/blogs/794995  Part 3 depicted, the JMX architecture can be broken down into three levels: Instrumentation, Agent, Remote Management, As the following figure described:

      Instrumentation Layer contains MBeans representing their manageable resources, such as applications, devices, or services, are instrumented using Java objects called Managed Beans (MBeans). MBeans expose their management interfaces, composed of attributes and operations, through a JMX agent for remote management and monitoring;

      Agent Layer is the main component of a JMX agent is the MBean server. This is a core managed object server in which MBeans are registered. A JMX agent also includes a set of services for handling MBeans. JMX agents directly control resources and make them available to remote management agents;

      Distributed Layer also named Remote Management layer, contain adapters and connectors make a JMX agent accessible from remote management applications outside the agent’s Java Virtual Machine (Java VM).

 

HelloWorld JMX way

1. Complete Instrumentation layer dev

      The first step in developing the HelloWorld MBean is to write its Java interface. The interface declares three methods: one getter, one setter, and an additional method for printing the HelloWorld MBean’s greeting. Code view:

public interface HelloWorldMBean {
	public void setGreeting( String greeting );
	public String getGreeting();
	public void printGreeting();
}

 Before we start HelloWroldMBean implemetation, we introduce JMX notification first, notification  is the most imprtant feature of JMX, any managment system need notification mechanism, to add notification to our Helloworld mbean we need to extends the avax.management.NotificationBroadcasterSupport. Our MBean class:

public class HelloWorld extends NotificationBroadcasterSupport implements HelloWorldMBean {
	
	private String greeting = null;

	public HelloWorld() {
		this.greeting = "Hello World! I am a Standard MBean";
	}

	public HelloWorld(String greeting) {
		this.greeting = greeting;
	}

	public void setGreeting(String greeting) {
		this.greeting = greeting;
		Notification notification = new Notification("jmx.demo.helloWorld.test"
													, this
													, -1
													, System.currentTimeMillis()
													, greeting );
		sendNotification(notification);
	}

	public String getGreeting() {
		return greeting;
	}

	public void printGreeting() {
		System.out.println(greeting);
	}
}

2 Complete Agent Code

      As step 1, we have our HelloWorldMbean, we need to make it available to use, to do so we must register it in a JMX Agent. Therefore we create HelloAgent class JMX agents are JMX components in the agent layer of JMX and are the containers for MBeans. The HelloAgent class performs 4 important tasks:

      1> It creates an MBeanServer instance to contain MBeans.

      2> It creates an HTML adapter to handle connections from HTML clients.

      3> It registers a new instance of the HelloWorld MBean.

      4> It handles the notification that HelloWorldMBean sent.

public class HelloAgent implements NotificationListener {

	private MBeanServer mbs = null;
	
	public HelloAgent() {
//		mbs = MBeanServerFactory.createMBeanServer("jmx.demo.HelloAgent");
		mbs = ManagementFactory.getPlatformMBeanServer();
		
		HtmlAdaptorServer adapter = new HtmlAdaptorServer();
		
		HelloWorld hw = new HelloWorld();
		
		ObjectName adapterName = null;
		ObjectName helloWorldName = null;
		
		try {
			helloWorldName = new ObjectName( "jmx.demo.HelloAgent:type=helloWorld,name=helloWorld" );
			mbs.registerMBean( hw, helloWorldName );
			hw.addNotificationListener(this, null, null);
			
			adapterName = new ObjectName("jmx.demo.HelloAgent:type=htmlAdapter,name=htmlAdapter,port=8000");
			adapter.setPort(8000);
			mbs.registerMBean( adapter, adapterName );
			adapter.start();
		}  catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String args[]) throws InterruptedException {
		System.out.println("HelloAgent is running");
		HelloAgent agent = new HelloAgent();
		Thread.sleep(Long.MAX_VALUE);
	}

	public void handleNotification(Notification notification, Object handback) {
		System.out.println( "Receiving notification..." );
		System.out.println( notification.getType() );
		System.out.println( notification.getMessage() );
	}
}

 3. Compete Distibuted layer Code

      In this simple HelloWorld example we only Use  HTML adapter to implement remote management, however, RMI connector implement remote management is more popular, I will explore into it in the later blogs. In this blog we will show Html adapter implement remote management in Test section.

 

HelloWorld Test

      After starting the main method, we can through 2 methods test and manage HelloWrold

Method one:

      Start a new command line, input 'jconsole' the following widget came out:



 Clicking HelloAgent then you will get into Jconsole control interface and find both HelloWorld and htmlAdapter selection folder bar in the left menu tree:



 Clicking reference method or change the attributes, the corresponding action will take place.

Method two:

      Through http://127.0.0.1:8000/ we could find jmx.demo.HelloAgent from All Agent View List 



 Cliking helloWord we also can find the operation and attributes, through HTML interface we also can triger the response notification event.



 

  • 大小: 23.8 KB
  • 大小: 21.7 KB
  • 大小: 15.5 KB
  • 大小: 2.5 KB
0
0
分享到:
评论
2 楼 kylinsoong 2011-10-27  
up2pu 写道
http://kylinsoong.iteye.com/admin/blogs/794995
This cannot be accessed by other users.

try use this:http://kylinsoong.iteye.com/blog/794995
1 楼 up2pu 2011-10-26  
http://kylinsoong.iteye.com/admin/blogs/794995
This cannot be accessed by other users.

相关推荐

    JMX HelloWorld Download

    **标题解析:** "JMX HelloWorld Download" 指的是一个关于Java Management Extensions(JMX)的简单示例,可能是用于教学或演示如何在Java应用中使用JMX技术。"Download"表明这是一个可以下载的资源,可能包含了...

    jmx_access&password;

    在使用JMC时,`jmx_access&password;` 文件起着至关重要的作用,特别是与JMX(Java Management Extensions)安全相关的配置有关。 JMX 是Java平台的一个标准接口,允许开发者管理应用程序、设备和服务。它提供了一...

    JMX一步一步来,快速学会开发JMX应用

    MBeanServer可以将Hello对象注册进去,然后通过JMX客户端接口(如HtmlAdaptorServer)暴露给外部进行管理。 总结起来,JMX是一个强大的工具,它简化了Java应用程序的管理和监控,通过MBeans的抽象,使得开发者可以...

    jmx三种访问方式

    Java Management Extensions(JMX)是Java平台中用于管理和监控应用程序、操作系统、网络设备等资源的一种标准框架。通过JMX,开发者可以创建管理代理(MBeans),这些代理暴露了各种管理特性,使得系统管理员可以...

    JMX实战 JMX开发

    JMX实战 书中不仅有对于基础知识的介绍,还有对于JMX开发中重大的体系架构问题的深入探讨,总结了大量JMX开发中的设计模式,并讨论了框架、安全性与性能等等。书中提供了几个典型的例子,兼顾各种开发平台,这些...

    jmx监控activeMQ监控

    jmx监控ActiveMQ监控 jmx(Java Management Extensions)是一种Java技术,为Java应用程序提供了管理和监控的功能。ActiveMQ是Apache软件基金会下的一个开源消息队列系统,提供了高效、可靠的消息传递服务。在生产...

    JMX学习,开发文档

    一个简单的JMX示例是创建一个名为`Hello`的类,该类实现了`HelloMBean`接口。`HelloMBean`定义了`getName()`和`setName()`方法,以及`printHello()`方法。`Hello`类中的这些方法允许外部管理工具获取和设置名称,...

    jmx监控weblogic,tomcat,websphere源码

    Java管理扩展(JMX)是Java平台提供的一种标准机制,用于管理和监视应用程序、服务和设备。在本项目中,"jmx监控weblogic,tomcat,websphere源码"涉及了使用JMX来监控三个主流的Java应用服务器:WebLogic、Tomcat和...

    jmx-1.2.1(jmxri+jmxtools) jar

    这个"jmx-1.2.1(jmxri+jmxtools) jar"包含了JMX的两个核心组件:JMX Remote Interface (jmxri) 和 JMX Tools。 1. **JMX Remote Interface (jmxri)**: JMX Remote Interface 是JMX框架的一部分,它允许远程访问和...

    Hbase和Hadoop JMX监控实战

    JMX(Java Management Extensions)是一种Java平台标准,用于管理和监控应用程序。在本实战中,我们将深入探讨如何利用JMX对HBase和Hadoop进行监控,以确保系统的稳定性和性能。 首先,我们需要理解HBase。HBase是...

    TongWeb7的JMX监控.doc

    在运维过程中,JMX(Java Management Extensions)监控是一个非常重要的工具,可以帮助我们实时查看和管理应用程序的状态,以及诊断和解决问题。本文将详细介绍如何使用 JMX 监控 TongWeb7。 首先,要开启 JMX 监控...

    JMX入门教程

    接下来,我们将通过一个简单的“Hello World”示例来演示如何使用JMX。 1. **定义MBean接口**:首先,需要定义一个MBean接口,即`HelloMBean`。该接口规定了被管理对象(MBean)应该具有的行为,例如获取和设置名称...

    jmxri-1.2.1.jar+jmxtools-1.2.1.jar

    Java Management Extensions (JMX) 是Java平台上的一个标准技术,用于管理和监控应用程序、操作系统和网络设备。`jmxri-1.2.1.jar` 和 `jmxtools-1.2.1.jar` 是与JMX相关的两个核心库文件,它们在Java应用程序中扮演...

    使用jmx所需的jar包

    Java Management Extensions(JMX)是Java平台提供的一种标准框架,用于管理和监控应用程序、操作系统和网络设备等资源。它允许开发者创建可管理的组件,并通过管理代理暴露这些组件,以便远程或本地工具进行监控和...

    jmx-tools.zip

    Java Management Extensions(JMX)是Java平台上的一个标准技术,用于管理和监控应用程序、服务和设备。JMX提供了创建、配置、查询和管理管理对象(MBeans)的能力,这些对象可以代表任何可管理的资源,从操作系统到...

    亲测可用 com.sun.jmx. jmxri-1.2.1.jar

    Description Resource Path Location Type Missing artifact com.sun.jmx:jmxri:jar:1.2.1 pom.xml /eshop-storm line 2 Maven Dependency Problem

    Fiddler导出jmx文件

    Fiddler导出jmx文件,解决Fiddler导出文件中 没有jmx文件选项,各个版本fiddler都适用

    java jmx agent不安全的配置漏洞如何改进(由浅入深代码范例和详细说明).docx

    Java JMX Agent 不安全的配置漏洞如何改进 Java JMX(Java Management Extensions)是一种用于监控和管理应用程序的工具,通过使用 JMX Agent,我们可以暴露应用程序的管理和监控接口,从而允许外部管理应用程序的...

Global site tag (gtag.js) - Google Analytics