@Override
    public boolean notifySipContextListeners(SipContextEvent event) {
        boolean ok = true;
        if (logger.isDebugEnabled()) {
            logger.debug(this.deploymentInfoFacade.getSipServlets().size() + " container to notify of " + event.getEventType());
        }
        if (event.getEventType() == SipContextEventType.SERVLET_INITIALIZED) {
            //fixes https://github.com/RestComm/sip-servlets/issues/165
            //now the SipService is totally ready/started, we prepare 
            //the context again just in case some att was not properly
            //initiated
            try {
                prepareServletContext();
            } catch (Exception e) {
                logger.warn("Couldnt prepare context", e);
            }              
            if (!timerService.isStarted()) {
                timerService.start();
            }
            if (!proxyTimerService.isStarted()) {
                proxyTimerService.start();
            }
            if (!sasTimerService.isStarted()) {
                sasTimerService.start();
            }
        }

        // if(this.available) {
        enterSipApp(null, null, false, true);
        boolean batchStarted = enterSipAppHa(true);
        try {

            for (String servletName : this.deploymentInfoFacade.getSipServlets().keySet()) {
                SipServletImpl managedServlet = (SipServletImpl) this.getChildrenMap().get(servletName);
                if (logger.isDebugEnabled()) {
                    logger.debug("managedServlet " + managedServlet.getServletInfo().getName() + ", class : "
                            + managedServlet.getClass().getName());
                }
                try {
                    final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();

                    try {
                        final ClassLoader cl = this.getSipContextClassLoader();
                        Thread.currentThread().setContextClassLoader(cl);
                        // http://code.google.com/p/sipservlets/issues/detail?id=135
                        // kakonyii: in SipStandardContext, there was a threadBindingListener which handled thread context switches (to get proper jndi context namespace selector, etc),
                        // in wildfly we use threadSetupAction from the deployment object for that purpose:
                        bindThreadBindingListener();

                        Servlet sipServlet = managedServlet.getServlet().getInstance();
                        if (sipServlet instanceof SipServlet) {
                            // Fix for issue 1086 (http://code.google.com/p/mobicents/issues/detail?id=1086) :
                            // Cannot send a request in SipServletListener.initialize() for servlet-selection applications
                            boolean servletHandlerWasNull = false;
                            if (this.getServletHandler() == null) {
                                this.setServletHandler(managedServlet.getServletInfo().getName());
                                servletHandlerWasNull = true;
                            }

                            switch (event.getEventType()) {
                                case SERVLET_INITIALIZED: {
                                    SipServletContextEvent sipServletContextEvent = new SipServletContextEvent(
                                            getServletContext(), (SipServlet) sipServlet);
                                    List<SipServletListener> sipServletListeners = sipListeners.getSipServletsListeners();
                                    if (logger.isDebugEnabled()) {
                                        logger.debug(sipServletListeners.size()
                                                + " SipServletListener to notify of servlet initialization");
                                    }
                                    for (SipServletListener sipServletListener : sipServletListeners) {
                                        sipServletListener.servletInitialized(sipServletContextEvent);
                                    }
                                    break;
                                }
                                case SIP_CONNECTOR_ADDED: {
                                    // reload the outbound interfaces if they have changed
                                    this.getServletContext().setAttribute(javax.servlet.sip.SipServlet.OUTBOUND_INTERFACES,
                                            sipApplicationDispatcher.getOutboundInterfaces());
                                    // https://code.google.com/p/sipservlets/issues/detail?id=246
                                    this.getServletContext().setAttribute("org.mobicents.servlet.sip.SIP_CONNECTORS",
                                            sipApplicationDispatcher.getSipService().findSipConnectors());

                                    List<SipConnectorListener> sipConnectorListeners = sipListeners.getSipConnectorListeners();
                                    if (logger.isDebugEnabled()) {
                                        logger.debug(sipConnectorListeners.size()
                                                + " SipConnectorListener to notify of sip connector addition");
                                    }
                                    for (SipConnectorListener sipConnectorListener : sipConnectorListeners) {
                                        sipConnectorListener.sipConnectorAdded((SipConnector) event.getEventObject());
                                    }
                                    break;
                                }
                                case SIP_CONNECTOR_REMOVED: {
                                    // reload the outbound interfaces if they have changed
                                    this.getServletContext().setAttribute(javax.servlet.sip.SipServlet.OUTBOUND_INTERFACES,
                                            sipApplicationDispatcher.getOutboundInterfaces());
                                    // https://code.google.com/p/sipservlets/issues/detail?id=246
                                    this.getServletContext().setAttribute("org.mobicents.servlet.sip.SIP_CONNECTORS",
                                            sipApplicationDispatcher.getSipService().findSipConnectors());

                                    List<SipConnectorListener> sipConnectorListeners = sipListeners.getSipConnectorListeners();
                                    if (logger.isDebugEnabled()) {
                                        logger.debug(sipConnectorListeners.size()
                                                + " SipConnectorListener to notify of sip connector removal");
                                    }
                                    for (SipConnectorListener sipConnectorListener : sipConnectorListeners) {
                                        sipConnectorListener.sipConnectorRemoved((SipConnector) event.getEventObject());
                                    }
                                    break;
                                }
                            }
                            if (servletHandlerWasNull) {
                                this.setServletHandler("");
                            }
                        }
                    } finally {
                        // http://code.google.com/p/sipservlets/issues/detail?id=135
                        // kakonyii: in SipStandardContext, there was a threadBindingListener which handled thread context switches (to get proper jndi context namespace selector, etc),
                        // in wildfly we use threadSetupAction from the deployment object for that purpose:
                        unbindThreadBindingListener();
                        Thread.currentThread().setContextClassLoader(oldClassLoader);
                    }
                } catch (ServletException e) {
                    logger.error("Cannot allocate the servlet " + managedServlet.getClass() + " for notifying the listener "
                            + " of the event " + event.getEventType(), e);
                    ok = false;
                } catch (Throwable e) {
                    logger.error("An error occured when notifying the servlet " + managedServlet.getClass() + " of the event "
                            + event.getEventType(), e);
                    ok = false;
                }

                // FIXME: kakonyii: do we need this deallocation in wildfly?
                // try {
                // if(sipServlet != null) {
                // wrapper.deallocate(sipServlet);
                // }
                // } catch (ServletException e) {
                // logger.error("Deallocate exception for servlet" + wrapper.getName(), e);
                // ok = false;
                // } catch (Throwable e) {
                // logger.error("Deallocate exception for servlet" + wrapper.getName(), e);
                // ok = false;
                // }
            }
        } finally {
            exitSipAppHa(null, null, batchStarted);
            exitSipApp(null, null);
        }
        // }
        return ok;
    }
