Example #1
0
  @Override
  public void onApplicationStop() {

    List<Class> jobs = Play.classloader.getAssignableClasses(Job.class);

    for (final Class clazz : jobs) {
      // @OnApplicationStop
      if (clazz.isAnnotationPresent(OnApplicationStop.class)) {
        try {
          Job<?> job = ((Job<?>) clazz.newInstance());
          scheduledJobs.add(job);
          job.run();
          if (job.wasError) {
            if (job.lastException != null) {
              throw job.lastException;
            }
            throw new RuntimeException("@OnApplicationStop Job has failed");
          }
        } catch (InstantiationException e) {
          throw new UnexpectedException("Job could not be instantiated", e);
        } catch (IllegalAccessException e) {
          throw new UnexpectedException("Job could not be instantiated", e);
        } catch (Throwable ex) {
          if (ex instanceof PlayException) {
            throw (PlayException) ex;
          }
          throw new UnexpectedException(ex);
        }
      }
    }

    executor.shutdownNow();
    executor.getQueue().clear();
  }
Example #2
0
  public void contextDestroyed(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();
    InitFacesContext initContext = null;
    try {
      initContext = new InitFacesContext(context);

      if (webAppListener != null) {
        webAppListener.contextDestroyed(sce);
        webAppListener = null;
      }
      if (webResourcePool != null) {
        webResourcePool.shutdownNow();
      }
      if (!ConfigManager.getInstance().hasBeenInitialized(context)) {
        return;
      }
      GroovyHelper helper = GroovyHelper.getCurrentInstance(context);
      if (helper != null) {
        helper.setClassLoader();
      }
      if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.log(
            Level.FINE, "ConfigureListener.contextDestroyed({0})", context.getServletContextName());
      }

      ELContext elctx = new ELContextImpl(initContext.getApplication().getELResolver());
      elctx.putContext(FacesContext.class, initContext);
      initContext.setELContext(elctx);
      Application app = initContext.getApplication();
      app.publishEvent(initContext, PreDestroyApplicationEvent.class, Application.class, app);

      Util.setNonFacesContextApplicationMap(null);

    } catch (Exception e) {
      if (LOGGER.isLoggable(Level.SEVERE)) {
        LOGGER.log(
            Level.SEVERE,
            "Unexpected exception when attempting to tear down the Mojarra runtime",
            e);
      }
    } finally {
      ApplicationAssociate.clearInstance(initContext.getExternalContext());
      ApplicationAssociate.setCurrentInstance(null);
      com.sun.faces.application.ApplicationImpl.clearInstance(initContext.getExternalContext());
      com.sun.faces.application.InjectionApplicationFactory.clearInstance(
          initContext.getExternalContext());
      // Release the initialization mark on this web application
      ConfigManager.getInstance().destory(context);
      if (initContext != null) {
        initContext.release();
      }
      ReflectionUtils.clearCache(Thread.currentThread().getContextClassLoader());
      WebConfiguration.clear(context);
    }
  }
  @AfterClass
  public static void finalization() {

    for (int i = 0; i < serverNumbers; i++) {
      logger.info("Stopping SMPP server " + i + " ...");
      serverArray[i].destroy();
      logger.info("SMPP server " + i + "stopped");
    }
    executor.shutdownNow();
    monitorExecutor.shutdownNow();
    balancer.stop();
    logger.info("Done. Exiting");
  }
Example #4
0
 public void shutdownNow() {
   estimatedTimeThread.running = false;
   estimatedTimeThread.interrupt();
   scheduler.shutdownNow();
   for (ExecutorHolder executor : executors.values()) {
     if (executor.executor instanceof ThreadPoolExecutor) {
       ((ThreadPoolExecutor) executor.executor).shutdownNow();
     }
   }
   while (!retiredExecutors.isEmpty()) {
     ((ThreadPoolExecutor) retiredExecutors.remove().executor).shutdownNow();
   }
 }
 @Override
 protected void serviceStop() throws Exception {
   if (sched != null) {
     sched.shutdown();
     boolean terminated = false;
     try {
       terminated = sched.awaitTermination(10, SECONDS);
     } catch (InterruptedException e) {
     }
     if (terminated != true) {
       sched.shutdownNow();
     }
   }
   super.serviceStop();
 }
Example #6
0
 /** Stops the SimpleTimer. Subsequent executions should not throw a RejectedExecutionException. */
 public void stop() {
   _executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
   _executor.shutdownNow();
 }
Example #7
0
 public void shutdown() {
   scheduledThreadPoolExecutor.shutdownNow();
 }
 @Override
 public void onApplicationStop() {
   executor.shutdownNow();
   executor.getQueue().clear();
 }
Example #9
0
 public static void shutdown() {
   schedThPoolExec.shutdownNow();
 }
Example #10
0
 // Implement finalizer.
 // This is just a small security to stop scheduled task if
 // instance is garbage collected.
 @Override
 protected void finalize() throws Throwable {
   super.finalize();
   stop();
   executor.shutdownNow();
 }