JDK-6238815 : Add a way to get the address to which a connector client is connected
  • Type: Enhancement
  • Component: core-svc
  • Sub-Component: javax.management
  • Affected Version: 6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-03-10
  • Updated: 2017-05-16
  • Resolved: 2005-06-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b39Fixed
Description
Because JMXConnector is an interface, we cannot add new methods to it without breaking existing code that implements the interface.  In particular, it would be useful to have a getAddress() method, even though that method would not always be able to return a meaningful JMXServiceURL.  The only way to add a method would be to define a new subinterface, JMXConnector2 say, and put getAddress() in that.  And if in a later revision we wanted to add yet another method, we would have to add JMXConnector3.

The proposed alternative is to define an abstract class rather than an interface: AbstractJMXConnector, which defines an abstract method getAddress().  The existing concrete class RMIConnector can be retrofitted to extend AbstractJMXConnector and define getAddress().  Other methods can be added to this class in the future, although they cannot be abstract (for the same reason as methods cannot be added to interfaces) but must have a default implementation.

Another advantage of AbstractJMXConnector is that it can provide implementations of two JMXConnector methods that are in practice always implemented in the same way:

public void connect() throws IOException {
    connect((Map<String,?>) null);
}

public void MBeanServerConnection getMBeanServerConnection() throws IOException {
    return getMBeanServerConnection((Subject) null);
}

If you want to be able to call getAddress() on a JMXConnector, unfortunately you have to write something like this:

JMXServiceURL addr;
if (jmxConnector instanceof AbstractJMXConnector)
    addr = ((AbstractJMXConnector) jmxConnector).getAddress();
else
    addr = null;

The downcast isn't very pretty but there does not seem to be any alternative if we want to have getAddress().
###@###.### 2005-03-10 14:37:19 GMT

Comments
EVALUATION A better solution might be to define an new interface javax.management.remote.Addressable, say, like this: public interface Addressable { public JMXServiceURL getAddress(); } Then various JMXConnector implementations could implement this interface and you could write: JMXServiceURL addr = null; if (connector instanceof Addressable) addr = ((Addressable) connector).getAddress(); This seems cleaner than downcasting. ###@###.### 2005-04-20 14:55:49 GMT
20-04-2005