FileDocCategorySizeDatePackage
CreateRemoveListener.javaAPI DocGlassfish v2 API4858Fri May 04 22:23:50 BST 2007com.sun.enterprise.management

CreateRemoveListener

public final class CreateRemoveListener extends Object implements NotificationListener
A NotificationListener which expects to receive a CONFIG_CREATED_NOTIFICATION_TYPE and CONFIG_REMOVED_NOTIFICATION_TYPE from an MBean with a particular j2eeType and name.

Fields Summary
private final String
mNameExpected
private final String
mJ2EETypeExpected
private final com.sun.appserv.management.base.Container
mSource
private Notification
mCreateNotif
private Notification
mRemoveNotif
Constructors Summary
public CreateRemoveListener(com.sun.appserv.management.base.Container source, String j2eeTypeExpected, String nameExpected)

		mSource				= source;
		mNameExpected		= nameExpected;
		mJ2EETypeExpected	= j2eeTypeExpected;
		
		mSource.addNotificationListener( this, null, null );
	
Methods Summary
public voidhandleNotification(javax.management.Notification notifIn, java.lang.Object handback)

		final String	type	= notifIn.getType();

		//final Map<String,Serializable>	m	= getAMXNotificationData * notifIn );
		final ObjectName	objectName	=
		    Util.getAMXNotificationValue( notifIn, AMXConfig.CONFIG_OBJECT_NAME_KEY, ObjectName.class );
		
		//trace( "CreateRemoveListener:\n" + SmartStringifier.toString( notifIn ) + ":\n" + objectName );
			
		if ( Util.getJ2EEType( objectName ).equals( mJ2EETypeExpected )  &&
			Util.getName( objectName ).equals( mNameExpected ) )
		{
			if ( type.equals( AMXConfig.CONFIG_CREATED_NOTIFICATION_TYPE ) )
			{
				mCreateNotif	= notifIn;
			}
			else if ( type.equals( AMXConfig.CONFIG_REMOVED_NOTIFICATION_TYPE ) )
			{
				mRemoveNotif	= notifIn;
			}
		}
	
protected voidtrace(java.lang.Object o)

		System.out.println( SmartStringifier.toString( o ) );
	
public voidwaitCreate()

		long	millis	= 10;
		
		while ( mCreateNotif == null )
		{
			AMXTestBase.mySleep( millis );
			trace( "waiting " + millis + "ms for CONFIG_CREATED_NOTIFICATION_TYPE for " + mNameExpected);
			millis	*= 2;
		}
	
public voidwaitNotifs()

		waitCreate();
		waitRemove();
		
		try
		{
			mSource.removeNotificationListener( (NotificationListener)this, null, null );
		}
		catch( ListenerNotFoundException e )
		{
			throw new RuntimeException( e );
		}
	
public voidwaitRemove()

		long	millis	= 10;
		while ( mRemoveNotif == null )
		{
			AMXTestBase.mySleep( millis );
			trace( "waiting " + millis + "ms for CONFIG_REMOVED_NOTIFICATION_TYPE for " + mNameExpected);
			millis	*= 2;
		}