FileDocCategorySizeDatePackage
DeploymentMgrImpl.javaAPI DocGlassfish v2 API14128Fri May 04 22:23:28 BST 2007com.sun.enterprise.management.deploy

DeploymentMgrImpl

public final class DeploymentMgrImpl extends com.sun.enterprise.management.support.AMXNonConfigImplBase implements com.sun.appserv.management.base.Utility, com.sun.appserv.management.base.Singleton, com.sun.appserv.management.deploy.DeploymentMgr
Implementation note--the design of this class is unnecessarily complicated due to the inclusion of certain polling-style methods such as takeNotifications() and getFinalDeploymentStatus(). If this aspect of the API can be eliminated, the implemention of this class as well as DeployThread can be simplified. This limitation was driven by the issue of not having Notification support in the http connector used by the deployment team.

Fields Summary
private final Map
mDeployThreads
A Map keyed by deployID to values of DeployThread
private final com.sun.enterprise.management.support.UniqueIDGenerator
mDeployIDs
private long
mDeploymentCompletedNotificationSequenceNumber
private final Set
NOTIF_TYPES
private static final long
SECOND_MILLIS
private static final long
MINUTE_MILLIS
private static final long
DEPLOY_KEEP_ALIVE_MILLIS
Constructors Summary
public DeploymentMgrImpl()

		mDeployThreads	= Collections.synchronizedMap( new HashMap<Object,DeployThread>() );
		mDeployIDs		= new UniqueIDGenerator( "deploy:" );
		
		mDeploymentCompletedNotificationSequenceNumber	= 0;
	
Methods Summary
public booleanabortDeploy(java.lang.Object deployID)

		final DeployThread	deployThread	= getDeployThread( deployID );
		
		final boolean	abortedSuccessfully	= deployThread.quit();
		
		issueDeploymentAbortedNotification( deployID );
		
		return( abortedSuccessfully );
	
private DeployThreadaddDeployThread(java.lang.Object deployID)

		final DeploymentCallback	callback	=
			new InternalDeploymentCallback( deployID );
			
		final DeployThread	deployThread	=
			new DeployThread( deployID, callback, null );
		mDeployThreads.put( deployThread.getID(), deployThread );
		
		return( deployThread );
	
public byte[]downloadBytes(java.lang.Object downloadID, int requestSize)

		return( getUploadDownloadMgr().downloadBytes( downloadID, requestSize ) );
    
private DeployThreadgetDeployThread(java.lang.Object deployID)

		final DeployThread	deployThread	= (DeployThread)mDeployThreads.get( deployID );
		if ( deployThread == null )
		{
			final IllegalArgumentException	e	= new IllegalArgumentException( "" + deployID );
			
			e.printStackTrace();
			throw e;
		}
		return( deployThread );
	
public longgetDownloadLength(java.lang.Object downloadID)
Get the total length the download will be, in bytes.

param
downloadID the file download operation id, from initiateFileDownload()

		return( getUploadDownloadMgr().getDownloadLength( downloadID ) );
    
public java.util.MapgetFinalDeploymentStatus(java.lang.Object deployID)

		final DeployThread	deployThread	= removeDeployThread( deployID );
		
		if ( deployThread == null )
		{
			throw new IllegalArgumentException( deployID.toString() );
		}
		
		return( deployThread.getDeploymentStatus().asMap() );
	
protected java.util.SetgetNotificationTypes(java.util.Set existing)

	
		 
	   
	
	    existing.addAll( NOTIF_TYPES );
	    return existing;
	
private com.sun.appserv.management.base.UploadDownloadMgrgetUploadDownloadMgr()

		return( getDomainRoot().getUploadDownloadMgr() );
	
public java.lang.ObjectinitDeploy()

		final Object	deployID	= mDeployIDs.createID();
		
		final DeployThread	deployThread	= addDeployThread( deployID );
		
		return( deployID );
	
public java.lang.ObjectinitiateFileDownload(java.lang.String moduleID, java.lang.String filename)

		final DownloadFileSource	source	= new DownloadFileSource( moduleID, filename );
		final File			theFile	= source.getDownloadFile( );
		final boolean		deleteWhenDone	= source.isTempFile();
		
		return( getUploadDownloadMgr().initiateDownload( theFile, deleteWhenDone ) );
	
public java.lang.ObjectinitiateFileUpload(long totalSize)

		return initiateFileUpload( null, totalSize );
	
public java.lang.ObjectinitiateFileUpload(java.lang.String name, long totalSize)

	    debug( "initiateFileUpload(" + name + ", " + totalSize + ")" );
		return( getUploadDownloadMgr().initiateUpload( name, totalSize ) );
	
protected voidissueDeploymentAbortedNotification(java.lang.Object deployID)

		final NotificationBuilder	builder	=
			getNotificationBuilder( DEPLOYMENT_ABORTED_NOTIFICATION_TYPE );
		
		final Notification	notif	= builder.buildNew( );
		builder.putMapData( notif, NOTIF_DEPLOYMENT_ID_KEY, (Serializable)deployID );
		
		issueNotification( deployID, notif );
	
protected voidissueDeploymentDoneNotification(java.lang.Object deployID, com.sun.appserv.management.deploy.DeploymentStatus deploymentStatus)

		final NotificationBuilder	builder	=
			getNotificationBuilder( DEPLOYMENT_COMPLETED_NOTIFICATION_TYPE );
		
		final Notification	notif	= builder.buildNew( );
		builder.putMapData( notif, NOTIF_DEPLOYMENT_ID_KEY, (Serializable)deployID );
		builder.putMapData( notif, NOTIF_DEPLOYMENT_COMPLETED_STATUS_KEY, (Serializable)deploymentStatus.asMap() );
		
		issueNotification( deployID, notif );
	
