Exemplo n.º 1
0
 @OverrideOnDemand
 @OverridingMethodsMustInvokeSuper
 protected void initPaths(@Nonnull final ServletContext aSC) {
   // Get the ServletContext base path
   final String sServletContextPath = getServletContextPath(aSC);
   // Get the data path
   final String sDataPath = getDataPath(aSC);
   if (StringHelper.hasNoText(sDataPath))
     throw new InitializationException("No data path was provided!");
   final File aDataPath = new File(sDataPath).getAbsoluteFile();
   // Should the file access check be performed?
   final boolean bFileAccessCheck = shouldCheckFileAccess(aSC);
   // Init the IO layer
   WebFileIO.initPaths(aDataPath, new File(sServletContextPath), bFileAccessCheck);
 }
Exemplo n.º 2
0
 /**
  * Handle all statistics AFTER the context was shut down. Depending on {@link
  * #isHandleStatisticsOnEnd()} this method is called or not.
  */
 @OverrideOnDemand
 protected void handleStatisticsOnEnd() {
   // serialize statistics
   try {
     final File aDestPath = WebFileIO.getDataIO().getFile(getStatisticsFilename());
     final IMicroDocument aDoc = StatisticsExporter.getAsXMLDocument();
     aDoc.getDocumentElement().setAttribute("location", "shutdown");
     aDoc.getDocumentElement()
         .setAttribute(
             "datetime", PDTWebDateHelper.getAsStringXSD(PDTFactory.getCurrentDateTime()));
     SimpleFileIO.writeFile(
         aDestPath, MicroWriter.getXMLString(aDoc), XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ);
   } catch (final Throwable t) {
     s_aLogger.error("Failed to write statistics on context shutdown.", t);
   }
 }
Exemplo n.º 3
0
  public final void contextDestroyed(@Nonnull final ServletContextEvent aSCE) {
    final ServletContext aSC = aSCE.getServletContext();

    final StopWatch aSW = StopWatch.createdStarted();
    if (s_aLogger.isInfoEnabled())
      s_aLogger.info("Servlet context '" + aSC.getServletContextName() + "' is being destroyed");

    // Callback before global scope end
    beforeContextDestroyed(aSC);

    // Shutdown global scope and destroy all singletons
    WebScopeManager.onGlobalEnd();

    // Callback after global scope end
    afterContextDestroyed(aSC);

    // Handle statistics
    if (isHandleStatisticsOnEnd()) handleStatisticsOnEnd();

    // Reset base path - mainly for testing
    WebFileIO.resetPaths();

    // Clear commons cache also manually - but after destroy because it
    // is used in equals and hashCode implementations
    CommonsCleanup.cleanup();

    // De-init
    s_aInited.set(false);

    if (s_aLogger.isInfoEnabled())
      s_aLogger.info(
          "Servlet context '"
              + aSC.getServletContextName()
              + "' was destroyed in "
              + aSW.stopAndGetMillis()
              + " milli seconds");
  }