notify all registered ShutdownListener objects that the ServletContext is
being destroyed.
344794
public void shutdown() {
		for (ShutdownListener shutdownListener : shutdownListeners) {
			try {
				shutdownListener.shutdown();
			} catch(Exception e) {
				LOGGER.severe("failed shutdown"+e.getMessage());
			}
		}
	}
805102
public void shutdown() {
        if (zombie) {
            return;
        }
        logger.info("Shutting down Rythm Engine: [%s]", id());
        if (null != _cacheService) {
            try {
                _cacheService.shutdown();
            } catch (Exception e) {
                logger.error(e, "Error shutdown cache service");
            }
        }
        if (null != _secureExecutor) {
            try {
                _secureExecutor.shutdown();
            } catch (Exception e) {
                logger.error(e, "Error shutdown secure executor");
            }
        }
        if (null != _resourceManager) {
            try {
                _resourceManager.shutdown();
            } catch (Exception e) {
                logger.error(e, "Error shutdown resource manager");
            }
        }
        if (null != shutdownListener) {
            try {
                shutdownListener.onShutdown();
            } catch (Exception e) {
                logger.error(e, "Error execute shutdown listener");
            }
        }
        if (null != nonExistsTemplatesChecker) {
            nonExistsTemplatesChecker.onShutdown();
        }
        if (null != _templates) _templates.clear();
        if (null != _classes) _classes.clear();
        if (null != _nonExistsTags) _nonExistsTags.clear();
        if (null != nonExistsTemplates) nonExistsTemplates.clear();
        if (null != _nonTmpls) _nonTmpls.clear();
        _classLoader = null;
        Rythm.RenderTime.clear();
        zombie = true;
    }
1305700
protected void didShutdown ()
    {
        // clear out our listenership
        _plobj.removeListener(this);
        _plobj.removeListener(_bodyUpdater);
        _plobj.removeListener(_occListener);
        _plobj.removeListener(_deathListener);

        // clear out our invocation service registrations
        for (InvocationMarshaller<?> marsh : _marshallers) {
            _invmgr.clearDispatcher(marsh);
        }

        // let our delegates know that we've shut down
        applyToDelegates(new DelegateOp(PlaceManagerDelegate.class) {
            @Override
            public void apply (PlaceManagerDelegate delegate) {
                delegate.didShutdown();
            }
        });

        // if shutting down emptied the place and scheduled the shutdowner, clear that out
        cancelShutdowner();
    }
1058059
def on_session_destroyed(self, *callbacks):
        ''' 

        '''
        for callback in callbacks:
            _check_callback(callback, ('session_context',))
            self._session_destroyed_callbacks.add(callback)
1347063
@Override
    public void registerDestructionCallback(String name, Runnable callback) {
        final HttpSession session = this.getPortalSesion(true);
        final DestructionCallbackBindingListener callbackListener =
                new DestructionCallbackBindingListener(callback);
        session.setAttribute(DESTRUCTION_CALLBACK_NAME_PREFIX + name, callbackListener);
    }
88321
@Override
    public void shutdown() {
        Throwable shutdownException = null;
        try {
            fire(new ManagerStopping());
        } catch (Exception e) {
            try {
                fireException(e);
            } catch (Exception e2) {
                shutdownException = e2;
            }
        }
        synchronized (this) {
            for (Context context : contexts) {
                context.clearAll();
            }
            contexts.clear();
            extensions.clear();

            runtimeLogger.clear();

            handledThrowables.remove();
        }
        if (shutdownException != null) {
            UncheckedThrow.throwUnchecked(shutdownException);
        }
    }
119329
protected synchronized void handleCompleted() {
        latch.countDown();
        for (final ShutdownListener listener : listeners) {
            listener.handleCompleted();
        }
        listeners.clear();
    }
26918
public void addShutdownListener(final ShutdownListener shutdownListener) {
        synchronized (lock) {
            if (!shutdown) {
                throw UndertowMessages.MESSAGES.handlerNotShutdown();
            }
            long count = activeRequestsUpdater.get(this);
            if (count == 0) {
                shutdownListener.shutdown(true);
            } else {
                shutdownListeners.add(shutdownListener);
            }
        }
    }
28952
@OnDestroy
  public void onShutdown()
  {
    _lifecycle.toDestroy();

    ArrayList<TimerListener> listeners = new ArrayList<>(_timerMap.values());

    _timerMap.clear();

    for (TimerListener listener : listeners) {
      listener.close();
    }
  }
570137
public void shutdown(ShutdownModeAmp mode)
  {
    Thread thread = Thread.currentThread();
    ClassLoader oldLoader = thread.getContextClassLoader();

    try {
      thread.setContextClassLoader(classLoader());

      if (! _lifecycle.toStopping()) {
        return;
      }
      
      //_httpCache.close();

      try {
        shutdownImpl(mode);
      } catch (Throwable e) {
        log.log(Level.WARNING, e.toString(), e);
      }

      _lifecycle.toDestroy();
    } finally {
      thread.setContextClassLoader(oldLoader);
    }
  }
1259886
void notifyListenersNetworkUneachable() {
        // NOTE: synchronized(listener) causes deadlock with listeners and Replicator.lock.
        final Set<NetworkReachabilityListener> copy = new HashSet<>(listeners);
        for (NetworkReachabilityListener listener : copy) {
            if (listener != null) { listener.networkUnreachable(); }
        }
    }
898776
protected void destroyAndRemoveConnectionListener(ConnectionListener cl, Collection<ConnectionListener> listeners)
   {
      try
      {
         pool.destroyConnectionListener(cl);
      }
      catch (ResourceException e)
      {
         // TODO:
         cl.setState(ZOMBIE);
      }
      finally
      {
         listeners.remove(cl);
      }
   }
445715
private void notifyBroadcastClose() {
        final IStreamAwareScopeHandler handler = getStreamAwareHandler();
        if (handler != null) {
            try {
                handler.streamBroadcastClose(this);
            } catch (Throwable t) {
                log.error("Error in notifyBroadcastClose", t);
            }
        }
    }
347294
@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;
    }
213568
public void destroyOnShutdownHook()
    {
        Runtime.getRuntime().addShutdownHook(new Thread()
        {
            @Override
            public void run()
            {
                try {
                    LifeCycleManager.this.destroy();
                }
                catch (Exception e) {
                    System.err.print("Exception in life cycle shutdown handler ");
                    e.printStackTrace(System.err);
                }
            }
        });
    }
481068
protected void destroyEurekaServerContext() throws Exception {
		EurekaMonitors.shutdown();
		if (this.awsBinder != null) {
			this.awsBinder.shutdown();
		}
		if (this.serverContext != null) {
			this.serverContext.shutdown();
		}
	}
1337506
public void prepareForShutdown() {
        Collection<CompletableFuture<Void>> prepareShutdownFutures = shutdownListeners.stream()
                                                                                      .map(shutdownListener -> CompletableFuture.runAsync(() -> shutdownListener.prepareForShutdown()))
                                                                                      .collect(Collectors.toList());
        try {
            CompletableFuture.allOf(prepareShutdownFutures.toArray(new CompletableFuture[prepareShutdownFutures.size()]))
                             .get(prepareForShutdownTimeoutSec, TimeUnit.SECONDS);
        } catch (Exception e) {
            logger.error("Exception occurred while preparing shutdown.", e);
        }
    }