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

NotificationServiceImpl

public final class NotificationServiceImpl extends AMXImplBase implements NotificationEmitter, NotificationListener

Fields Summary
private Map
mListenees
private final Object
mUserData
private final Map
mIncludePatterns
private final Map
mExcludePatterns
private final Map
mBuffers
private final String[]
NOTIF_TYPES
private static int
sBufferID
Constructors Summary
public NotificationServiceImpl(Object userData, int bufferSize)

		if ( userData == null || !(userData instanceof Serializable) )
		{
			throw new IllegalArgumentException();
		}
		
		mUserData	= userData;

		mListenees		= Collections.synchronizedMap( new HashMap<ObjectName,NotificationFilter>() );
		
		mBuffers		= Collections.synchronizedMap( new HashMap<Object,NotificationBuffer>() );
		
		mIncludePatterns	= new HashMap<ObjectName,NotificationFilter>();
		mExcludePatterns	= new HashMap<ObjectName,NotificationFilter>();
	
Methods Summary
private javax.management.NotificationFilter_getFilter(javax.management.ObjectName objectName)

		final NotificationFilter filter	=
			(NotificationFilter)mListenees.get( objectName );
		
		return( filter );
	
private voidcheckListeningTo(javax.management.ObjectName objectName)

		if ( ! mListenees.containsKey( objectName ) )
		{
			throw new IllegalArgumentException( objectName.toString() );
		}
	
public java.lang.ObjectcreateBuffer(int bufferSize, javax.management.NotificationFilter filter)

		 
	
		 					
		 	 
	
		final OverflowHandler	handler	= new OverflowHandlerImpl();
		
		final NotificationBuffer	buffer	=
			new NotificationBuffer( bufferSize, filter, handler );
		
		Object	id	= null;
		
		synchronized( mBuffers )
		{
			++sBufferID;
			id	= "" + sBufferID;
			
			mBuffers.put( id, buffer );
		}
		
		return( id );
	
public voiddontListenTo(javax.management.ObjectName pattern)

		mIncludePatterns.remove( pattern );
		
		final Set<ObjectName>	listenees	= getMatchingObjectNames( pattern );
		
		final MBeanServer	server	= getMBeanServer();
		for( final ObjectName objectName : listenees )
		{
			try
			{
				server.removeNotificationListener( objectName, this );
				mListenees.remove( objectName );
			}
			catch( ListenerNotFoundException e )
			{
			}
			catch( InstanceNotFoundException e )
			{
			}
		}
	
private NotificationBuffergetBuffer(java.lang.Object bufferID)

		return( (NotificationBuffer)mBuffers.get( bufferID ) );
	
public java.util.MapgetBufferNotifications(java.lang.Object bufferID, long sequenceNumberIn)

		final NotificationBuffer	buffer	= getBuffer( bufferID );
		
		return( buffer.getNotifications( sequenceNumberIn ) );
	
public javax.management.NotificationFiltergetFilter(javax.management.ObjectName objectName)

		checkListeningTo( objectName );
		
		return( _getFilter( objectName ) );
	
public java.lang.StringgetGroup()

		return( AMX.GROUP_UTILITY );
	
public java.util.SetgetListeneeObjectNameSet()

		final Set<ObjectName>	objectNames	= new HashSet<ObjectName>();
		
		synchronized( mListenees )
		{
			objectNames.addAll( mListenees.keySet() );
		}
		
		return( objectNames );
	
protected java.util.SetgetMatchingObjectNames(javax.management.ObjectName pattern)

		Set<ObjectName>	s	= null;
		
		if ( pattern.isPattern() )
		{
			s	= JMXUtil.queryNames( getMBeanServer(), pattern, null );
		}
		else
		{
			s	= GSetUtil.newSingletonSet( pattern );
		}
		
		return( s );
	
public javax.management.MBeanNotificationInfo[]getNotificationInfo()

	
		 
	
	
		final MBeanNotificationInfo	info	= new MBeanNotificationInfo(
			NOTIF_TYPES,
			Notification.class.getName(),
			"" );
		final MBeanNotificationInfo[]	selfInfos	= new MBeanNotificationInfo[] { info };
		
		return( JMXUtil.mergeMBeanNotificationInfos( super.getNotificationInfo(), selfInfos ) );
	
public final java.lang.ObjectgetUserData()

		return( mUserData );
	
public voidhandleNotification(javax.management.Notification notif, java.lang.Object handback)

		synchronized( mBuffers )
		{
			for( final Object id : mBuffers.keySet() )
			{
				getBuffer( id ).bufferNotification( notif );
			}
		}
		
		// let all listeners know...
		sendNotification( notif );
	
protected voidissueBufferOverflowNotification(javax.management.Notification oldNotif)

		if ( shouldEmitNotifications() )
		{
			sendNotification( NotificationService.BUFFER_OVERFLOW_NOTIFICATION_TYPE,
					NotificationService.OVERFLOWED_NOTIFICATION_KEY,
					oldNotif );
		}
	
public voidlistenTo(javax.management.ObjectName pattern, javax.management.NotificationFilter filter)

		mIncludePatterns.put( pattern, filter );
		
		final Set<ObjectName>	listenees	= getMatchingObjectNames( pattern );
		
		final MBeanServer	server	= getMBeanServer();
		for( final ObjectName objectName : listenees )
		{
			if ( objectName.equals( getObjectName() ) )
			{
				continue;
			}
			
			listenToSingle( objectName, filter );
		}
	
protected voidlistenToIfMatch(javax.management.ObjectName objectName)

		if ( ! mListenees.keySet().contains( objectName ) )
		{
			final String	defaultDomain	= getMBeanServer().getDefaultDomain();
			
			for( final ObjectName pattern : mIncludePatterns.keySet() )
			{
				if ( JMXUtil.matchesPattern( defaultDomain, pattern, objectName ) )
				{
					final NotificationFilter	filter	=
						(NotificationFilter)mIncludePatterns.get( pattern );
				
					listenToSingle( objectName, filter );
				}
			}
		}
	
protected voidlistenToSingle(javax.management.ObjectName objectName, javax.management.NotificationFilter filter)

		mListenees.put( objectName, filter );
		try
		{
			getMBeanServer().addNotificationListener( objectName, this, filter, null );
		}
		catch( Exception e )
		{
			mListenees.remove( objectName );
		}
	
public voidpreDeregisterHook()

		super.preDeregisterHook();
		
		synchronized( mListenees )
		{
			final Set<ObjectName> s	= getListeneeObjectNameSet();
			
			final ObjectName[]	objectNames	= new ObjectName[ s.size() ];
			s.toArray( objectNames );
			
			for( int i = 0; i < objectNames.length; ++i )
			{
				dontListenTo( objectNames[ i ] );
			}
		}
		
		synchronized( mBuffers )
		{
			for( final NotificationBuffer buffer : mBuffers.values() )
			{
				removeBuffer( buffer );
			}
		}
	
protected voidpreRegisterDone()

		super.preRegisterDone();
		
		// it's crucial we listen for registration/unregistration events
		// so that any patterns are maintained.
		JMXUtil.listenToMBeanServerDelegate( getMBeanServer(),
			new RegistrationListener(), null, null );
	
public voidremoveBuffer(java.lang.Object bufferID)

		final NotificationBuffer	buffer	=
			(NotificationBuffer)mBuffers.remove( bufferID );