1 4 package com.tc.object.net; 5 6 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 7 8 import com.tc.net.protocol.tcm.ChannelID; 9 import com.tc.net.protocol.tcm.MessageChannel; 10 import com.tc.stats.counter.Counter; 11 import com.tc.stats.counter.sampled.SampledCounterConfig; 12 import com.tc.stats.counter.sampled.SampledCounterManager; 13 14 import java.util.Map ; 15 16 20 public class ChannelStatsImpl implements ChannelStats { 21 22 private static final String DSO_STATS_MAP = "dso_stats_map"; 23 private static final SampledCounterConfig DEFAULT_CONFIG = new SampledCounterConfig(1, 300, true, 0L); 24 25 private final SampledCounterManager counterManager; 26 private final DSOChannelManager channelManager; 27 28 public ChannelStatsImpl(SampledCounterManager counterManager, DSOChannelManager channelManager) { 29 this.counterManager = counterManager; 30 this.channelManager = channelManager; 31 } 32 33 public Counter getCounter(MessageChannel channel, String name) { 34 return getCounter(getStatsMap(channel), name); 35 } 36 37 private Counter getCounter(Map statsMap, String name) { 38 Counter rv = (Counter) statsMap.get(name); 39 if (rv != null) return rv; 40 41 synchronized (statsMap) { 42 if (statsMap.containsKey(name)) { return (Counter) statsMap.get(name); } 43 44 rv = counterManager.createCounter(DEFAULT_CONFIG); 49 statsMap.put(name, rv); 50 return rv; 51 } 52 53 } 54 55 private static Map getStatsMap(MessageChannel channel) { 56 Map rv = (Map) channel.getAttachment(DSO_STATS_MAP); 57 if (rv != null) { return rv; } 58 channel.addAttachment(DSO_STATS_MAP, new ConcurrentReaderHashMap(), false); 59 return (Map) channel.getAttachment(DSO_STATS_MAP); 60 } 61 62 public void notifyTransaction(ChannelID channelID) { 63 try { 64 MessageChannel channel = channelManager.getActiveChannel(channelID); 65 getCounter(channel, TXN_RATE).increment(); 66 } catch (NoSuchChannelException e) { 67 } 69 } 70 71 } 72 | Popular Tags |