com.jrockit.mc.rjmx
Class ConnectionDescriptorToolkit

java.lang.Object
  extended by com.jrockit.mc.rjmx.ConnectionDescriptorToolkit

public class ConnectionDescriptorToolkit
extends java.lang.Object

Toolkit for extracting and caching data from IConnectionDescriptor

Author:
Marcus Hirt

Field Summary
static int UNKNOWN_PORT
          Port number returned when no actual port number currently is known.
static java.lang.String VALUE_LOCALHOST
          The interned string "localhost".
 
Method Summary
static java.util.Map createCredentialsEnv(java.lang.String username, java.lang.String password)
          Creates a JMX environment from the provided credentials.
static javax.management.remote.JMXServiceURL createServiceURL(java.lang.String host, int port, boolean useJMXRMI)
          Creates a jmx over rmi or "jmx over rmp" service URL.
static java.lang.String generateGUID()
          An adequately globally unique ID.
static java.lang.String getCompactName(IConnectionDescriptor descr)
          Returns the server name in the form "server IP:port", if available.
static java.lang.String[] getCredentials(IConnectionDescriptor descriptor)
          Returns the credentials for the connection descriptor as a String array.
static int getDefaultPort()
           
static java.lang.String getEncryptionScheme(IConnectionDescriptor descr)
           
static java.lang.String getHostName(IConnectionDescriptor descr)
          Will attempt to derive the host name from connection descriptor.
static java.lang.String getPassword(IConnectionDescriptor descr, IConnectionManager manager)
          Returns the currently set password.
static int getPort(IConnectionDescriptor descr)
          Will attempt to derive the port from the IConnectionDescriptor.
static java.lang.String getUser(IConnectionDescriptor descr)
          Returns the user name, if available.
static boolean isAutoDiscovered(IConnectionDescriptor descriptor)
          Returns true if the JVM represented by the descriptor was automatically discovered.
static boolean isExportingPassword(IConnectionDescriptor descr)
          Whether the provided ConnectionDescriptor exports its password along its other data to XML.
static java.lang.Boolean isHotspotJVMName(java.lang.String vmName)
          Returns whether this is a HotSpot JVM or not.
static boolean isJRockit(IConnectionHandle connectionHandle)
          Returns true if the connection handle is connected to a JRockit, false otherwise.
static java.lang.Boolean isJRockitJVMName(java.lang.String vmName)
          Returns whether this is a JRockit JVM or not.
static boolean isLocal(IConnectionDescriptor descriptor)
          Returns true if the descriptor is a local descriptor.
static boolean isUsingRMP(IConnectionDescriptor descriptor)
          Returns true if the descriptor uses the legacy RMP protocol.
static IConnectionDescriptor rename(IConnectionDescriptor connectionDescriptor, java.lang.String name)
          Wraps the connection descriptor, deferring all calls but the getName() to the delegate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALUE_LOCALHOST

public static final java.lang.String VALUE_LOCALHOST
The interned string "localhost".


UNKNOWN_PORT

public static final int UNKNOWN_PORT
Port number returned when no actual port number currently is known. (The value is -2.)

See Also:
Constant Field Values
Method Detail

getPassword

public static java.lang.String getPassword(IConnectionDescriptor descr,
                                           IConnectionManager manager)
                                    throws com.jrockit.mc.common.security.SecurityException
Returns the currently set password.

Returns:
will retrieve the currently set password. If only encrypted password exists, an attempt to decrypt it will be made.
Throws:
com.jrockit.mc.common.security.SecurityException - if the password was encrypted and could not be decrypted.

getUser

public static java.lang.String getUser(IConnectionDescriptor descr)
Returns the user name, if available.

Parameters:
descr - the IConnectionDescriptor to retrieve the user name from.
Returns:
the user, if available, or null.

getCompactName

public static java.lang.String getCompactName(IConnectionDescriptor descr)
Returns the server name in the form "server IP:port", if available.

Returns:
the connection name in compact form, or "Unknown" if the service URL could not be resolved.

generateGUID

public static java.lang.String generateGUID()
An adequately globally unique ID. It is guaranteed to be locally unique, and very likely to be globally unique.

Returns:
a globally unique identifier.

getHostName

public static java.lang.String getHostName(IConnectionDescriptor descr)
Will attempt to derive the host name from connection descriptor. If the JXMServiceURL uses jmxrmi, the host name will be derived from the information in the JXMServiceURL.

