View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.util;
15  
16  /**
17   * A default {@link DelayStrategy} that implements a simple fixed delay.
18   *
19   * @author Carl Harris
20   * @since 1.1.0
21   */
22  public class FixedDelay implements DelayStrategy {
23  
24      private final long subsequentDelay;
25      private long nextDelay;
26  
27      /**
28       * Initialize a new {@code FixedDelay} with a given {@code initialDelay} and
29       * {@code subsequentDelay}.
30       *
31       * @param initialDelay    value for the initial delay
32       * @param subsequentDelay value for all other delays
33       */
34      public FixedDelay(long initialDelay, long subsequentDelay) {
35          this.nextDelay = initialDelay;
36          this.subsequentDelay = subsequentDelay;
37      }
38  
39      /**
40       * Initialize a new {@code FixedDelay} with fixed delay value given by
41       * {@code delay} parameter.
42       *
43       * @param delay value for all delays
44       */
45      public FixedDelay(int delay) {
46          this(delay, delay);
47      }
48  
49      /**
50       * {@inheritDoc}
51       */
52      public long nextDelay() {
53          long delay = nextDelay;
54          nextDelay = subsequentDelay;
55          return delay;
56      }
57  
58  }