FileDocCategorySizeDatePackage
DeployNotificationListener.javaAPI DocGlassfish v2 API7890Fri May 04 22:30:50 BST 2007com.sun.appserv.management.helper

DeployNotificationListener

public class DeployNotificationListener extends Object implements NotificationListener
A NotificationListener designed to listen to the {@link DeploymentMgr}.

Note that Notifications are not guaranteed to be delivered in order. Thus, it is theoretically possible for a DEPLOYMENT_COMPLETED_NOTIFICATION_TYPE to be received before a DEPLOYMENT_STARTED_NOTIFICATION_TYPE.

A subclass may choose to override {@link #deploymentStarted}, {@link #deploymentProgress} and

since
AppServer 9.0

Fields Summary
private final Object
mDeployID
private boolean
mIsCompleted
private com.sun.appserv.management.deploy.DeploymentStatus
mDeploymentStatus
private com.sun.appserv.management.deploy.DeploymentProgress
mDeploymentProgress
private final com.sun.appserv.management.deploy.DeploymentMgr
mDeploymentMgr
Constructors Summary
public DeployNotificationListener(com.sun.appserv.management.deploy.DeploymentMgr deploymentMgr, Object deployID)

		
		if ( deploymentMgr == null || deployID == null )
		{
		    throw new IllegalArgumentException();
		}

		mIsCompleted	= false;
		mDeploymentStatus    = null;
		mDeploymentProgress  = null;
		mDeploymentMgr  = deploymentMgr;
		mDeployID       = deployID;
		mDeploymentMgr.addNotificationListener( this, null, null );
	
Methods Summary
public voidcleanup()
Clean things up. This mainly means removing this listener from the DeploymentMgr.

		try
		{
            mDeploymentMgr.removeNotificationListener( this, null, null );
        }
        catch( ListenerNotFoundException e )
        {
        }
	
protected voiddeploymentAborted(javax.management.Notification notif, com.sun.appserv.management.deploy.DeploymentStatus status)
Deployment has been cancelled. There may or may not be a DeploymentStatus.

		mIsCompleted	    = true;
		mDeploymentStatus	= status;
    
protected voiddeploymentDone(javax.management.Notification notif, com.sun.appserv.management.deploy.DeploymentStatus status)
Deployment has finished. For convenience, the DeploymentStatus has been extracted from the Notification.

		//SampleUtil.println( "Deployment completed for " + deployID + " with status: " + 
			//status.getStageStatus() );
		mIsCompleted	= true;
		mDeploymentStatus	= status;
    
protected voiddeploymentProgress(javax.management.Notification notif, com.sun.appserv.management.deploy.DeploymentProgress status)
Deployment progress. For convenience, the DeploymentProgress has been extracted from the Notification.

    	mDeploymentProgress	= status;
    
protected voiddeploymentStarted(javax.management.Notification notif)
Deployment has begun. The Notification contains no additional data.

	
public java.lang.ObjectgetDeployID()

return
the deployID this listener responds to

	    return mDeployID;
	
public com.sun.appserv.management.deploy.DeploymentMgrgetDeploymentMgr()

return
the DeploymentMgr in use for deployment.

	    return mDeploymentMgr;
	
public com.sun.appserv.management.deploy.DeploymentProgressgetDeploymentProgress()

return
the latest DeploymentProgress, may be null

		return( mDeploymentProgress );
	
public com.sun.appserv.management.deploy.DeploymentStatusgetDeploymentStatus()

return
DeploymentStatus, may be null if not finished or abnormally terminated.

		return( mDeploymentStatus );
	
public synchronized voidhandleNotification(javax.management.Notification notif, java.lang.Object handback)
Callback for all Notifications occurring during deployment. Note for public use.

		try
		{
			realHandleNotification( notif, handback );
		}
		catch( Exception e )
		{
			e.printStackTrace();
		}
	
public booleanisCompleted()
Return true if deployment has finished.

		return( mIsCompleted );
	
protected final voidrealHandleNotification(javax.management.Notification notif, java.lang.Object handback)
Handle a received Notification.

		final String	type	= notif.getType();
		final Map<String,?>		m	= TypeCast.asMap( notif.getUserData() );
		final Object	deployID	= m.get( DeploymentMgr.NOTIF_DEPLOYMENT_ID_KEY );
		
		if ( deployID.equals( mDeployID ) )
		{
			if ( type.equals( DeploymentMgr.DEPLOYMENT_STARTED_NOTIFICATION_TYPE ) )
			{
			    deploymentStarted( notif );
			}
			else if ( type.equals( DeploymentMgr.DEPLOYMENT_ABORTED_NOTIFICATION_TYPE ) )
			{
				try
				{
			        deploymentAborted( notif, null );
				}
				finally
				{
				    cleanup();
				}
			}
			else if ( type.equals( DeploymentMgr.DEPLOYMENT_COMPLETED_NOTIFICATION_TYPE ) )
			{
				final Map<String,Serializable>	statusData	= (Map<String,Serializable>)
				    Util.getAMXNotificationValue( notif, NOTIF_DEPLOYMENT_COMPLETED_STATUS_KEY );
				
				final DeploymentStatus	status	= 
					DeploymentSupport.mapToDeploymentStatus( statusData );
					
				try
				{
				    deploymentDone( notif, status );
				}
				finally
				{
				    cleanup();
				}
			}
			else if ( type.equals( DeploymentMgr.DEPLOYMENT_PROGRESS_NOTIFICATION_TYPE ) )
			{
				final Map<String,Serializable>	statusData	= (Map<String,Serializable>)
				    Util.getAMXNotificationValue( notif, NOTIF_DEPLOYMENT_PROGRESS_KEY );
				    
				final DeploymentProgress	progress	= 
					DeploymentSupport.mapToDeploymentProgress( statusData );
				
            	deploymentProgress( notif, progress );
			}
		}