//mbean interface
public interface HelloWorldMBean
{
public void setGreeting( String greeting );
public String getGreeting();
public void printGreeting();
}
//mbean implementation
import javax.management.Notification;
import javax.management.NotificationBroadcasterSupport;
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(
"helloWorld.fanrey", this, -1,
System.currentTimeMillis(), greeting );
sendNotification( notification );
}
public String getGreeting()
{
return greeting;
}
public void printGreeting()
{
System.out.println( greeting );
}
}
//Agent implementation
import javax.management.*;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import com.sun.jdmk.comm.*;
public class HelloAgent
{
private MBeanServer server = null;
public HelloAgent()
{
System.out.println("\n\tCREATE the MBeanServer.");
server = MBeanServerFactory.createMBeanServer("JMXAgent");
startHTMLAdapter();
startRMIConnector();
// HelloWorld hw = new HelloWorld();
// ObjectName helloWorldName;
// try {
// helloWorldName = new ObjectName( "JMXAgent:name=helloWorld1" );
// server.registerMBean( hw, helloWorldName );
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
protected void startHTMLAdapter()
{
HtmlAdaptorServer adapter = new HtmlAdaptorServer();
ObjectName adapterName = null;
try
{
adapter.setPort( 9092 );
//create the HTML adapter
adapterName = new ObjectName(
"JMXAgent:name=html,port=9092" );
server.registerMBean( adapter, adapterName );
adapter.start();
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Error Starting HTML Adapter for Agent");
}
}
protected void startRMIConnector()
{
try {
JMXServiceURL url = new JMXServiceURL("jmxmp", null, 2099);
JMXConnectorServer connector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
ObjectName connectorName = new ObjectName("JMXAgent:name=RMIConnector");
server.registerMBean(connector, connectorName);
connector.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main( String args[] )
{
System.out.println( "HelloAgent is running" );
HelloAgent agent = new HelloAgent();
System.out.println("\nAgent is Ready for Service...\n");
}
}
import java.net.MalformedURLException;
import javax.management.*;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
// test RMI client
public class Tester {
public static void main(String[] args) throws MalformedURLException,
InstantiationException, IllegalAccessException,
ClassNotFoundException {
JMXServiceURL url = new JMXServiceURL("jmxmp", null, 2099);
try {
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
ObjectName hwName;
hwName = new ObjectName("JMXAgent:name=helloWorld1");
jmxc.getMBeanServerConnection().createMBean("HelloWorld", hwName);
jmxc.getMBeanServerConnection().invoke(hwName, "printGreeting", null, null);
jmxc.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
分享到:
相关推荐
ObjectName name = new ObjectName("com.example:type=Simple"); mbs.registerMBean(new SimpleMBean(), name); } } ``` ##### 3.3 访问MBean 一旦MBean注册成功,就可以通过MBeanServer对其进行访问。例如,...
与之配合使用的*slf4j-log4j12-1.7.6.jar*是SLF4J(Simple Logging Facade for Java)的一个实现,SLF4J提供了一个抽象层,允许用户在部署时插入任何日志框架,如log4j。 mina-example-2.0.7.jar包含了MINA提供的...
- **A Simple POJO Example**: Demonstrates how to create a simple Plain Old Java Object (POJO) that can be persisted using Hibernate. - **Implementing Inheritance**: Explains how to implement ...
4.1. A simple POJO example 4.1.1. Implement a no-argument constructor 4.1.2. Provide an identifier property (optional) 4.1.3. Prefer non-final classes (optional) 4.1.4. Declare accessors and mutators ...
8. `mina-integration-jmx-2.0.7.jar`:与Java Management Extensions (JMX) 的集成,提供了管理和监控MINA服务的能力,可以对MINA应用程序的运行状态进行远程监控和控制。 9. `mina-integration-ognl-2.0.7.jar`:...
8. **mina-integration-jmx-2.0.7.jar**:MINA与Java Management Extensions (JMX) 的集成,允许监控和管理MINA服务的运行状态,包括连接统计、性能指标等。 9. **mina-integration-ognl-2.0.7.jar**:MINA与OGNL...
@Managed ( type = " example " , group = " simple " , name = " managed bean " , description = " This is a sample managed bean " , attributes = { @Attribute ( attribute = " name " , description = " This...
10.2.6. Quick-start Spring CLI Example 10.3. Upgrading from an Earlier Version of Spring Boot 11. Developing Your First Spring Boot Application 11.1. Creating the POM 11.2. Adding Classpath ...
9. **SLF4J(Simple Logging Facade for Java)**: SLF4J 是一个日志 API,它提供了一层抽象,使得我们可以根据项目需求选择合适的日志框架,如 Logback。在项目中,我们通常通过 SLF4J 的接口来记录日志,而不是...
- **6.4 集合例子 (Collection example)**:提供了一个完整的集合映射示例。 #### 7. 关联关系映射 这一章探讨了 Hibernate 中关联关系的映射方式。 - **7.1 介绍**:简要介绍关联映射的基本概念。 - **7.2 单向...
3.1. Understanding the Example Use Cases ..................................... 59 3.1.1. Prerequisites .................................................................... 60 3.1.2. ActiveMQ In Action...