FileDocCategorySizeDatePackage
JmxConnectorLifecycle.javaAPI DocGlassfish v2 API14033Wed Aug 01 11:39:20 BST 2007com.sun.enterprise.admin.server.core

JmxConnectorLifecycle

public class JmxConnectorLifecycle extends Object implements com.sun.appserv.server.ServerLifecycle
author
kedar

Fields Summary
public static final Logger
sLogger
private static final com.sun.enterprise.util.i18n.StringManager
sm
private com.sun.enterprise.server.ServerContext
initContext
private com.sun.enterprise.config.serverbeans.JmxConnector
connectorConfig
private JMXConnectorServer
cs
private JMXConnectorServer
jconsolecs
private com.sun.enterprise.admin.jmx.remote.server.rmi.JmxConnectorServerDriver
driver
private boolean
isEnabled
Constructors Summary
public JmxConnectorLifecycle()
Creates a new instance of JmxConnectorLifecycle.

               
      
        sLogger.log(Level.FINE, "rjmx.lc.init");
    
Methods Summary
private voidconfigureJmxConnectorServerDriver()

        
        driver.setAuthentication(true);
        driver.setAuthenticator(createJMXAuthenticator());        
        driver.setLogger(this.sLogger);
        driver.setMBeanServer(this.getAssociatedMBS());
        driver.setRmiRegistrySecureFlag(new Boolean(System.getProperty(RmiTweaks.SECURE_RMI_REGISTRY)).booleanValue());
        try {
            driver.setProtocol(RemoteJmxProtocol.instance(connectorConfig.getProtocol()));
            driver.setPort(Integer.parseInt(connectorConfig.getPort()));
            driver.setBindAddress(connectorConfig.getAddress());
            handleSsl();
        }
        catch (final Exception e) {
            throw new ServerLifecycleException(e.getMessage());
        }
    
private javax.management.remote.JMXAuthenticatorcreateJMXAuthenticator()

        final ASJMXAuthenticator authenticator = new ASJMXAuthenticator();
        // TODO: If domain.xml is not present, can not configure authentication        
        authenticator.setRealmName(connectorConfig.getAuthRealmName());        
        authenticator.setLoginDriver(new ASLoginDriverImpl());
        return authenticator;
    
private javax.management.MBeanServergetAssociatedMBS()

        /*
        final String returnAllMBS = null;
        final ArrayList list = MBeanServerFactory.findMBeanServer(returnAllMBS);
        if (list.isEmpty())
                throw new RuntimeException("Initialize the MBeanServers first...");
        return (MBeanServer)list.get(0); //for now
         */
        return ( MBeanServerFactory.getMBeanServer() );
    
private java.util.MapgetEnvironment()

        final Map env = new HashMap();
        return ( env );
    
private voidhandleIsEnabled(java.lang.String port)
Handles the enabled flag on system-jmx-connector. On dev profile, it is okay that this flag is set to false. But for other profiles, it has to be true as the inter server communication depends on it.

        /* Implementation note: This could have been handled using the Pluggable
         * Feature Factory, but since there isn't much pluggable behavior, I am going to
         * rely on the system property. In general, this should not be done.
         */
        if (isEE() && !isEnabled) {
            //EE and not enabled is not fine
            final String msg = sm.getString("rjmx.lc.disabled_ee_na", port);
            throw new ServerLifecycleException(msg);
        }
        if (!isEE() && !isEnabled) {
            //PE and not enabled is fine - log and move on
            sLogger.log(Level.INFO, "rjmx.lc.not_enabled", port);
        }
        //other 2 cases are implicitly handled
    
private voidhandleSsl()

        final boolean ssl = connectorConfig.isSecurityEnabled();
        
        RMIServerSocketFactory sf = null;
        if (ssl) {
            driver.setSsl(ssl);
            Ssl sslc = connectorConfig.getSsl();
            if (sslc == null) 
                sslc = initDefaultSslConfiguration();
            sf = new AdminSslServerSocketFactory(sslc, connectorConfig.getAddress());
            RMIClientSocketFactory cf = new AdminRMISSLClientSocketFactory();
            driver.setRmiClientSocketFactory(cf);
        } else sf = new RMIMultiHomedServerSocketFactory(connectorConfig.getAddress());
        driver.setRmiServerSocketFactory(sf);        
    