@ Override public boolean notifySipContextListeners ( SipContextEvent event ) { boolean ok = true ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( this . deploymentInfoFacade . getSipServlets ( ) . size ( ) + " container to notify of " + event . getEventType ( ) ) ; } if ( event . getEventType ( ) == SipContextEventType . SERVLET_INITIALIZED ) { try { prepareServletContext ( ) ; } catch ( Exception e ) { logger . warn ( "Couldnt prepare context" , e ) ; } if ( ! timerService . isStarted ( ) ) { timerService . start ( ) ; } if ( ! proxyTimerService . isStarted ( ) ) { proxyTimerService . start ( ) ; } if ( ! sasTimerService . isStarted ( ) ) { sasTimerService . start ( ) ; } } enterSipApp ( null , null , false , true ) ; boolean batchStarted = enterSipAppHa ( true ) ; try { for ( String servletName : this . deploymentInfoFacade . getSipServlets ( ) . keySet ( ) ) { SipServletImpl managedServlet = ( SipServletImpl ) this . getChildrenMap ( ) . get ( servletName ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "managedServlet " + managedServlet . getServletInfo ( ) . getName ( ) + ", class : " + managedServlet . getClass ( ) . getName ( ) ) ; } try { final ClassLoader oldClassLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; try { final ClassLoader cl = this . getSipContextClassLoader ( ) ; Thread . currentThread ( ) . setContextClassLoader ( cl ) ; bindThreadBindingListener ( ) ; Servlet sipServlet = managedServlet . getServlet ( ) . getInstance ( ) ; if ( sipServlet instanceof SipServlet ) { boolean servletHandlerWasNull = false ; if ( this . getServletHandler ( ) == null ) { this . setServletHandler ( managedServlet . getServletInfo ( ) . getName ( ) ) ; servletHandlerWasNull = true ; } switch ( event . getEventType ( ) ) { case SERVLET_INITIALIZED : { SipServletContextEvent sipServletContextEvent = new SipServletContextEvent ( getServletContext ( ) , ( SipServlet ) sipServlet ) ; List < SipServletListener > sipServletListeners = sipListeners . getSipServletsListeners ( ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( sipServletListeners . size ( ) + " SipServletListener to notify of servlet initialization" ) ; } for ( SipServletListener sipServletListener : sipServletListeners ) { sipServletListener . servletInitialized ( sipServletContextEvent ) ; } break ; } case SIP_CONNECTOR_ADDED : { this . getServletContext ( ) . setAttribute ( javax . servlet . sip . SipServlet . OUTBOUND_INTERFACES , sipApplicationDispatcher . getOutboundInterfaces ( ) ) ; this . getServletContext ( ) . setAttribute ( "org.mobicents.servlet.sip.SIP_CONNECTORS" , sipApplicationDispatcher . getSipService ( ) . findSipConnectors ( ) ) ; List < SipConnectorListener > sipConnectorListeners = sipListeners . getSipConnectorListeners ( ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( sipConnectorListeners . size ( ) + " SipConnectorListener to notify of sip connector addition" ) ; } for ( SipConnectorListener sipConnectorListener : sipConnectorListeners ) { sipConnectorListener . sipConnectorAdded ( ( SipConnector ) event . getEventObject ( ) ) ; } break ; } case SIP_CONNECTOR_REMOVED : { this . getServletContext ( ) . setAttribute ( javax . servlet . sip . SipServlet . OUTBOUND_INTERFACES , sipApplicationDispatcher . getOutboundInterfaces ( ) ) ; this . getServletContext ( ) . setAttribute ( "org.mobicents.servlet.sip.SIP_CONNECTORS" , sipApplicationDispatcher . getSipService ( ) . findSipConnectors ( ) ) ; List < SipConnectorListener > sipConnectorListeners = sipListeners . getSipConnectorListeners ( ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( sipConnectorListeners . size ( ) + " SipConnectorListener to notify of sip connector removal" ) ; } for ( SipConnectorListener sipConnectorListener : sipConnectorListeners ) { sipConnectorListener . sipConnectorRemoved ( ( SipConnector ) event . getEventObject ( ) ) ; } break ; } } if ( servletHandlerWasNull ) { this . setServletHandler ( "" ) ; } } } finally { unbindThreadBindingListener ( ) ; Thread . currentThread ( ) . setContextClassLoader ( oldClassLoader ) ; } } catch ( ServletException e ) { logger . error ( "Cannot allocate the servlet " + managedServlet . getClass ( ) + " for notifying the listener " + " of the event " + event . getEventType ( ) , e ) ; ok = false ; } catch ( Throwable e ) { logger . error ( "An error occured when notifying the servlet " + managedServlet . getClass ( ) + " of the event " + event . getEventType ( ) , e ) ; ok = false ; } } } finally { exitSipAppHa ( null , null , batchStarted ) ; exitSipApp ( null , null ) ; } return ok ; }
callers: SipApplicationDispatcher.addSipApplications()