1 4 package com.tc.stats; 5 6 import EDU.oswego.cs.dl.util.concurrent.SynchronizedLong; 7 8 import com.tc.stats.statistics.Statistic; 9 10 import java.io.Serializable ; 11 import java.util.HashMap ; 12 import java.util.Map ; 13 14 import javax.management.AttributeChangeNotification ; 15 import javax.management.MBeanNotificationInfo ; 16 import javax.management.NotificationBroadcasterSupport ; 17 18 public class StatsSupport extends NotificationBroadcasterSupport implements Serializable { 19 private final Map m_stats = new HashMap (); 20 private final SynchronizedLong sequenceNumber = new SynchronizedLong(0L); 21 22 public synchronized void addStatistic(String id, Statistic statistic) { 23 m_stats.put(id, statistic); 24 } 25 26 public synchronized Statistic getStatistic(String id) { 27 return (Statistic) m_stats.get(id); 28 } 29 30 public synchronized String [] getStatisticNames() { 31 return (String []) m_stats.keySet().toArray(new String [m_stats.size()]); 32 } 33 34 public synchronized Statistic[] getStatistics() { 35 return (Statistic[]) m_stats.values().toArray(new Statistic[m_stats.size()]); 36 } 37 38 public MBeanNotificationInfo [] getNotificationInfo() { 39 String [] types = new String [] { AttributeChangeNotification.ATTRIBUTE_CHANGE }; 40 String name = AttributeChangeNotification .class.getName(); 41 String description = "An attribute of this MBean has changed"; 42 43 return new MBeanNotificationInfo [] { new MBeanNotificationInfo (types, name, description) }; 44 } 45 46 protected void sendNotification(String msg, String attr, String type, Object oldVal, Object newVal) { 47 sendNotification(new AttributeChangeNotification (this, sequenceNumber.increment(), System.currentTimeMillis(), msg, 48 attr, type, oldVal, newVal)); 49 } 50 } 51 | Popular Tags |