NotificationEmitterServiceImpl.javaAPI DocGlassfish v2 API6009Fri May 04 22:23:42 BST


public final class NotificationEmitterServiceImpl extends AMXImplBase implements
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
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( notif)
Cumulatively update our Map of Notification classes and the types corresponding to each class. A few of the standard ones are: => { AttributeChangeNotification.ATTRIBUTE_CHANGE } => { MBeanServerNotification.REGISTRATION_NOTIFICATION, MBeanServerNotification.UNREGISTRATION_NOTIFICATION } Various others are likely to be just generic 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 );
			final Set<String>	types	= mEmittedTypes.get( notifClass );
			if ( ! types.contains( type ) )
				types.add( type );
public voidemitNotification( 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

		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;