加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

Basic Example of JMX Technology--转载

发布时间:2020-12-14 06:20:35 所属栏目:Java 来源:网络整理
导读:原文地址:http://nick-lab.gs.washington.edu/java/jdk1.5b/guide/jmx/tutorial/connectors.html ,? ,? ?and? . This example demonstrates standard and dynamic MBeans only. The server: Creates an MBean server Registers a? ?and a? ?MBean in the lo

原文地址:http://nick-lab.gs.washington.edu/java/jdk1.5b/guide/jmx/tutorial/connectors.html

,?,??and?. This example demonstrates standard and dynamic MBeans only.

  • The server:
  • Creates an MBean server
  • Registers a??and a??MBean in the local MBean server
  • Performs local operations on the MBeans
  • Creates an RMI connector server
  • The client:
  • Creates an RMI connector
  • Registers a??and a??MBean on the remote MBean server
  • Performs remote operations on both MBeans
  • .

    Open the??directory.

  • SimpleDynamic.java
    1. Open each of the??files in a text editor.

    ?class is shown in several code excerpts.

    ?class creates a new MBean server called??by calling the??method of the??class.

    ?method of the??interface. The domain is identified by the string?.

    ?is also identified by a variable,in this case the string?.??is the name of the Java class for the Java object of which this MBean is an instance. The?object is examined in?.

    ,is defined as the combination of the domain,plus the following key=value pairs:

  • The?,which in this case is the?.
  • An?,to differentiate this MBean from other MBeans of the same type that might be created subsequently. In this case the index number is?.
  • ?is to give the MBean a human-readable identifier.

    ,and??are then performed on the??MBean. Like?,these methods are defined later in the??code,and are shown in?and XXX.

    ?is created and registered in the MBean server in exactly the same way as the??MBean. As the name suggests,this MBean is an instance of the?Java object,which is examined in?.

    ?creates a new service URL called?,which serves as an address for the connector server. In this example,the service URL is given in?,rather than in??(see the API documentation for the??package for an explanation of JNDI form). This service URL defines the following:

  • The connector will use the default RMI transport,denoted by?.
  • The RMI registry in which the RMI connector stub will be stored will be running on port??on the local host,and the server address will be registered under the name?. The port??specified in the example is arbitrary; you can use any available port.
  • ?is created by calling the constructor?,with the service URL?,a?environment map,and the MBean server??as parameters. The connector server??is launched by calling the??method of?,whereupon??exports the RMI object??to the RMI registry. The connection will remain open until the Enter key is pressed,as instructed by the simple method,that is defined later in the??code.

    >> Create the " + mbeanClassName + " MBean within the MBeanServer"); echo( "ObjectName = " + mbeanObjectNameStr); try { ObjectName mbeanObjectName = ObjectName.getInstance(mbeanObjectNameStr); mbs.createMBean(mbeanClassName,mbeanObjectName); return mbeanObjectName; } catch (Exception e) { echo( "!!! Could not create the " + mbeanClassName + " MBean !!!"); e.printStackTrace(); echo("nEXITING...n"); System.exit(1); } return null; } [...]

    ?method. In this method,the MBean instance with the object name??is passed to the??method of the??interface to create a new object name for registering the MBean inside the MBean server. The resulting object name instance is named?. A call to the??method??then instantiates an MBean defined by the combination of the Java object identified by??and the MBean instance??and registers this MBean in the MBean server?.

    0) { for (int i = 0; i < attrInfo.length; i++) { echo(" ** NAME: " + attrInfo[i].getName()); echo(" DESCR: " + attrInfo[i].getDescription()); echo(" TYPE: " + attrInfo[i].getType() + "READ: "+ attrInfo[i].isReadable() + "WRITE: "+ attrInfo[i].isWritable()); } } else echo(" ** No attributes **"); [...]

    . The??method calls the??method??to obtain details of the attributes and operations that are exposed by the MBean.??defines the following methods,each of which is called in turn to obtain information about the??MBean’s attributes:

  • ,to obtain the attribute’s name.
  • ,to obtain the human readable description of the attribute.
  • ,to obtain the class name of the attribute.
  • ,to determine whether or not the attribute is readable.
  • ,to determine whether or not the attribute is writeable.
  • ?MBean’s constructors,operations and notifications:

  • ,to obtain information about the MBean’s Java class.
  • ,to learn what operations the MBean performs,and what parameters it takes.
  • ,to find out what notifications the MBean sends when its operations are performed.
  • ?method first of all calls the??method that is also defined by?. The??method obtains an MBean attribute called??from the MBean?,as well as another MBean atttribute called?. Both of these attributes are defined in the??class,shown in?.

    ?method then defines an attribute called?,which is an instance of the??class. The??attribute associates a value of??with the existing attribute?,defined by. A call to the??method??then sets the??MBean’s state to the new state defined by?.

    ?method??invokes the??MBean’s??operation. The??operation is defined in the??class.

    ?class is shown in?.

    ?class is a straightforward JMX specification management interface for the MBean?. This interface exposes the four operations defined by??for management through a JMX agent.

    ?class is shown in?.

    ?class defines a straightforward JMX specification standard MBean.

    ?MBean exposes operations and attributes for management by implementing the corresponding??interface,shown in?.

  • To define a state.
  • To update this state.
  • To count the number of times the state is updated
  • To reset the values of the state and the number of changes to their original value of zero
  • To send a notification whenever the reset operation is invoked
  • ,which collects information about the number of changes carried out on the??attribute before calling reset. The content of the notification sent is defined by the??instance.

    ?class is shown in?.

    ?dynamic MBean shows how to expose attributes and operations for management at runtime,by implementing the??interface. It starts by defining a method,?,for obtaining information for the MBean dynamically. The??method builds the??for the dynamic MBean.

    ?corresponds to the implementation of the??interface. The attributes,operations and notifications exposed are identical to those exposed by the??MBean.

    ?class is shown in?.

    ?class implements a straightforward JMX specification notification listener.

    ?method of the??interface is called upon reception of a notification,and prints out a message to confirm that a notification has been received.

    ?class is shown in?.

    ?class creates an RMI connector client that is configured to connect to the RMI connector server created by?.

    ?defines the same service URL??as that defined by?. This allows the connector client to retrieve the RMI connector server stub named??from the RMI registry running on port??of the local host,and to connect to the RMI connector server.

    ,is an instance of the interface?,created by the??method of?. The??method is passed the parameters??and a??environment map when it is called.

    ,to listen for notifications,as shown in?.

    ,named?,is then created by calling the??method of the??instance?.

    ,and can register MBeans and perform operations on themwith the connection remaining completely transparent to both ends.

    ?MBean and the SimpleDynamic MBean in the MBean server with a call to the??method of?,and performs the operations defined by?and??as if they were local JMX specification MBean operations. The code for the different operations performed on??is not shown here,because the operations are the same as those performed on.

    ?MBean and closes the connection. The final??is optional,as listeners registered by a remote client are removed when that client is closed.

    ?file:

    Compile the Java classes.

      Start an RMI registry on port??of the local host.

    ?to register the RMI connector stub.

      Start the??class.

    ?MBean in the MBean server. You will then be prompted to press the Enter key to obtain information about,and then to perform operations on,the??MBean.

    ?have completed,the process will be repeated for the??MBean.

    .

      Start the??class in another terminal window.

    ?and SimpleDynamic MBeans. The client will then perform operations on??and SimpleDynamic MBeans,before unregistering them.

    (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读