Accessing Standard and Dynamic MBeans via the RMI Connector

The purpose of this examples is to demostrate the implementation of a standard MBean and a dynamic MBean. It also shows how to perform operations on them, both locally, and remotely through an RMI connection between a server and a remote client.

 

A standard MBean is one that statically defines its management interface through the name of the methods it contains. A dynamic MBean implements a specific java interface and reveals its attributes and opterations at run time.

 

The JMX technology defines a connector base on RMI. The RMI connector supports the standard RMI transports, Java Remote Method Protocol(JRMP) and the Internet Inter-Lbject Request Broker(ORB) Protocol(IIOP). This connector allows you to connect to an MBean server from a remote location, and perform operations on it, exactly as if the operations were being performed locally.

 

due to its size, the Server.java class is shown in several code excerpts.

 

public static void main(String[] args) {
     try {
        
         // Firstly, the Server.java class creates a new MBean server called mbs by calling the

         // createMBeanServer() method of the MBeanServerFactory class.    
         MBeanServer mbs = MBeanServerFactory.createMBeanServer();


         waitForEnterPressed();


          // Then, the default domain in which the MBean server is registered is obtained with a call to the

          // getDefaultDomain() method of the MBeanServer interface. The domain is identified by the the string domain .
         String domain = mbs.getDefaultDomain();
         waitForEnterPressed();

 

         // The MBean class named SimpleStandard is also identified by a variable mbeanClassName .

         // SimpleStandard is the name of java class for the java object of which this MBean is an instance.
         String mbeanClassName = "SimpleStandard";

 

         // Anothere variable, the string mbeanObjectNameStr, is defined as the combination of the domain,

         // plus the following key=value pairs:

         // The type, which in this case is the variable value of mbeanClassName

         // A name, to differentiate this MBean from other MBeans of the same type that might be created subsequently.

         // In this case the name number is 1.

         // The purpose of mbeanObjectNameStr is to give the MBean a human-readble identifier.

         String mbeanObjectNameStr = domain + ":type=" + mbeanClassName + ",name=1";

 

         // A call to createSimpleMBean creates and registers the SimpleStandard MBean in the local MBean server,

         // with the given object name.
         ObjectName mbeanObjectName = createSimpleMBean(mbs, mbeanClassName, mbeanObjectNameStr);
         waitForEnterPressed();
 
         printMBeanInfo(mbs, mbeanObjectName, mbeanClassName);
         waitForEnterPressed();
 
         manageSimpleMBean(mbs, mbeanObjectName, mbeanClassName);
         waitForEnterPressed();

         // This MBean is an instance of SimpleDynamic class
         mbeanClassName = "SimpleDynamic";
         mbeanObjectNameStr = domain + ":type=" + mbeanClassName + ",name=1";
         mbeanObjectName = createSimpleMBean(mbs, mbeanClassName, mbeanObjectNameStr);
         waitForEnterPressed();
 
         printMBeanInfo(mbs, mbeanObjectName, mbeanClassName);
         waitForEnterPressed();
 
         manageSimpleMBean(mbs, mbeanObjectName, mbeanClassName);
         waitForEnterPressed();
 
         [...]

 

// Create a new service URL called url, which serves as an address for the connector server.

// In this example, the service URL is given in JNDI form. This service URL defines the following:

// The connector will use default RMI transport, denoted by rmi .

// The RMI registry in which the RMI connector stub will be running on port 9999 on the local host,

// and the server address will be registered under the name server. The 9999 specified in this example is arbitrary; you can use any available port.

JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/server");

 

// An RMI connector server named cm is created by calling the static method

// newJMXConnectorServer of JMXConnectorFactory, with the service URL url , a null environment map,

// and the MBean server mbs as parameters.

JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);

 

// The connector server cs is launched by calling the start() method of JMXConnectorServer,

// whereupon RMIConnectorServer exports the RMI object server to the RMI registry.

// The connector will remain open until the Enter key is pressed,

// as instructed by the simple method waitForEnterPressed, that is defined later in the Server code.
cs.start();
waitForEnterPressed();
cs.stop();

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
项目:使用AngularJs编写的简单 益智游戏(附源代码)  这是一个简单的 javascript 项目。这是一个拼图游戏,也包含一个填字游戏。这个游戏玩起来很棒。有两个不同的版本可以玩这个游戏。你也可以玩填字游戏。 关于游戏 这款游戏的玩法很简单。如上所述,它包含拼图和填字游戏。您可以通过移动图像来玩滑动拼图。您还可以选择要在滑动面板中拥有的列数和网格数。 另一个是填字游戏。在这里你只需要找到浏览器左侧提到的那些单词。 要运行此游戏,您需要在系统上安装浏览器。下载并在代码编辑器中打开此项目。然后有一个 index.html 文件可供您修改。在命令提示符中运行该文件,或者您可以直接运行索引文件。使用 Google Chrome 或 FireFox 可获得更好的用户体验。此外,这是一款多人游戏,双方玩家都是人类。 这个游戏包含很多 JavaScript 验证。这个游戏很有趣,如果你能用一点 CSS 修改它,那就更好了。 总的来说,这个项目使用了很多 javascript 和 javascript 库。如果你可以添加一些具有不同颜色选项的级别,那么你一定可以利用其库来提高你的 javascript 技能。 演示: 该项目为国外大神项目,可以作为毕业设计的项目,也可以作为大作业项目,不用担心代码重复,设计重复等,如果需要对项目进行修改,需要具备一定基础知识。 注意:如果装有360等杀毒软件,可能会出现误报的情况,源码本身并无病毒,使用源码时可以关闭360,或者添加信任。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值