View Javadoc

1   /***
2    *  Copyright 2003-2010 Terracotta, Inc.
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  
17  package net.sf.ehcache.util.counter.sampled;
18  
19  import net.sf.ehcache.util.counter.Counter;
20  
21  /***
22   * An implementation of {@link SampledCounterConfig}
23   * 
24   * @author <a href="mailto:asanoujam@terracottatech.com">Abhishek Sanoujam</a>
25   * @since 1.7
26   * 
27   */
28  public class SampledRateCounterConfig extends SampledCounterConfig {
29  
30      private final long initialNumeratorValue;
31      private final long initialDenominatorValue;
32  
33      /***
34       * Constructor accepting the interval time in seconds, history-size and
35       * whether counters should reset on each sample or not.
36       * Initial values of both numerator and denominator are zeroes
37       * 
38       * @param intervalSecs
39       * @param historySize
40       * @param isResetOnSample
41       */
42      public SampledRateCounterConfig(int intervalSecs, int historySize, boolean isResetOnSample) {
43          this(intervalSecs, historySize, isResetOnSample, 0, 0);
44      }
45  
46      /***
47       * Constructor accepting the interval time in seconds, history-size and
48       * whether counters should reset on each sample or not. Also the initial
49       * values for the numerator and the denominator
50       * 
51       * @param intervalSecs
52       * @param historySize
53       * @param isResetOnSample
54       * @param initialNumeratorValue
55       * @param initialDenominatorValue
56       */
57      public SampledRateCounterConfig(int intervalSecs, int historySize, boolean isResetOnSample, long initialNumeratorValue,
58              long initialDenominatorValue) {
59          super(intervalSecs, historySize, isResetOnSample, 0);
60          this.initialNumeratorValue = initialNumeratorValue;
61          this.initialDenominatorValue = initialDenominatorValue;
62      }
63  
64      /***
65       * {@inheritDoc}
66       */
67      @Override
68      public Counter createCounter() {
69          SampledRateCounterImpl sampledRateCounter = new SampledRateCounterImpl(this);
70          sampledRateCounter.setValue(initialNumeratorValue, initialDenominatorValue);
71          return sampledRateCounter;
72      }
73  
74  }