protected voidissueDeploymentProgressNotification(java.lang.Object deployID, com.sun.appserv.management.deploy.DeploymentProgress progress)

		final NotificationBuilder	builder	=
			getNotificationBuilder( DEPLOYMENT_PROGRESS_NOTIFICATION_TYPE );
		
		final Notification	notif	= builder.buildNew( );
		builder.putMapData( notif, NOTIF_DEPLOYMENT_ID_KEY, (Serializable)deployID );
		builder.putMapData( notif, NOTIF_DEPLOYMENT_PROGRESS_KEY, (Serializable)progress.asMap() );
		
		issueNotification( deployID, notif );
	
protected voidissueDeploymentStartedNotification(java.lang.Object deployID)

		final NotificationBuilder	builder	=
			getNotificationBuilder( DEPLOYMENT_STARTED_NOTIFICATION_TYPE );
		
		final Notification	notif	= builder.buildNew( );
		builder.putMapData( notif, NOTIF_DEPLOYMENT_ID_KEY, (Serializable)deployID );
		
		issueNotification( deployID, notif );
	
private voidissueNotification(java.lang.Object deployID, javax.management.Notification notif)

		// send it, for normal callers
		sendNotification( notif );
		
		trace( "\nDeploymentMgrImpl.issueNotification: sent notification for " +
			deployID + " = " + notif.toString() );
		
		// queue it, for pollers
		final DeployThread	deployThread	= getDeployThread( deployID );
		deployThread.queueNotification( notif );
	
private booleannotifsAreDone(javax.management.Notification[] notifs)

		boolean	done	= false;
		
		for( int i = notifs.length -1; i >= 0; --i )
		{
			final String	notifType	= notifs[ notifs.length - 1].getType();
		
			if ( notifType.equals( DEPLOYMENT_COMPLETED_NOTIFICATION_TYPE ) ||
						notifType.equals( DEPLOYMENT_ABORTED_NOTIFICATION_TYPE ) )
			{
				done	= true;
				break;
			}
		}
		
		return( done );
	
public voidremove(java.lang.String name)

		throw new RuntimeException( "not applicable" );
	
private DeployThreadremoveDeployThread(java.lang.Object deployID)

	
	
		 
	  	
	
		trace( "\n###Removing deploy thread: " + deployID );
		return( (DeployThread)mDeployThreads.remove( deployID ) );
	
private final voidstaleDeployCheck()
Cleanup any threads that have been done for a proscribed amount of time given by UPLOAD_KEEP_ALIVE_MILLIS. We don't want to clean them up immediately because the client should have a reasonable chance to get the status after completion.

		final Set<Object> keySet		= mDeployThreads.keySet();
		
		synchronized( mDeployThreads )
		{
			final String[]	deployIDs	= GSetUtil.toStringArray( keySet );
		
			for( final String deployID : deployIDs )
			{
				final DeployThread	deployThread	= (DeployThread)mDeployThreads.get( deployID );
				
				if ( deployThread.getMillisSinceDone() > DEPLOY_KEEP_ALIVE_MILLIS )
				{
					removeDeployThread( deployID );
				}
			}
		}
	
private voidstartDeploy(java.lang.Object deployID, DeployThreadParams params)

		final DeployThread	deployThread	= getDeployThread( deployID );
		if ( deployThread == null )
		{
			throw new IllegalArgumentException( deployID.toString() );
		}
		deployThread.setParams( params );
		
		/**
			Issue a DEPLOYMENT_STARTED_NOTIFICATION_TYPE *before*
			starting the thread, because a client could receive
			other Notifications (even "done") before the "started" one.
		 */
		issueDeploymentStartedNotification( deployID );
		
		deployThread.start();
	
public voidstartDeploy(java.lang.Object deployID, java.lang.Object uploadID, java.lang.Object planUploadID, java.util.Map options)

		staleDeployCheck();
		
		final UploadDownloadMgr	mgr	= getUploadDownloadMgr();
		
		final File	deployFile	= mgr.takeUpload( uploadID );
		final File	planFile	= planUploadID == null ? null : mgr.takeUpload( planUploadID );
		
		final DeployThreadParams	params	=
			new DeployThreadParams(
				getQueryMgr(),
				options,
				deployFile,
				planFile );
		
		startDeploy( deployID, params );
	
public voidstartDeploy(java.lang.Object deployID, java.util.Map sourceData, java.util.Map planData, java.util.Map options)

		final DeploymentSource	source	=
			DeploymentSupport.mapToDeploymentSource( sourceData );
			
		final DeploymentSource	plan	= planData == null ?
			null : DeploymentSupport.mapToDeploymentSource( planData );
			
		final DeployThreadParams	params	=
			new DeployThreadParams( getQueryMgr(), options, source, plan );
		
		startDeploy( deployID, params );
	
public javax.management.Notification[]takeNotifications(java.lang.Object deployID)

		final DeployThread	deployThread	= getDeployThread( deployID );
		
		final Notification[]	notifs	= deployThread.takeNotifications();
		
		return( notifs );
    
public java.util.Mapundeploy(java.lang.String moduleID, java.util.Map optionalParams)

		final Undeployer		undeployer	= new Undeployer( moduleID, optionalParams );
		final DeploymentStatus	undeploymentStatus	= undeployer.undeploy();
		
		return( undeploymentStatus.asMap() );
	
public booleanuploadBytes(java.lang.Object uploadID, byte[] bytes)

		return( getUploadDownloadMgr().uploadBytes( uploadID, bytes ) );