`
scanfprintf123
  • 浏览: 80399 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

JMX M-LET Service

阅读更多

1.What does M-LET service can do?

   M-Let service provide a mechanism of dynamic loading new MBeans without restarting your agent. Sounds like the things Dynamic MBean can do,huh? But there are some differences btw them. M-LET service can let agent use classes that are not in its original startup CLASSPATH, dynamic MBean can't do this.

 

2.What should be done to make this service available?

   Sun provide this service thro MLet class, it is easy for your application to use this service only by pre-adding MLet Mbean to your MBean server before your agent starts.

 

                                //add MLet service
		ObjectName mLetService=new ObjectName("Hello:name=MLet");
		server.createMBean("javax.management.loading.MLet", mLetService);

 

3.MLetMBean Architechture


 

As we can see above, MLet class extends URLClassLoader, so MLet is capable of adding new urls to its classpath or getResource from classpath, of course, it use URLClassLoader to do this. That is why it inherits from URLClassLoader.

 

And let's check MLetMBean interface to see what we have.

public abstract interface MLetMBean
{
  public abstract Set<Object> getMBeansFromURL(String paramString)
    throws ServiceNotFoundException;

  public abstract Set<Object> getMBeansFromURL(URL paramURL)
    throws ServiceNotFoundException;

  public abstract void addURL(URL paramURL);

  public abstract void addURL(String paramString)
    throws ServiceNotFoundException;

  public abstract URL[] getURLs();

  public abstract URL getResource(String paramString);

  public abstract InputStream getResourceAsStream(String paramString);

  public abstract Enumeration<URL> getResources(String paramString)
    throws IOException;

  public abstract String getLibraryDirectory();

  public abstract void setLibraryDirectory(String paramString);
}

 

As we can see from MLetMBean interface, addURL() & getResource() related methods are actually methods from URLClassLoader. So what we need to pay attention to here is only the getMBeansFromURL() method,this method has two overrided versions:

  public abstract Set<Object> getMBeansFromURL(String paramString)
    throws ServiceNotFoundException;

  public abstract Set<Object> getMBeansFromURL(URL paramURL)
    throws ServiceNotFoundException;

 

the parameter paramURL is referring to the url of  a M-LET file. M-Let file is a XML-like file that contains some attributes for MBeans which are about to load. The following is a sample of M-LET entry:


 

You will be familiar with this if you have ever experience with XML. Now I will walk you through some commonly used atrributes of the M-LET file:

  • CODE:specify the specific class that contains an MBean implementation, its value must contains the package name.
  • ARCHIVE:its value can be either a jar file or a jar file list, which should be enclosed in quotation mark(") and filenames must be comma separated.
  • NAME: actually the objectname used to register in a MBean server.
  • CODEBASE: you might notice that we dont provide the exactly path for ARCHIVE attribute but the jar file name-'mlet.jar', what if there are many mlet.jar exist in the classpath? This attaribute will help give it a specific url path for ARCHIVE attribute, if it is not specified, we assume that the jar file specified in ARCHIVE attribute is to be in the same directory as the M-LET file.

And now let's go back to our getMBeansFromURL() method, what it actually does is creating a new MBean from the info pre-defined in the M-Let file.

 
 

For point #3 using server.createMBean to create a new MBean. You might get confused about the server here. Where does the server come from? Do you forget our MBeanRegistration interface? Recall from MLetMBean Architechture, and we can see that MLET implements this interface. Knowing how MLET class get its MBean server? Yes, I am sure you do.

 

4.Concrete Example

   OK, after we learn enough theories, time for us to construct a concrete example. I will demostrate that how use M-LET service to load MBean dynamicly with M-Let file.

 

   First thing is to finish our MBean which is about to be loaded. Here I use the simple MBean-Standard MBean.

 

package MLetService;

public class MLetSample implements MLetSampleMBean{

	public void sayHelloToMLet() {
		System.out.println("Hello,MLet sample");
	}
	
}

 

 

package MLetService;

public interface MLetSampleMBean {
	public void sayHelloToMLet();
}

 

    And then let's use jar command to pack them in a jar: jar -cvf mlet.jar MLetService/MLetSample.class MLetService/MLetSampleMBean.class

 

    And then the M-Let file:

 

   The last, of course, will be our MLetAgent:

public class MLetAgent {

	public static void main(String[] args) throws Exception{
		MBeanServer server=MBeanServerFactory.createMBeanServer();
		//new a adaptor and register it in the server
		HtmlAdaptorServer adaptor=new HtmlAdaptorServer();
		adaptor.setPort(8888);
		ObjectName adaptorName=new ObjectName("Hello:name=adaptor");
		server.registerMBean(adaptor, adaptorName);
		
		//add MLet service
		ObjectName mLetService=new ObjectName("Hello:name=MLet");
		server.createMBean("javax.management.loading.MLet", mLetService);
		
		adaptor.start();
	}

}

 

 

   Let's start our MLetAgent and get access to http://localhost:8888 to load our MLetSample MBean.

 

   Note: There is one point you need to keep in mind, that is you have to ensure that the mlet.jar is not in your startup MLetAgent's classpath. Since what I want to show you is a more realistic case. Of course, it is fine with mlet.jar to be in the MLetAgent's classpath. It can work too.

 

   When you connect to our MLetAgent, you can see that we dont have MLetSample in hand:

 

 

 Go into the MLetMBean's view(clicking the name=MLet link), and input the url of mlet file:



 Click the button 'getMBeansFromURL' and back to our agent's view to check what we get:



 

   Can you see that? Our MLetSample shows up.

 

  • 大小: 41.8 KB
  • 大小: 14.1 KB
  • 大小: 14.1 KB
  • 大小: 1.9 KB
  • 大小: 2.3 KB
  • 大小: 3.2 KB
  • 大小: 3.1 KB
2
0
分享到:
评论
2 楼 scanfprintf123 2010-04-07  
yugong2009 写道
请问博主,你的example里传入的URL是file格式,也就 是访问的是本机上的MBean,
那如何访问远程主机上的MBean 呢?
请赐教,项目需要做这么,急呀!



你使用http协议头就可以了,URL本身支持的,只要正确读取到mlet文件即可。
1 楼 yugong2009 2010-04-07  
请问博主,你的example里传入的URL是file格式,也就 是访问的是本机上的MBean,
那如何访问远程主机上的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应用程序中扮演...

    cmdline-jmxclient-0.10.3.jar

    catalina-jmx-remote.jar,jmxcmd.jar,cmdline-jmxclient-0.10.3.jar这三个jar包打包合集。因为下载网站已经被墙,所以下载下来放在这里供有需要的同学使用

    zabbix监控tomcat所需的cmdline-jmxclient-0.10.3.jar和zbx自定义模版

    首先,`cmdline-jmxclient-0.10.3.jar`是一个Java管理扩展(JMX)客户端,它允许通过命令行接口连接到Tomcat服务器,获取和操作JMX MBeans(管理Bean),从而获取Tomcat的运行时信息,如线程池状态、内存使用情况、...

    jmxri-1.2.1 和 jmxtools-1.2.1.rar

    maven编译时报找不到这两个jar文件,发现已经无法从网站...Could not resolve dependencies for project ****:jar:0.0.1-SNAPSHOT: The following artifacts could not be resolved: com.sun.jdmk:jmxtools:jar:1.2.1, ...

    cmdline-jmxclient-0.10.3.jar + zabbix tomcat监控模板

    - 查询:使用`-m`参数查询MBean,例如`-m 'java.lang:type=Memory'`可以查看内存使用情况。 - 操作:可以使用`-o`参数执行MBean的操作,具体操作依赖于MBean的定义。 3. **Zabbix与JMX集成**: - Zabbix提供了...

    jmxtools-1.2.1.jar+jmxri-1.2.1.jar.zip

    `javax.jms` 包是Java消息服务(Java Message Service)的API,它是Java平台上的标准,定义了在分布式环境中如何发送和接收异步消息。JMS是基于JMX的,因为可以通过JMX来监控和管理JMS资源,如消息代理、队列和主题...

    jmxri-1.2.1

    【标题】"jmxri-1.2.1" 是一个关键的Java管理扩展(JMX)实现包,主要用于提供远程接口(RI)支持。在Maven项目中,JMXri是实现Java管理扩展(JMX)规范的一部分,它允许开发者管理和监控应用程序的运行状态。在开发...

    cmdline-jmxclient-0.10.3.jar-KafkaOffsetMonitor-assembly-0.2.0.jar

    标题中的"cmdline-jmxclient-0.10.3.jar"和"KafkaOffsetMonitor-assembly-0.2.0.jar"是两个在Java环境中使用的工具,它们与Apache Kafka的管理和监控紧密相关。让我们详细了解一下这两个工具及其背后的原理。 JMX ...

    jmxri-1.2.1.jar

    Java Management Extensions (JMX) 是Java平台提供的一种用于管理和监控应用程序、系统和服务的标准框架。`jmxri-1.2.1.jar`是这个框架的一部分,主要包含了JMX的运行时实现(Runtime Implementation)。在Maven项目...

    tomcat-catalina-jmx-remote-9.0.5.jar

    tomcat-catalina-jmx-remote-9.0.5 tomcat-catalina-jmx-remote-9.0.5.jar

    cmdline-jmxclient-0.10.3.jar.zip

    `cmdline-jmxclient-0.10.3.jar.zip` 是一个用于Tomcat性能监控的工具包,其中包含 `cmdline-jmxclient-0.10.3.jar` 文件,这是一个Java档案(JAR)文件,专门设计用于通过命令行界面与Java管理扩展(JMX)接口交互...

    jmxtools-1.2.1.jar和jmxri-1.2.1.jar.zip

    mvn仓库里面找不到jmxtools-1.2.1.jar,jmxri-1.2.1.jar的包了,备个份,解压密码123

    jmxtools-1.2.1.jar +jmxri-1.2.1.jar+ jms-1.1.jar

    3. **jms-1.1.jar**:Java Message Service (JMS) 是Java平台上定义的消息传递API,用于在分布式环境中交换异步消息。JMS允许应用程序创建、发送、接收和读取消息。在JMX上下文中,JMS可以被用作通知机制,当特定的...

    jms-1.1+jmxri-1.2.1+jmxtools-1.2.1.zip

    Java消息服务(Java Message Service,简称JMS)是Java平台中用于企业级应用间异步通信的标准接口。JMS-1.1是该规范的一个版本,它定义了应用程序如何创建、发送、接收和读取消息。JMS允许分布式系统中的不同组件...

    cmdline-jmxclient-0.10.3

    标题“cmdline-jmxclient-0.10.3”指的是一个特定版本的命令行JMX客户端工具,这个工具主要用于与Java Management Extensions (JMX)接口进行交互,从而获取JMX相关的各种信息。JMX是一种Java平台的标准,它提供了一...

    jmxtools-1.2.1.jar&jmxri-1.2.1.jar

    亲测可用 com.sun.jmx. jmxri-1.2.1.jar;maven中使用了log4j 1.2.15及以后的版本中如果找不到jmxtools-1.2.1.jar,jmxri-1.2.1.jar那么来这里免费下载吧

Global site tag (gtag.js) - Google Analytics