KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > stats > counter > sampled > SampledCounterManagerImpl


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.stats.counter.sampled;
5
6 import com.tc.util.TCTimerImpl;
7
8 import java.util.Timer JavaDoc;
9
10 public class SampledCounterManagerImpl implements SampledCounterManager {
11   private final Timer JavaDoc timer = new TCTimerImpl("SampledCounterManager Timer", true);
12   private boolean shutdown = false;
13
14   public SampledCounterManagerImpl() {
15     super();
16   }
17
18   public synchronized void shutdown() {
19     if (shutdown) { return; }
20     try {
21       timer.cancel();
22     } finally {
23       shutdown = true;
24     }
25   }
26
27   public synchronized SampledCounter createCounter(SampledCounterConfig config) {
28     if (shutdown) { throw new IllegalStateException JavaDoc("counter manager is shutdown"); }
29     if (config == null) { throw new NullPointerException JavaDoc("config cannot be null"); }
30
31     final SampledCounterImpl counter = new SampledCounterImpl(config);
32
33     final long period = config.getIntervalSecs() * 1000;
34     timer.schedule(counter.getTimerTask(), period, period);
35
36     return counter;
37   }
38
39 }
40
Popular Tags