dk.netarkivet.monitor.jmx
Class JMXUtils

java.lang.Object
  extended by dk.netarkivet.monitor.jmx.JMXUtils

public class JMXUtils
extends java.lang.Object

Various JMX-related utility functions that have nowhere better to live.


Field Summary
static org.apache.commons.logging.Log log
           
 
Constructor Summary
JMXUtils()
           
 
Method Summary
static javax.management.MBeanServerConnection getMBeanServerConnection(javax.management.remote.JMXServiceURL url, java.util.Map<java.lang.String,java.lang.String[]> credentials)
          Connects to the given (url-specified) service point, sending the given credentials as login.
static javax.management.MBeanServerConnection getMBeanServerConnection(java.lang.String server, int jmxPort, int rmiPort, java.lang.String userName, java.lang.String password)
          Returns a connection to a remote MbeanServer defined by the given arguments.
static javax.management.remote.JMXServiceURL getUrl(java.lang.String server, int jmxPort, int rmiPort)
          Constructs the same service URL that JConsole does on the basis of a server name, a JMX port number, and a RMI port number.
static java.util.Map<java.lang.String,java.lang.String[]> packageCredentials(java.lang.String userName, java.lang.String password)
          Packages credentials as an environment for JMX connections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static org.apache.commons.logging.Log log
Constructor Detail

JMXUtils

public JMXUtils()
Method Detail

getUrl

public static javax.management.remote.JMXServiceURL getUrl(java.lang.String server,
                                                           int jmxPort,
                                                           int rmiPort)
Constructs the same service URL that JConsole does on the basis of a server name, a JMX port number, and a RMI port number. Example URL: service:jmx:rmi://0.0.0.0:9999/jndi/rmi://0.0.0.0:1099/JMXConnector where RMI port number = 9999, JMX port number = 1099 server = 0.0.0.0 aka localhost(?).

Parameters:
server - The server that should be connected to using the constructed URL.
jmxPort - The number of the JMX port that should be connected to using the constructed URL
rmiPort - The number of the RMI port that should be connected to using the constructed URL
Returns:
the constructed URL.

getMBeanServerConnection

public static javax.management.MBeanServerConnection getMBeanServerConnection(java.lang.String server,
                                                                              int jmxPort,
                                                                              int rmiPort,
                                                                              java.lang.String userName,
                                                                              java.lang.String password)
Returns a connection to a remote MbeanServer defined by the given arguments.

Parameters:
server - the remote servername
jmxPort - the remote jmx-port
rmiPort - the remote rmi-port
userName - the username
password - the password
Returns:
a MBeanServerConnection to a remote MbeanServer defined by the given arguments.

getMBeanServerConnection

public static javax.management.MBeanServerConnection getMBeanServerConnection(javax.management.remote.JMXServiceURL url,
                                                                              java.util.Map<java.lang.String,java.lang.String[]> credentials)
Connects to the given (url-specified) service point, sending the given credentials as login.

Parameters:
url - The JMX service url of some JVM on some machine.
credentials - a map with (at least) one entry, mapping "jmx.remote.credentials" to a String array of length 2. Its first item should be the user name. Its second item should be the password.
Returns:
An MBeanServerConnection representing the connected session.

packageCredentials

public static java.util.Map<java.lang.String,java.lang.String[]> packageCredentials(java.lang.String userName,
                                                                                    java.lang.String password)
Packages credentials as an environment for JMX connections. This packaging has the same form that JConsole uses: a one-entry Map, the mapping of "jmx.remote.credentials" being an array containing the user name and the password.

Parameters:
userName - The user to login as
password - The password to use for that user
Returns:
the packaged credentials