1 23 package com.sun.enterprise.management.support; 24 25 import java.util.Set ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.Map ; 29 import java.util.HashMap ; 30 import java.util.Collections ; 31 32 import javax.management.Notification ; 33 import javax.management.MBeanNotificationInfo ; 34 35 36 import com.sun.appserv.management.base.AMX; 37 import com.sun.appserv.management.base.NotificationEmitterService; 38 39 import com.sun.appserv.management.util.misc.GSetUtil; 40 import com.sun.appserv.management.util.jmx.JMXUtil; 41 42 43 44 52 public final class NotificationEmitterServiceImpl extends AMXImplBase 53 implements NotificationEmitterService 54 { 55 60 private final Map <String ,Set <String >> mEmittedTypes; 61 62 public 63 NotificationEmitterServiceImpl( ) 64 { 65 mEmittedTypes = Collections.synchronizedMap( new HashMap <String ,Set <String >>() ); 66 } 67 68 public String 69 getGroup() 70 { 71 return( AMX.GROUP_UTILITY ); 72 } 73 74 public boolean 75 getMBeanInfoIsInvariant() 76 { 77 return( false ); } 79 80 81 public MBeanNotificationInfo [] 82 getNotificationInfo() 83 { 84 final MBeanNotificationInfo [] superTypes = super.getNotificationInfo(); 85 86 final Set <MBeanNotificationInfo > dynamicInfos = 87 new HashSet <MBeanNotificationInfo >(); 88 89 93 for( final String notifClass : mEmittedTypes.keySet() ) 94 { 95 final Set <String > types = mEmittedTypes.get( notifClass ); 96 97 final MBeanNotificationInfo info = new MBeanNotificationInfo ( 98 GSetUtil.toStringArray( types ), notifClass, "" ); 99 100 dynamicInfos.add( info ); 101 } 102 103 final MBeanNotificationInfo [] dynamicInfosArray = (MBeanNotificationInfo []) 104 dynamicInfos.toArray( new MBeanNotificationInfo [ dynamicInfos.size() ] ); 105 106 108 final MBeanNotificationInfo [] allInfos = 109 JMXUtil.mergeMBeanNotificationInfos( superTypes, dynamicInfosArray ); 110 111 return allInfos; 112 } 113 114 115 136 private void 137 cumulateTypes( final Notification notif ) 138 { 139 final String notifClass = notif.getClass().getName(); 140 final String type = notif.getType(); 141 142 if ( ! mEmittedTypes.containsKey( notifClass ) ) 143 { 144 final Set <String > types = GSetUtil.newStringSet( type ); 145 mEmittedTypes.put( notifClass, types ); 146 } 147 else 148 { 149 final Set <String > types = mEmittedTypes.get( notifClass ); 150 if ( ! types.contains( type ) ) 151 { 152 types.add( type ); 153 } 154 } 155 } 156 157 163 public void 164 emitNotification( final Notification notif ) 165 { 166 cumulateTypes( notif ); 167 168 if ( getListenerCount() != 0 ) 169 { 170 sendNotification( notif ); 171 } 172 } 173 } 174 175 176 177 178 179 180 181 182 183 184 185 | Popular Tags |