⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 springjmxclient.java

📁 jmx在spring中的实现
💻 JAVA
字号:
/*
======================================================================

  SpringJmxClient.java

  Created by Claude Duguay
  Copyright (c) 2005

======================================================================
*/

package com.claudeduguay.jmx.demo.client;

import java.util.*;

import javax.management.*;
import javax.management.remote.*;

public class SpringJmxClient implements NotificationListener
{
	public void handleNotification(Notification notification, Object handback) 
	{
		System.out.println("Notification: " + notification.getMessage());
	}
	
	public static void main(String[] args)
		throws Exception
	{
		SpringJmxClient listener = new SpringJmxClient();
		
		String address = "service:jmx:rmi:///jndi/rmi://localhost:8999/jmxrmi";
		JMXServiceURL serviceURL = new JMXServiceURL(address);
		Map<String,Object> environment = null;
		JMXConnector connector = JMXConnectorFactory.connect(serviceURL, environment);
		MBeanServerConnection mBeanConnection = connector.getMBeanServerConnection();
		
		ObjectName exampleServiceName = ObjectName.getInstance("Services:name=ExampleService");
		mBeanConnection.addNotificationListener(exampleServiceName, listener, null, null);
		
		mBeanConnection.invoke(exampleServiceName, "startService", null, null);
		mBeanConnection.setAttribute(exampleServiceName, new Attribute("propertyValue", "new value"));
		System.out.println(mBeanConnection.getAttribute(exampleServiceName, "propertyValue"));
		mBeanConnection.invoke(exampleServiceName, "stopService", null, null);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -