JMX Architecture & "Hello Word" the JMX way

本文深入探讨了JMX架构的三个关键层次:Instrumentation、Agent和Remote Management,通过实现一个简单的HelloWorld MBean示例,详细阐述了如何在JMX环境中进行资源管理和监控。

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.



 

【博士论文复现】【阻抗建模、验证扫频法】光伏并网逆变器扫频与稳定性分析(包含锁相环电流环)(Simulink仿真实现)内容概要:本文档是一份关于“光伏并网逆变器扫频与稳定性分析”的Simulink仿真实现资源,重点复现博士论文中的阻抗建模与扫频法验证过程,涵盖锁相环和电流环等关键控制环节。通过构建详细的逆变器模型,采用小信号扰动方法进行频域扫描,获取系统输出阻抗特性,并结合奈奎斯特稳定判据分析并网系统的稳定性,帮助深入理解光伏发电系统在弱电网条件下的动态行为与失稳机理。; 适合人群:具备电力电子、自动控制理论基础,熟悉Simulink仿真环境,从事新能源发电、微电网或电力系统稳定性研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①掌握光伏并网逆变器的阻抗建模方法;②学习基于扫频法的系统稳定性分析流程;③复现高水平学术论文中的关键技术环节,支撑科研项目或学位论文工作;④为实际工程中并网逆变器的稳定性问题提供仿真分析手段。; 阅读建议:建议读者结合相关理论教材与原始论文,逐步运行并调试提供的Simulink模型,重点关注锁相环与电流控制器参数对系统阻抗特性的影响,通过改变电网强度等条件观察系统稳定性变化,深化对阻抗分析法的理解与应用能力。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值