United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6238815 Add a way to get the address to which a connector client is connected
JDK-6238815 : Add a way to get the address to which a connector client is connected

Details
Type:
Enhancement
Submit Date:
2005-03-10
Status:
Resolved
Updated Date:
2010-07-29
Project Name:
JDK
Resolved Date:
2005-06-02
Component:
core-svc
OS:
generic
Sub-Component:
javax.management
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports

Sub Tasks

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
                                     
2005-04-20



Hardware and Software, Engineered to Work Together