`

Remote JMX Exceptions

    博客分类:
  • JAVA
阅读更多

转载自:http://marxsoftware.blogspot.com/2008/06/remote-jmx-exceptions.html(需要fanqiang)

 

Perhaps the most difficult aspect of getting a freshly written JSR-160 (Remote JMX ) compliant application working is ensuring a proper JMXServiceURL . In this blog entry, I cover some of the most common JMXServiceURL -related exceptions one may run into when developing the client and server portions of a management and monitoring system using Remote JMX.

The JMX 1.4 Specification combines the original JMX specification with the Remote JMX specification in a single document (the JMX Remote API Specification is part III of this document ). This third part covers the required RMI connector as well as the optional JMXMP connector. In this blog entry, I'll be focusing on using the RMI connector with Java SE 6 HotSpot platform MBean server . Instead of using JConsole as a client, I'll use a simple custom client to illustrate some of the exceptions one may encounter when writing one's own client.

I am using essentially the same code in this blog for examples that I previously used in the previous blog entry Remote JMX: With and Without Spring and Proxies . I will not reproduce the code here, but it is sufficient to know that the JMX Connector server code generally establishes its JMXServiceURL as service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi . Note that the protocol is RMI, the host is localhost, the port is 1099, and the URL string is "jmxrmi". Because the JMX client needs to use the same JMXServiceURL as provided by the server, I appreciate it when third-party JMX servers provide this to me. For example, both GlassFish and the JMX Web Services Connector Reference Implementation sample provide their JMXServiceURL to the console when they are executed.

When the JMXServiceURL is known, it is relatively straightforward to write a client. The most significant lines of code for doing this are extracted from the code in the previously referenced blog and displayed next:


 final String objectNameStr = "dustin:type=status,name=remoteJMX";  
 final String jmxRmiStr =  "service:jmx:rmi://localhost/jndi/rmi://localhost:1099/jmxrmi";  
  try  
    {  
         final ObjectName objectName = new ObjectName(objectNameStr);  
         final JMXServiceURL jmxUrl = new JMXServiceURL(jmxRmiStr);  
         final JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl);  
         final MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();  

 

As the code listing above demonstrates, it is fairly easy (and mostly boilerplate) to connect clients to a JMX Connector Server with a well-known JMXServiceURL . However, it is not uncommon for new JMX developers to struggle to get the JMXServiceURL appropriately set. In the remainder of this blog entry, I now look at some of the most common JMXServiceURL -related exceptions one may run into.

ERROR: IOException trying to connect to JMX Connector Server : Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException : Connection refused to host: localhost; nested exception is:
java.net.ConnectException: Connection refused: connect]

A possible cause of this exception includes no JMX Connector Server running on the specified host and port combination.

Also, ensure that an RMI registry has been started at the specified port.

ERROR: IOException trying to connect to JMX Connector Server: Failed to retrieve RMIServer stub: javax.naming.NameNotFoundException: jmx- rmi

This NameNotFoundException was a result of inadvertently mistyping the client's String URL portion (jmx-rmi specified by the client rather than jmxrmi without the hyphen). This is different from the above error because a JMX Connector Server is at the specified host and port, but with a different String portion. Because multiple JMX Connector Servers can use the same host/port combination as long as they have unique String portions of their URLs, it is not surprising that no assumptions can be made about what String was intended.

Exception in thread "main" java.lang.ClassCastException : com.sun.jndi.rmi.registry.RegistryContext cannot be cast to javax.management.remote.rmi.RMIServer

The previous exception demonstrated the result of attempting to access a JMX Connector Server from a client with the correct host/port comibination, but with an incorrect String URL portion. This ClassCastException is the result of not specifying any String URL portion at all in the JMXServiceURL . In other words, the jmxrmi portion was left off the end of the client's JMXServiceURL .

java.io.IOException: Cannot bind to URL [rmi://localhost:1099/jmxrmi] : javax.naming.NameAlreadyBoundException : jmxrmi [Root exception is java.rmi.AlreadyBoundException: jmxrmi ]

Until now, all of the previously covered exceptions resulted from a JMX Client using a mistyped or otherwise incorrect JMXServiceURL that did not match that used by the JMX Connector Server. This exception, however, is a JMX Connector Server exception that results from two different applications trying to use the same JMXServiceURL on the same host/port with the same URL String.

ERROR: Problem with JMXServiceURL based on rmi:///jndi/rmi://localhost:1099/jmxrmi: Service URL must start with service:jmx:

This error message is particularly descriptive and occurs when the JMXServiceURL does not begin with the specification-required service:jmx: portion. See Section 13.8 ("Connector Server Addresses") for additional details on all JMXServiceURL s beginning with this portion.


ERROR: Problem with JMXServiceURL based on service:jmx:: ///jndi/rmi://localhost:1099/jmxrmi: Missing or invalid protocol name: ""

As the error message indicates, the protocol is missing from the JMXServiceURL , which should be service:jmx:rmi :///jndi/rmi://localhost:1099/jmxrmi , but the portion in red was omitted.

ERROR: Problem with JMXServiceURL based on service:jmx:nothing :///jndi/rmi://localhost:1099/jmxrmi: Unsupported protocol: nothing

Whereas the previous error message indicated a missing protocol designation, this error indicates an erroneous protocol specification. In this particular case, the incorrect JMXServiceURL used was service:jmx:nothing :///jndi/rmi://localhost:1099/jmxrmi where the "nothing" in red should have been "rmi".

ERROR: IOException trying to connect to JMX Connector Server: Failed to retrieve RMIServer stub: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

This error message is displayed for the case where the second protocol listing in the JMXServiceURL is either omitted or has an incorrect value. In other words, if the highlighted portion of the correct JMXServiceURL (service:jmx:rmi:///jndi/rmi ://localhost:1099/jmxrmi )was omitted entirely or had something unexpected like "nothing," this error message would occur.

Other Remote JMX Exceptions/Errors Considerations

There are, of course, several other types of exceptions one can run into when remotely accessing a JMX Connector Server. These exceptions, which have not been covered here, are those that are thrown when the connection is successfully made, but the sought-after MBean cannot be found or some other problem occurs. The JMX Best Practices document outlines recommendations related to MBeans throwing standard exceptions and also recommends having MBeans intended for remote management/monitoring implement interfaces with operations that use the throws IOException clause (more granular for client than available as UndeclaredThrowableException ).

JMX Exceptions in General

The focus of this blog entry has been on common exceptions and errors encountered when running a custom JMX Connector Client with a custom JMX Connector Server. Note that JMX spells out its own exception hierarchy related to the JMX Agent. Section 6.4 (JMX Exceptions) of the JMX 1.4 Specification is devoted to these JMX exceptions. The section talks about the JMException , which is the main class and parent of all descendant exception classes (exception runtime exceptions) thrown by a JMX agent implementation. The JMX runtime exceptions are represented by JMRuntimeException and its descendant exceptions.

分享到:
评论

相关推荐

    catalina-jmx-remote.jar

    catalina jmx remote jmx 监控 tomcat 资源

    tomcat-catalina-jmx-remote-9.0.5.jar

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

    catalina-jmx-remote.rar

    `catalina-jmx-remote.rar`这个压缩包文件,显然与通过JMX远程访问Catalina相关,让我们深入探讨一下这个主题。 首先,理解JMX的原理和作用是至关重要的。JMX允许开发者创建和注册管理对象(MBeans),这些对象代表...

    JMX以RMI方式连接的场景示例

    在本场景中,我们将介绍如何使用RMI(Remote Method Invocation)连接方式来实现JMX框架的各层级的连接。 MBean是JMX框架的基本组件,用于提供管理信息和功能。MBean可以是任何Java对象,只要它实现了相关的接口。...

    catalina-jmx-remote包,版本是7.0.54

    用于windows通过VisualVM远程监控linux下的tomcat使用情况时所需要的jar包。可监控CPU、内存、类和线程。

    jmx-1_2_1-ri.zip jmx_remote-1_0_1_03-ri.zip jmx-1_1-mr-spec.zip

    2. **jmx_remote-1_0_1_03-ri.zip**:此文件是JMX Remote API的一个实现,版本为1.0.1_03。JMX Remote API扩展了基本的JMX,使得管理操作可以跨越网络进行,允许远程监控和管理Java应用程序。这个版本可能包含了更新...

    catalina-jmx-remote

    zabbix配置tomcat所需要的jmx的jar包,这里对应tomcat的8.0.36版本

    jmx-1.2.1(jmxri+jmxtools) jar

    这个"jmx-1.2.1(jmxri+jmxtools) jar"包含了JMX的两个核心组件:JMX Remote Interface (jmxri) 和 JMX Tools。 1. **JMX Remote Interface (jmxri)**: JMX Remote Interface 是JMX框架的一部分,它允许远程访问和...

    jmx三种访问方式

    1. **远程JMX连接**:Java默认使用Remote Method Invocation (RMI) 协议来实现远程JMX连接。通过设置`-Dcom.sun.management.jmxremote.rmi.port`和`-Dcom.sun.management.jmxremote.port`等参数,可以启用RMI服务,...

    catalina-jmx-remote-6.0.36.jar

    此jar包为zabbix监控tomcat时用到的库文件包,请结合zabbix官网中操作明细来实施操作

    jmx简单实例,附带jar包完整项目

    - `jmxri-1.2.1.jar`:JMX Remote Lifecycle API,实现了JMX的远程访问功能,使得我们可以远程监控和管理应用。 - `jmxtools-1.2.1.jar`:包含了一些JMX工具,如JConsole,用于图形化地查看和管理Java应用程序的...

Global site tag (gtag.js) - Google Analytics