private voidhandleSupportedProtocol()

        final String pfc = connectorConfig.getProtocol();
        if (RemoteJmxProtocol.RMIJRMP != RemoteJmxProtocol.instance(pfc)) {
            final String port = connectorConfig.getPort();
            final String setP = connectorConfig.getProtocol();
            final String supportedP = RemoteJmxProtocol.RMIJRMP.getName();
            final String msg = sm.getString("rjmx.lc.unsupported_protocol", port, setP, supportedP);
            throw new ServerLifecycleException (msg);
        }
    
private voidinitConnectorConfig()

        //This is the AdminService config bean
        AdminService as = ServerBeansFactory.getConfigBean(initContext.getConfigContext()).
                  getAdminService();
        connectorConfig = as.getJmxConnectorByName(as.getSystemJmxConnectorName());
        if (connectorConfig.isEnabled()) {
            this.isEnabled = true;
        }
    
private com.sun.enterprise.config.serverbeans.SslinitDefaultSslConfiguration()

        Ssl ssl = new Ssl();
        ssl.setCertNickname(ServerHelper.DEFAULT_CERT_NICKNAME);
        ssl.setClientAuthEnabled(false);
        ssl.setSsl2Enabled(false);
        ssl.setSsl3Enabled(true);
        ssl.setTlsEnabled(true);
        ssl.setTlsRollbackEnabled(true);
        return ssl;
    
private booleanisEE()

        boolean isEE = false;
        final String eepffc = SystemPropertyConstants.CLUSTER_AWARE_FEATURE_FACTORY_CLASS;
        final String pn = PluggableFeatureFactory.PLUGGABLE_FEATURES_PROPERTY_NAME;
        final String pv = System.getProperty(pn);
        if (eepffc.equals(pv)) {
            isEE = true;
        }
        return ( isEE );
    
public voidonInitialization(com.sun.enterprise.server.ServerContext sc)

        try {
            initContext = sc;
            initConnectorConfig();
            handleIsEnabled(connectorConfig.getPort());
            handleSupportedProtocol();
            if (isEnabled) {
                driver = new JmxConnectorServerDriver();
                configureJmxConnectorServerDriver();
            }
        }
        catch(Exception e) {
            throw new ServerLifecycleException(e.getMessage(), e);
        }
    
public voidonReady(com.sun.enterprise.server.ServerContext sc)

    
public voidonShutdown()

        try {
            if (isEnabled) {
                driver.stopConnectorServer(cs);
                driver.stopConnectorServer(jconsolecs);
            }
            else {
                final String msg = "JmxConnectorLifeCycle.onShutdown: Connector Server not enabled at port: " + connectorConfig.getPort() + ", its shutdown is not required";
                sLogger.fine(msg);
            }
        }
        catch (final Exception e) {
            throw new ServerLifecycleException(e.getMessage());
        }
    
public voidonStartup(com.sun.enterprise.server.ServerContext sc)

        try {
            setupClientSide();
            if (isEnabled) {
                this.cs = driver.startConnectorServer();
                // start the connector server for third party jmx clients like
                // JConsole on a thread
                new Thread(
                    new Runnable() {
                        public void run() {
                            try {
                                jconsolecs = driver.startJconsoleConnectorServer();
                            } catch (IOException ex) {
                                sLogger.info("rjmx.connector_server.failed_startup");
                            }
                        }
                } ).start();
            }
            else {
                final String msg = "JmxConnectorLifeCycle.onStartup: Connector Server not enabled at port: " + connectorConfig.getPort();
                sLogger.fine(msg);
            }
        } catch (Exception e) {
            throw new ServerLifecycleException(e.getMessage(), e);
        }
    
public voidonTermination()

    
private voidsetupClientSide()
A method to set up the client side of the TLS connection. Here is the scenario: When the system jmx connector is set up with TLS enabled, all the other server instances need to have the RMIClientSocketFactory related environment. This method ensures that. Since this method is called when the server end is being brought up with the startup, it ensures that the setup happens early. This is also required in case of cascading where the server instances have the TLS setup on the jmx-connectors that are started in their life cycle. Even if the jmx connectors are not set up with TLS, it is okay to setup the client side.

        String serverName = System.getProperty(SystemPropertyConstants.SERVER_NAME);
        String certNickName = ServerHelper.getCertNickname(
            initContext.getConfigContext(), serverName);
        new ServerClientEnvSetter(certNickName).setup();