1 4 package com.tc.stats.counter.sampled; 5 6 import com.tc.util.TCTimerImpl; 7 8 import java.util.Timer ; 9 10 public class SampledCounterManagerImpl implements SampledCounterManager { 11 private final Timer 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 ("counter manager is shutdown"); } 29 if (config == null) { throw new NullPointerException ("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 |