FileDocCategorySizeDatePackage
NotificationEmitterServiceImpl.javaAPI DocGlassfish v2 API6009Fri May 04 22:23:42 BST 2007com.sun.enterprise.management.support

NotificationEmitterServiceImpl

public final class NotificationEmitterServiceImpl extends AMXImplBase implements com.sun.appserv.management.base.NotificationEmitterService
A key aspect of the implementation is that it maintains a list of all types of Notifications it has seen emitted, paired with the implementing class so that getNotificationInfo() can return infos that accurately reflect what it is likely to emit. This approach is used instead of statically coding Notification classes/types because it cannot be known in advance which type(s) will actually be emitted.

Fields Summary
private final Map
mEmittedTypes
Each class of Notification may have one or more types associated with it, stored in a Set<String>:
Map<notif classname, Set<String of notif type>>
Constructors Summary
public NotificationEmitterServiceImpl()

		mEmittedTypes	= Collections.synchronizedMap( new HashMap<String,Set<String>>() );
	
Methods Summary
private voidcumulateTypes(javax.management.Notification notif)
Cumulatively update our Map of Notification classes and the types corresponding to each class. A few of the standard ones are: javax.management.AttributeChangeNotification => { AttributeChangeNotification.ATTRIBUTE_CHANGE } javax.management.MBeanServerNotification => { MBeanServerNotification.REGISTRATION_NOTIFICATION, MBeanServerNotification.UNREGISTRATION_NOTIFICATION } Various others are likely to be just generic Notification: javax.management.Notification => { x.y.z, a.b.c, ... }

		final String notifClass	= notif.getClass().getName();
		final String type		= notif.getType();
		
		if ( ! mEmittedTypes.containsKey( notifClass ) )
		{
			final Set<String>	types	= GSetUtil.newStringSet( type );
			mEmittedTypes.put( notifClass, types );
		}
		else
		{
			final Set<String>	types	= mEmittedTypes.get( notifClass );
			if ( ! types.contains( type ) )
			{
				types.add( type );
			}
		}
	
public voidemitNotification(javax.management.Notification notif)
Note that this method may be used to test the functionality of this service by asking it to emit any desired Notification.

Note that this method is likely to be called from many different threads.

		cumulateTypes( notif );
		
		if ( getListenerCount() != 0 )
		{
			sendNotification( notif );
		}
	
public java.lang.StringgetGroup()

		return( AMX.GROUP_UTILITY );
	
public booleangetMBeanInfoIsInvariant()

		return( false );	// MBeanNotificationInfo may grow as we learn of new types
	
public javax.management.MBeanNotificationInfo[]getNotificationInfo()

		final MBeanNotificationInfo[]	superTypes	= super.getNotificationInfo();
		
		final Set<MBeanNotificationInfo>	dynamicInfos	=
		    new HashSet<MBeanNotificationInfo>();
		
		/*
			Go through our list of class/types we've seen emitted so far
			and generate MBeanNotificationInfo for each class of Notification
		 */
		for( final String notifClass : mEmittedTypes.keySet() )
		{
			final Set<String>	types		= mEmittedTypes.get( notifClass );
				
			final MBeanNotificationInfo	info	= new MBeanNotificationInfo(
				GSetUtil.toStringArray( types ), notifClass, "" );
			
			dynamicInfos.add( info );
		}
		
		final MBeanNotificationInfo[]	dynamicInfosArray	= (MBeanNotificationInfo[])
			dynamicInfos.toArray( new MBeanNotificationInfo[ dynamicInfos.size() ] );
		
		// now merge what we've found with super's types
		
		final MBeanNotificationInfo[]	allInfos	=
			JMXUtil.mergeMBeanNotificationInfos( superTypes, dynamicInfosArray );
		
		return allInfos;