FileDocCategorySizeDatePackage
JmxServiceUrlFactory.javaAPI DocGlassfish v2 API11370Fri May 04 22:36:30 BST 2007com.sun.enterprise.admin.jmx.remote.server.rmi

JmxServiceUrlFactory

public class JmxServiceUrlFactory extends Object
A factory class to create the various JMXServiceURLs in various cases. This is useful because there are many ways of creating the JMXServiceURL for an intended connector server and client. The methods in this class can be used precisely for given case.

Fields Summary
public static final String
RMI_JSR160_CS_JNDI_SUFFIX
Field
public static final String
JCONSOLE_RMI_JSR160_CS_JNDI_SUFFIX
private static final Logger
logger
Constructors Summary
private JmxServiceUrlFactory()

      
    
Methods Summary
private static java.lang.Stringconcat(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4)

        final StringBuffer sb = new StringBuffer();
        if (s1 != null)
            sb.append(s1);
        if (s2 != null)
            sb.append(s2);
        if (s3 != null)
            sb.append(s3);
        if (s4 != null)
            sb.append(s4);
        return ( sb.toString() );
    
public static javax.management.remote.JMXServiceURLforJconsoleOverRmiWithJndiInAppserver(java.lang.String host, int port)

        return ( forRmiWithJndi(host, port, JCONSOLE_RMI_JSR160_CS_JNDI_SUFFIX, false) );
    
public static javax.management.remote.JMXServiceURLforJmxmp(int port)

        return ( forJmxmp(localhost(), port) );
    
public static javax.management.remote.JMXServiceURLforJmxmp(java.lang.String host, int port)
Returns the JMXServiceURL for JMXMP and given host and port. The host may not be null.

        JMXServiceURL url;
        if (host == null)
            throw new IllegalArgumentException("Null Host");
        try {
            url = new JMXServiceURL("jmxmp", host, port);
            final String msg = "JMXServiceURL is: " + url;
            logger.fine(msg);
        }
        catch (MalformedURLException m) {
            url = null;
            //squelching the exception purposely, as I want to be sure.
        }
        assert (url != null): "Something seriously wrong, can't form the JMXServiceURL";
        return ( url );
    
public static javax.management.remote.JMXServiceURLforRmiIiopWithoutIor(int port)
This API should be called when the ConnectorServer and following is true.
  • The protocol is RMI over IIOP.
  • There is no JNDI involved.
After the ConnectorServer is created with this URL, its address will contain the actual base-64 encoded IOR that it can be used by ConnectorClients. In order to connect to such a ConnectorServer the client has to be provide the IIOP stub to form the JMXServiceURL. Bottom line: This API should be called when creating ConnectorServer.

see
JMXServiceURL

        JMXServiceURL url;
        try {
            final String s = "service:jmx:iiop://" + localhost() + ":" + port;
            url = new JMXServiceURL(s);
            final String msg = "JMXServiceURL is: " + url;
            logger.fine(msg);
        }
        catch (MalformedURLException m) {
            url = null;
            //squelching the exception purposely, as I want to be sure.
        }
        assert (url != null): "Something seriously wrong, can't form the JMXServiceURL";
        return ( url );
    
public static javax.management.remote.JMXServiceURLforRmiJrmpWithoutStub(int port)
This API should be called when the ConnectorServer and following is true.
  • The protocol is RMI over JRMP.
  • There is no JNDI involved.
After the ConnectorServer is created with this URL, its address will contain the actual base-64 encoded stub that it can be used by ConnectorClients. In order to connect to such a ConnectorServer the client has to be provide the stub to form the JMXServiceURL. Bottom line: This API should be called when creating ConnectorServer.

see
JMXServiceURL

        JMXServiceURL url;
        try {
            final String s = "service:jmx:rmi://" + localhost() + ":" + port;
            url = new JMXServiceURL(s);
            final String msg = "JmxServiceUrlFactory=>JMXServiceURL is: " + url;
            logger.fine(msg);
        }
        catch (MalformedURLException m) {
            url = null;
            //squelching the exception purposely, as I want to be sure.
        }
        assert (url != null): "Something seriously wrong, can't form the JMXServiceURL";
        return ( url );
    
private static javax.management.remote.JMXServiceURLforRmiWithJndi(java.lang.String host, int port, java.lang.String jn, boolean addHost)
A convenience method to create the JMXServiceURL for both Connector Client and Connector Server. This API should be used when:
  • JNDI is used to obtain the stub. This must start with '/'. Must not be null.
  • Naming Service's host and port are known.
  • The JNDI name of the stub with which it is registered is known.
This is a symmetric form of URL.

param
host String representing the host name
parm
port int representing the port of naming service like rmi registry
param
jn String representing the JNDI name of the stub. This is known to the client or server wants to specify it.
param
addHost boolean indicating the URL should have the host name or not. If false what is returned is an an ignored-host form.

        JMXServiceURL url;
        String hps = ""; //empty String
        if (host == null || jn == null) {
            throw new IllegalArgumentException("Null Argument");
        }
        if (! jn.startsWith("/"))
            throw new IllegalArgumentException("jndi-name must start with a /");
        if (addHost) {
            hps = host + ":" + port;
        }
        try {
            final String s = "service:jmx:rmi://" + hps + "/jndi/rmi://" + host + ":" + port  + jn;
            url = new JMXServiceURL(s);
            final String msg = "JMXServiceURL is: " + url;
            logger.fine(msg);
        }
        catch (MalformedURLException m) {
            url = null;
            //squelching the exception purposely, as I want to be sure. No real need to propagate.
        }
        assert (url != null): "Something seriously wrong, can't form the JMXServiceURL";
        return ( url );
    
private static javax.management.remote.JMXServiceURLforRmiWithJndi(int port, java.lang.String jn)
A variant of forRmiWithJndi(String, int, String, boolean). Returns the ignored host form with localhost as the naming host for the given jndi name.

        return ( forRmiWithJndi(localhost(), port, jn, false) );
    
private static javax.management.remote.JMXServiceURLforRmiWithJndi(int port)
A variant of forRmiWithJndi(String, int, String, boolean). Returns the System Jmx Connector address at the given port. The jndi name is fixed by the field RMI_JSR160_CS_JNDI_SUFFIX.

        return ( forRmiWithJndi(port, RMI_JSR160_CS_JNDI_SUFFIX) );
    
public static javax.management.remote.JMXServiceURLforRmiWithJndiInAppserver(java.lang.String host, int port)
This is a method used by both JSR 160 connector server and connector clients within the application server. This API should be used by all the components within the application server. Note the following points about the returned JMXServiceURL.
  • Naming Service's host and port are provided.
  • The JNDI name of the stub is fixed.
  • This is the "ignored-host" kind of form. It always returns the URL which looks like service:jmx:rmi:///jndi/rmi://host:port/
This is a symmetric form of URL.

param
host String representing the host name
parm
port int representing the port of naming service like rmi registry
see
JMXServiceUrlFactory#RMI_JSR160_CS_JNDI_SUFFIX

        return ( forRmiWithJndi(host, port, RMI_JSR160_CS_JNDI_SUFFIX, false) );
    
static java.lang.Stringlocalhost()

        String h;
        try {
            h = java.net.InetAddress.getLocalHost().getCanonicalHostName();
        }
        catch (java.net.UnknownHostException e) {
            h = "localhost";
        }
        return ( h );