Parameters:
descr - the IConnectionDescriptor to retrieve the host name from.
Returns:
the host name.

getPort

public static int getPort(IConnectionDescriptor descr)
Will attempt to derive the port from the IConnectionDescriptor. If the JXMServiceURL uses jmxrmi, the port will be derived from the information in the JXMServiceURL.

Parameters:
descr - the IConnectionDescriptor to derive the port from.
Returns:
the port number, or UNKNOWN_PORT if the URL has not been resolved yet.

rename

public static IConnectionDescriptor rename(IConnectionDescriptor connectionDescriptor,
                                           java.lang.String name)
Wraps the connection descriptor, deferring all calls but the getName() to the delegate.

Parameters:
connectionDescriptor - the connection descriptor rename
name - the name of the new descriptor
Returns:
a connection descriptor with the given name.

isExportingPassword

public static boolean isExportingPassword(IConnectionDescriptor descr)
Whether the provided ConnectionDescriptor exports its password along its other data to XML.

Returns:
true if it exports password, false otherwise.

getEncryptionScheme

public static java.lang.String getEncryptionScheme(IConnectionDescriptor descr)
Returns:
the encryption scheme used when encrypting the password.

createCredentialsEnv

public static java.util.Map createCredentialsEnv(java.lang.String username,
                                                 java.lang.String password)
Creates a JMX environment from the provided credentials.

Parameters:
username - the username.
password - the password.
Returns:
the environment map.

createServiceURL

public static javax.management.remote.JMXServiceURL createServiceURL(java.lang.String host,
                                                                     int port,
                                                                     boolean useJMXRMI)
                                                              throws java.net.MalformedURLException
Creates a jmx over rmi or "jmx over rmp" service URL.

Parameters:
host - the host name.
port - port or JMXDescriptorBuilder.DEFAULT_PORT for the default port for the selected protocol
useJMXRMI - true if JMX over RMI should be used, false to use JMX over RMP
Returns:
the JMXServiceURL.
Throws:
java.net.MalformedURLException - if the URL could not be created with the provided data.

getDefaultPort

public static int getDefaultPort()
Returns:
the default port for the management agent. May vary depending on which version of JRockit the method is executed in.

isLocal

public static boolean isLocal(IConnectionDescriptor descriptor)
Returns true if the descriptor is a local descriptor.

Parameters:
descriptor - the descriptor to check.
Returns:
true if it represents a local attach JVM.

isAutoDiscovered

public static boolean isAutoDiscovered(IConnectionDescriptor descriptor)
Returns true if the JVM represented by the descriptor was automatically discovered.

Parameters:
descriptor - the descriptor to check.
Returns:
true if this descriptor was automatically discovered, i.e. not created by the user.

isUsingRMP

public static boolean isUsingRMP(IConnectionDescriptor descriptor)
                          throws java.io.IOException
Returns true if the descriptor uses the legacy RMP protocol.

Parameters:
descriptor - the descriptor to check.
Returns:
true if a connection created with this descriptor would use the old legacy protocol RMP, false if the serviceURL would not use RMP.
Throws:
java.io.IOException - if the serviceURL could not be resolved.

getCredentials

public static java.lang.String[] getCredentials(IConnectionDescriptor descriptor)
Returns the credentials for the connection descriptor as a String array.

Parameters:
descriptor - the descriptor to return the credentials for.
Returns:
the credentials for the descriptor.

isJRockit

public static boolean isJRockit(IConnectionHandle connectionHandle)
Returns true if the connection handle is connected to a JRockit, false otherwise.

Parameters:
connectionHandle - the connection handle to check.
Returns:
true if the connection handle is connected to a JRockit, false otherwise.

isJRockitJVMName

public static java.lang.Boolean isJRockitJVMName(java.lang.String vmName)
Returns whether this is a JRockit JVM or not. TODO: In the future we probably want this to be "supports JMXMAPI" instead.

Parameters:
vmName - the JVM name to check.
Returns:
true of it is a JRockit, false if it isn't or null if not possible to tell.

isHotspotJVMName

public static java.lang.Boolean isHotspotJVMName(java.lang.String vmName)
Returns whether this is a HotSpot JVM or not.

Parameters:
vmName - the JVM name to check.
Returns:
true of it is a HotSpot, false if it isn't or null if not possible to tell.


Copyright © 1999, 2011, Oracle and/or its affiliates. All rights reserved.