public void init()

in core/src/main/java/flex/messaging/MessageBrokerServlet.java [79:176]


    public void init(ServletConfig servletConfig) throws ServletException {
        super.init(servletConfig);

        // allocate thread local variables
        createThreadLocals();

        // Set the servlet config as thread local
        FlexContext.setThreadLocalObjects(null, null, null, null, null, servletConfig);

        ServletLogTarget.setServletContext(servletConfig.getServletContext());

        ClassLoader loader = getClassLoader();

        if ("true".equals(servletConfig.getInitParameter("useContextClassLoader"))) {
            loader = Thread.currentThread().getContextClassLoader();
        }

        // Should we wrap http request for later error logging?
        log_errors = HTTPRequestLog.init(getServletContext());

        // Start the broker
        try {
            // Get the configuration manager
            ConfigurationManager configManager = loadMessagingConfiguration(servletConfig);

            // Load configuration
            MessagingConfiguration config = configManager.getMessagingConfiguration(servletConfig);

            // Set up logging system ahead of everything else.
            config.createLogAndTargets();

            // Create broker.
            broker = config.createBroker(servletConfig.getInitParameter("messageBrokerId"), loader);

            // Set the servlet config as thread local
            FlexContext.setThreadLocalObjects(null, null, broker, null, null, servletConfig);

            setupPathResolvers();

            // Set initial servlet context on broker
            broker.setServletContext(servletConfig.getServletContext());

            Logger logger = Log.getLogger(ConfigurationManager.LOG_CATEGORY);
            if (Log.isInfo()) {
                logger.info(VersionInfo.buildMessage());
            }

            // Create endpoints, services, security, and logger on the broker based on configuration
            config.configureBroker(broker);

            long timeBeforeStartup = 0;
            if (Log.isDebug()) {
                timeBeforeStartup = System.currentTimeMillis();
                Log.getLogger(LOG_CATEGORY_STARTUP_BROKER).debug("MessageBroker with id '{0}' is starting.",
                        new Object[]{broker.getId()});
            }

            //initialize the httpSessionToFlexSessionMap
            synchronized (HttpFlexSession.mapLock) {
                if (servletConfig.getServletContext().getAttribute(HttpFlexSession.SESSION_MAP) == null)
                    servletConfig.getServletContext().setAttribute(HttpFlexSession.SESSION_MAP, new ConcurrentHashMap());
            }

            broker.start();

            if (Log.isDebug()) {
                long timeAfterStartup = System.currentTimeMillis();
                Long diffMillis = timeAfterStartup - timeBeforeStartup;
                Log.getLogger(LOG_CATEGORY_STARTUP_BROKER).debug("MessageBroker with id '{0}' is ready (startup time: '{1}' ms)",
                        new Object[]{broker.getId(), diffMillis});
            }

            // Report replaced tokens
            configManager.reportTokens();

            // Report any unused properties.
            config.reportUnusedProperties();

            // Setup provider for FlexSessions that wrap underlying J2EE HttpSessions.
            httpFlexSessionProvider = new HttpFlexSessionProvider();
            broker.getFlexSessionManager().registerFlexSessionProvider(HttpFlexSession.class, httpFlexSessionProvider);

            // clear the broker and servlet config as this thread is done
            FlexContext.clearThreadLocalObjects();
        } catch (Throwable t) {
            // On any unhandled exception destroy the broker, log it and rethrow.
            String applicationName = servletConfig.getServletContext().getServletContextName();
            if (applicationName == null)
                applicationName = STRING_UNDEFINED_APPLICATION;

            System.err.println("**** MessageBrokerServlet in application '" + applicationName
                    + "' failed to initialize due to runtime exception: "
                    + ExceptionUtil.exceptionFollowedByRootCausesToString(t));
            destroy();
            // We used to throw  UnavailableException, but Weblogic didn't mark the webapp as failed. See bug FBR-237
            throw new ServletException(t);
        }
    }