Package org.saf.application

Source Code of org.saf.application.AbstractApplicationController

package org.saf.application;

import org.apache.log4j.Logger;
import org.saf.shutdownhook.ShutdownHook;
import org.saf.shutdownhook.ShutdownHookListener;

public abstract class AbstractApplicationController implements
  ShutdownHookListener, ApplicationCheckerListener {
 
  protected static final Logger logger =
    Logger.getLogger(AbstractApplicationController.class)
 
  private final static String SHUTDOWN_HOOK_NAME = "shutdownHook";

  protected ShutdownHook shutdownHook = null;
 
  private Thread shutdownHookThread = null;
  private ApplicationChecker applicationChecker = null;
  private Thread applicationCheckerThread = null;

  public Priority getPriority() {
    return Priority.NORMAL;
 
 
  public void shutdownHookReceived() {
    logger.info("application controller shutdown process..");
    customStop();
  }
 
  public void start() {
    Runtime.getRuntime().addShutdownHook(this.shutdownHookThread);     
    this.applicationCheckerThread.start();
    customStart();
  }

  protected abstract void customStart();
 
  protected abstract void customStop();
   
  protected AbstractApplicationController() {
    init();
  }
 
  protected void forceStop() {
    System.exit(0);
  }
 
  private void init() {
    this.applicationChecker = new ApplicationChecker(this);
    this.applicationCheckerThread =
      new Thread(this.applicationChecker, "memory checker");
    this.shutdownHook = new ShutdownHook()
    this.shutdownHook.addShutdownHookListener(this);
    this.shutdownHook.addShutdownHookListener(this.applicationChecker);
    this.shutdownHookThread =
      new Thread(shutdownHook, SHUTDOWN_HOOK_NAME);
  }
 
}
TOP

Related Classes of org.saf.application.AbstractApplicationController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.