Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6238815

Add a way to get the address to which a connector client is connected

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 6
    • core-svc
    • b39
    • generic
    • generic

      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

            sjiang Shanliang Jiang (Inactive)
            emcmanus Eamonn McManus
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: