@Override
    public void contextInitialized(ServletContextEvent event) {
        final ServletContext servletContext = event.getServletContext();

        // Create the bean
        this.javaManagementServerBean = new JavaManagementServerBean();

        // Get the failOnException option
        final String failOnExceptionStr = servletContext.getInitParameter(FAIL_ON_EXCEPTION);
        boolean failOnException = Boolean.parseBoolean(failOnExceptionStr);
        this.javaManagementServerBean.setFailOnException(failOnException);

        final String host = servletContext.getInitParameter(JMX_RMI_HOST);
        this.javaManagementServerBean.setHost(host);

        // Get the base rmi port from the init parameters
        final String portOneStr = servletContext.getInitParameter(JMX_RMI_PORT_1);
        try {
            final int portOne = Integer.parseInt(portOneStr);
            this.javaManagementServerBean.setPortOne(portOne);
        } catch (NumberFormatException nfe) {
            getLogger()
                    .warn(
                            "init-parameter '"
                                    + JMX_RMI_PORT_1
                                    + "' is required and must contain a number. '"
                                    + portOneStr
                                    + "' is not a valid number.",
                            nfe);
        }

        // Get the second rmi port from the init parameters
        final String portTwoStr = servletContext.getInitParameter(JMX_RMI_PORT_2);
        try {
            final int portTwo = Integer.parseInt(portTwoStr);
            this.javaManagementServerBean.setPortTwo(portTwo);
        } catch (NumberFormatException nfe) {
            getLogger()
                    .debug(
                            "Failed to convert init-parameter '"
                                    + JMX_RMI_PORT_2
                                    + "' with value '"
                                    + portTwoStr
                                    + "' to a number, defaulting portTwo to portOne + 1",
                            nfe);
        }

        this.javaManagementServerBean.startServer();
    }
@ Override public void contextInitialized ( ServletContextEvent event ) { final ServletContext servletContext = event . getServletContext ( ) ; this . javaManagementServerBean = new JavaManagementServerBean ( ) ; final String failOnExceptionStr = servletContext . getInitParameter ( FAIL_ON_EXCEPTION ) ; boolean failOnException = Boolean . parseBoolean ( failOnExceptionStr ) ; this . javaManagementServerBean . setFailOnException ( failOnException ) ; final String host = servletContext . getInitParameter ( JMX_RMI_HOST ) ; this . javaManagementServerBean . setHost ( host ) ; final String portOneStr = servletContext . getInitParameter ( JMX_RMI_PORT_1 ) ; try { final int portOne = Integer . parseInt ( portOneStr ) ; this . javaManagementServerBean . setPortOne ( portOne ) ; } catch ( NumberFormatException nfe ) { getLogger ( ) . warn ( "init-parameter '" + JMX_RMI_PORT_1 + "' is required and must contain a number. '" + portOneStr + "' is not a valid number." , nfe ) ; } final String portTwoStr = servletContext . getInitParameter ( JMX_RMI_PORT_2 ) ; try { final int portTwo = Integer . parseInt ( portTwoStr ) ; this . javaManagementServerBean . setPortTwo ( portTwo ) ; } catch ( NumberFormatException nfe ) { getLogger ( ) . debug ( "Failed to convert init-parameter '" + JMX_RMI_PORT_2 + "' with value '" + portTwoStr + "' to a number, defaulting portTwo to portOne + 1" , nfe ) ; } this . javaManagementServerBean . startServer ( ) ; }
@see
javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)