FileDocCategorySizeDatePackage
JMXDeploy.javaAPI DocGlassfish v2 API10450Fri May 04 22:31:18 BST 2007org.glassfish.deployment.util

JMXDeploy

public class JMXDeploy extends Object
Small Util to reload/restart a WebModule using JMX.
author
Jeanfrancois Arcand

Fields Summary
private static final String
mBeanName
private static URLConnection
conn
private static URL
url
private static ObjectOutputStream
objectWriter
private static ObjectInputStream
objectReader
private static String
adminUser
private static String
adminPassword
private static int
adminPort
private static String
contextRoot
private static String
host
public static final String
ADMIN_USER_ENV_PROPERTY_NAME
public static final String
ADMIN_PASSWORD_ENV_PROPERTY_NAME
public static final String
TRUST_MANAGER_PROPERTY_NAME
public static final String
KEY_MANAGER_PROPERTY_NAME
public static final String
SSL_SOCKET_FACTORY
public static final String
HOSTNAME_VERIFIER_PROPERTY_NAME
public static final String
STRING_MANAGER_CLASS_NAME
public static final String
DEFAULT_TRUST_MANAGER
public static final String
SERVLET_CONTEXT_PROPERTY_NAME
public static final String
HTTP_AUTH_PROPERTY_NAME
public static final String
DEFAULT_SERVLET_CONTEXT_ROOT
public static final String
DEFAULT_HTTP_AUTH_SCHEME
public static final String
DIGEST_HTTP_AUTH_SCHEME
public static final String
S1_HTTP_PROTOCOL
public static final String
S1_HTTPS_PROTOCOL
Constructors Summary
Methods Summary
private static javax.management.MBeanServerConnectiongetMBeanServerConnection()
Local the MBeanServer.

        return getMBeanServerConnection(host,adminPort,adminUser,adminPassword);
    
private static javax.management.MBeanServerConnectiongetMBeanServerConnection(java.lang.String host, int port, java.lang.String user, java.lang.String password)
Get an Server Connection.


        final JMXServiceURL url = 
            new JMXServiceURL("service:jmx:s1ashttp://" + host + ":" + port);
        final Map env = new HashMap();
        final String PKGS = "com.sun.enterprise.admin.jmx.remote.protocol";
        
        env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, PKGS);
        env.put(ADMIN_USER_ENV_PROPERTY_NAME, user );
        env.put( ADMIN_PASSWORD_ENV_PROPERTY_NAME, password);
        env.put(HTTP_AUTH_PROPERTY_NAME, DEFAULT_HTTP_AUTH_SCHEME);
        final JMXConnector conn = JMXConnectorFactory.connect(url, env);
        return conn.getMBeanServerConnection();
    
private static javax.management.MBeanServerConnectiongetSecureMBeanServerConnection()
Get a secure JMX connection.

       return getSecureMBeanServerConnection(host,adminPort,adminUser,
                adminPassword); 
    
private static javax.management.MBeanServerConnectiongetSecureMBeanServerConnection(java.lang.String host, int port, java.lang.String user, java.lang.String password)
Get a secure JMX connection.


        final JMXServiceURL url = new JMXServiceURL("service:jmx:s1ashttps://" +
                                  host + ":" + port);
        final Map env = new HashMap();
        final String PKGS = "com.sun.enterprise.admin.jmx.remote.protocol";
                                                                            
        env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, PKGS);
        env.put(ADMIN_USER_ENV_PROPERTY_NAME, user );
        env.put( ADMIN_PASSWORD_ENV_PROPERTY_NAME, password);
        env.put(HTTP_AUTH_PROPERTY_NAME, DIGEST_HTTP_AUTH_SCHEME);
        final JMXConnector conn = JMXConnectorFactory.connect(url, env);
        return conn.getMBeanServerConnection();
    
public static voidmain(java.lang.String[] args)

    
          
        try{
            String command = args[0];
            host = args[1];
            contextRoot = "/" + args[2];
            adminUser = args[3];
            adminPassword = args[4];
            adminPort = Integer.parseInt(args[5]);

            if ( command.equals("--restart")){
                restart(mBeanName + contextRoot);
            } else if (command.equals("--reload")){
                reload(mBeanName + contextRoot);
            }
            System.out.println("DEPLOYMENT SUCCESS");
        } catch(Throwable ex){
            System.out.println("Usage\n");
            System.out.println("jmxReload --reload|restart");
            System.out.print(" [contextRoot]");
            ex.printStackTrace();
            System.out.println("DEPLOYMENT FAILED");
        }
    
private static voidreload(java.lang.String oName)

        ObjectName appMBean = new ObjectName(oName);

        try {
            reloadHttp(appMBean);
        } catch (Throwable t){
            t.printStackTrace();
            reloadHttps(appMBean);
        }
     
private static voidreloadHttp(javax.management.ObjectName appMBean)
Reload the Context using JMX and HTTP.


        Object[] params = new Object[0];
        String[] signature = new String[0];
        System.out.println("Reload Context: " + contextRoot);

        Object o= getMBeanServerConnection().
            invoke(appMBean, "reload", params, signature);
    
private static voidreloadHttps(javax.management.ObjectName appMBean)
Reload the Context using JMX and HTTPs

        Object[] params = new Object[0];
        String[] signature = new String[0];
        System.out.println("Reloading Context: " + contextRoot);

        Object o= getSecureMBeanServerConnection()
                    .invoke(appMBean, "reload", params, signature);

    
private static voidrestart(java.lang.String oName)

        ObjectName appMBean = new ObjectName(oName);
        
        try {
            restartHttp(appMBean);
        } catch (Throwable t){
            restartHttps(appMBean);
        }
    
private static voidrestartHttp(javax.management.ObjectName appMBean)
Reload the Context using JMX and HTTP.

        Object[] params = new Object[0];
        String[] signature = new String[0];
        System.out.println("Stopping Context: " + contextRoot);

        Object o= getMBeanServerConnection().
            invoke(appMBean, "stop", params, signature);

        System.out.println("Starting Context: " + contextRoot);

        o= getMBeanServerConnection()
            .invoke(appMBean, "start", params, signature);
    
private static voidrestartHttps(javax.management.ObjectName appMBean)
Reload the Context using JMX and HTTPs

        Object[] params = new Object[0];
        String[] signature = new String[0];
        System.out.println("Stopping Context: " + contextRoot);

        Object o= getSecureMBeanServerConnection()
                    .invoke(appMBean, "stop", params, signature);

        System.out.println("Starting Context: " + contextRoot);

        o= getSecureMBeanServerConnection().invoke(
            appMBean, "start", params, signature);