예제 #1
0
/**
 * ShutdownHook implementation that stops the Logback context after a specified delay. The default
 * delay is 0 ms (zero).
 *
 * @author Mike Reinhold
 */
public class DelayingShutdownHook extends ShutdownHookBase {
  /** The default is no delay before shutdown. */
  public static final Duration DEFAULT_DELAY = Duration.buildByMilliseconds(0);

  /** The delay in milliseconds before the ShutdownHook stops the logback context */
  private Duration delay = DEFAULT_DELAY;

  public DelayingShutdownHook() {}

  public Duration getDelay() {
    return delay;
  }

  /**
   * The duration to wait before shutting down the current logback context.
   *
   * @param delay
   */
  public void setDelay(Duration delay) {
    this.delay = delay;
  }

  public void run() {
    try {
      Thread.sleep(delay.getMilliseconds());
    } catch (InterruptedException e) {
    }
    super.stop();
  }
}
예제 #2
0
 public void run() {
   try {
     Thread.sleep(delay.getMilliseconds());
   } catch (InterruptedException e) {
   }
   super.stop();
 }
예제 #3
0
 void processScanAttrib(InterpretationContext ic, Attributes attributes) {
   String scanAttrib = ic.subst(attributes.getValue(SCAN_ATTR));
   if (!OptionHelper.isEmpty(scanAttrib) && !"false".equalsIgnoreCase(scanAttrib)) {
     ReconfigureOnChangeFilter rocf = new ReconfigureOnChangeFilter();
     rocf.setContext(context);
     String scanPeriodAttrib = ic.subst(attributes.getValue(SCAN_PERIOD_ATTR));
     if (!OptionHelper.isEmpty(scanPeriodAttrib)) {
       try {
         Duration duration = Duration.valueOf(scanPeriodAttrib);
         rocf.setRefreshPeriod(duration.getMilliseconds());
         addInfo("Setting ReconfigureOnChangeFilter scanning period to " + duration);
       } catch (NumberFormatException nfe) {
         addError("Error while converting [" + scanAttrib + "] to long", nfe);
       }
     }
     rocf.start();
     LoggerContext lc = (LoggerContext) context;
     addInfo("Adding ReconfigureOnChangeFilter as a turbo filter");
     lc.addTurboFilter(rocf);
   }
 }