package test;
public interface HelloWorldMBean {
public void setGreeting(String greeting);
public String getGreeting();
public void printGreeting();
}
package test;
public class HelloWorld implements HelloWorldMBean {
private String greeting=null;
public HelloWorld(){
this.greeting="hello,wrold i am a standard MBean";
}
public HelloWorld(String greeting){
this.greeting=greeting;
}
public void setGreeting(String greeting) {
// TODO Auto-generated method stub
this.greeting=greeting;
}
public String getGreeting() {
// TODO Auto-generated method stub
return greeting;
}
public void printGreeting() {
// TODO Auto-generated method stub
System.out.println(greeting);
}
}
package test;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import com.sun.jdmk.comm.HtmlAdaptorServer;
public class HelloAgent {
private MBeanServer mbs=null;
public HelloAgent(){
mbs=MBeanServerFactory.createMBeanServer("HelloAgent");
HtmlAdaptorServer adapter = new HtmlAdaptorServer();
HelloWorld hw= new HelloWorld();
ObjectName adapterName=null;
ObjectName helloWorldName=null;
try {
helloWorldName= new ObjectName("HelloAgent:name=helloWorld");
mbs.registerMBean(hw, helloWorldName);
adapterName=new ObjectName("HelloAgent:name=htmladapter,port=9092");
adapter.setPort(9092);
mbs.registerMBean(adapter, adapterName);
adapter.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String args[]){
System.out.println("Hello is running");
HelloAgent agent= new HelloAgent();
}
}
1.Creating the MBean server and HTML adapter
The first step performed by the agent constructor is the creation of the MBeanServer object.
by using the javax.management.MBeanServerFactory class
Notice that the parameter HelloAgent was passed to the factory’s create-
MBeanServer() method. This parameter is a String value indicating the name for
this agent’s domain.
2。Registering and managing the MBean
Once the adapter has been created, you need to register it on the MBeanServer
3。Uniquely identifying MBeans
create an instance of the javax.management.ObjectName
class. The ObjectName class is a JMX class that provides a naming system for
MBeans, allowing unique identification of MBeans registered in the MBean
server.
Each ObjectName consists of two parts
A domain name— The domain name usually coincides with the domain
name of the MBeanServer in which the MBean wants to register
A key=value property list—The
object name may be the first representation a user will see of your MBean.
You can supply information such as names, port values, locations, and purposes
with a few property values.
4。Registering and starting the HTML adapter
call its start()
method
the domain name
does not even have to be specified. If it’s left blank,
the MBean server provides a default domain name.
The same is true for the MBeanServerFactory class.
If you use createMBeanServer() without a domain
name parameter, the factory will provide you with
an MBeanServer with a default domain.
what if you want to add additional MBeans to the agent
without writing more code? The Admin View is an HTML page presented by the
HTML adapter that gives you access to the agent’s MBean server in order to
remove or add MBeans. From this page, you can specify an ObjectName value and
associate it with a Java class that is an MBean. The MBean server will construct
and register an MBean corresponding to your input. The Admin View presents
four text fields
Domain—The HTML adapter defaults the Domain field to the domain of
the agent. Currently, it shows HelloAgent, which is your domain. This is
the first part of the object name.
Keys—The Keys field requires input in the form [name=value],* . This field
represents the key/value portion of an object name.
Java Class—This field requires a full Java class name of the class of the
MBean you want to create.
Class Loader—The Class Loader field is the only field that is optional. You
can specify a class loader for the MBean server to use when attempting to
load the Java class specified in the previous field.
Keys: name=helloWorld2
Java Class: test.HelloWorld
分享到:
相关推荐
JMX入门是一个重要的主题,尤其对于那些希望深入了解Java应用监控和管理的开发者而言。 这篇博客文章(可以通过给定的链接访问)可能是介绍JMX基础知识的一个很好的起点。虽然具体的博客内容未在描述中给出,但我们...
【JMX 入门详细教程】 Java Management Extensions (JMX) 是一种标准,它允许开发者在Java应用程序中集成管理和监控功能。JMX 提供了一种框架,使得开发者能够轻松地创建、注册和管理称为Managed Beans(MBeans)的...
### JMX入门教程详解 #### 一、JMX概述与价值 JMX(Java Management Extensions)是一种用于管理和监控Java应用程序的标准框架。通过JMX,开发者可以轻松地在Java应用程序中集成管理和监控的功能,从而实现对应用...
总结一下,这个JMX入门例子展示了如何创建一个简单的MBean,将其注册到MBean服务器,并通过`jconsole`进行交互。了解JMX对于任何需要管理和监控Java应用的开发者来说都是一项重要技能,它提供了强大的灵活性和可扩展...
在这个入门指南中,我们将深入探讨JMX的核心概念、API以及如何通过一个简单的示例来理解它的应用。 **一、JMX核心概念** 1. **MBean(Managed Beans)**:MBean是JMX中的核心组件,代表了可管理的资源。它可以是...
本教程将引导你入门Spring框架下的JMX应用。 首先,JMX是一种Java标准,它允许开发者创建可管理的Java组件,并提供了一种统一的方式来管理和监控这些组件。在Spring中,我们可以利用JMX来创建MBeans(Managed Beans...
Java Management Extensions(JMX)是Java平台上的一个标准,用于创建和管理应用程序的管理资源,如服务、设备、系统组件等。JMX 提供了一种框架和API来监控和管理运行时的应用程序,使得开发者可以轻松地添加管理...
JMX(Java Management Extensions)是一种用于在Java应用程序中实现管理和监控功能的框架。它允许开发者创建可管理的组件,即MBeans(Managed Beans),并通过MBeanServer进行交互。JMX提供了一种标准的方式来暴露...
JMX,全称为Java Management Extensions,是Java平台中用于管理和监控应用程序、系统和服务的一种框架。JMX技术在软件开发领域中扮演着重要角色,尤其在大型企业级应用中,能够帮助开发者实现对运行时环境的远程监控...
Java Management Extensions(JMX)是一种Java平台上的标准框架,用于管理和监控应用程序、系统和服务。它允许开发者创建可管理和监控的组件,称为MBeans,这些组件提供了对系统资源的访问和控制。以下是对JMX关键...
3. `jmx入门.rar`:这可能是JMX的基础教程或实践案例,可以帮助初学者快速上手。 4. `jmxremote-1_0_1-ri-bin-b58.zip`:这个文件包含了JMX远程访问的实现,可能包含API文档和库文件。 5. `jmx_remote-1_0-fr-...
Java Management Extensions(JMX)是一种Java平台上的框架,用于管理和监控应用程序、系统和服务。它提供了一种标准的方式来创建可管理的组件,称为MBeans(Managed Beans),这些组件可以暴露其状态和行为,允许...
本篇文章将深入探讨JMX的基本概念、核心组件、功能以及如何入门使用。 一、JMX概述 JMX提供了一种灵活的框架,可以创建、注册和管理被称为管理对象(MBeans)的实体,这些对象代表可管理的资源。MBeans提供了对...
本初学者入门教程将帮助你逐步了解并掌握JMX的核心概念和实际应用。 首先,我们要理解JMX的基本组件。在JMX中,有三个主要元素:管理Bean(MBean)、MBean服务器和代理(Agent)。MBean是JMX的核心,它代表了可管理...
jmeter 入门练习
-> DTO的映射器记录中测验使用DataJpaTest的存储库使用DataMongoTest的存储库使用Mockito的服务使用WebMvcTest的端点使用OpenPojo的Pojos和Dtos JMX入门使用Docker简化开发本教程的目的是提供一个Producer消费者...