FileDocCategorySizeDatePackage
DeployThread.javaAPI DocGlassfish v2 API7710Fri May 04 22:24:04 BST 2007com.sun.enterprise.management.deploy

DeployThread

public final class DeployThread extends Thread
This implementation of DeployThread is a stub implementation designed to replace the normal implementation when unit tests are being run.

Fields Summary
private DeployThreadParams
mParams
private final Object
mDeployID
private final DeploymentCallback
mDeploymentCallback
private boolean
mQuit
private boolean
mDone
private Throwable
mThrowable
private long
mDoneMillis
private com.sun.appserv.management.deploy.DeploymentStatusImpl
mDeploymentStatus
private final List
mQueuedNotifications
Constructors Summary
public DeployThread(Object id, DeploymentCallback deploymentCallback, DeployThreadParams params)

		mDeployID	= id;
		mDeploymentCallback	= deploymentCallback;
		mParams		= params;
		
		mDeploymentStatus	= null;
		mThrowable	= null;
		mDone		= false;
		
		mQuit		= false;
		
		mDoneMillis	= 0;
		
		mQueuedNotifications	= new ArrayList<Notification>();
		
	
Methods Summary
private com.sun.appserv.management.deploy.DeploymentStatusImpldeploy(DeployThreadParams params, DeploymentCallback callback)

		int	percent = 0;
		
		while ( percent < 100 )
		{
			percent	+= 10;
			
			final DeploymentProgress	progress	=
				new DeploymentProgressImpl( 
					(byte)percent, "percent done", null);
				
			callback.deploymentProgress( progress );
			Thread.sleep( 1 );
		}
		
		final DeploymentStatusImpl	deploymentStatus	=
			new DeploymentStatusImpl( 
			0,
			"completed",
			"description",
			null );
		
		return( deploymentStatus );
	
public com.sun.appserv.management.deploy.DeploymentProgressgetDeploymentProgress()

return
the ID of this DeployThread

		final byte		progressPercent			= 0;
		final String	description				= "<no description>";
		
		final DeploymentProgressImpl	progress	=
			new DeploymentProgressImpl( progressPercent, description, null);
		
		return( progress );
	
public com.sun.appserv.management.deploy.DeploymentStatusgetDeploymentStatus()

		return( mDeploymentStatus );
	
public java.lang.ObjectgetID()

return
the ID of this DeployThread

		return( mDeployID );
	
public longgetMillisSinceDone()

return
the number of milliseconds since the deploy finished

		return( isDone() ? (System.currentTimeMillis() - mDoneMillis) : 0  );
	
public booleangetSuccess()

return
true if done and success

		return( isDone() && mDeploymentStatus != null );
	
public java.lang.ThrowablegetThrowable()
Return any Throwabe that caused a failure

return
the Throwable, or null if none.

		return( mThrowable );
	
public booleanisDone()

return
true if done (success or failure)

		return( mDone );
	
public voidqueueNotification(javax.management.Notification notif)

		if ( isDone() )
		{
			throw new IllegalArgumentException(
				"Notification cannot be queued after being done for: " + mDeployID);
		}
		
		synchronized( mQueuedNotifications )
		{
			mQueuedNotifications.add( notif );
		}
	
public booleanquit()

		mQuit	= true;
		this.interrupt();
		
		while ( ! isDone() )
		{
			try
			{
				Thread.sleep( 200 );
			}
			catch( InterruptedException e )
			{
			}
		}
		
		return( true );
	
public voidrun()

		mThrowable	= null;
		mDone		= false;
		
		//trace( "DeployThread.run: starting: " + getID() );
		try
		{
			if ( mParams == null )
			{
				throw new IllegalArgumentException( "no params specified" );
			}
			
			//trace( "DeployThread.run: calling deploy() for: " + getID() );
			mDeploymentStatus	= deploy( mParams, mDeploymentCallback );
			//trace( "DeployThread.run: deploy() successful for: " + getID()  );
		}
		catch( Throwable t )
		{
			mDeploymentStatus	=
			new DeploymentStatusImpl(
				-1,
				"failure",
				"description",
				null );
				
			mThrowable	= t;
			
			mDeploymentStatus.setStageThrowable( t );
		}
		
		try
		{
			mDeploymentCallback.deploymentDone( mDeploymentStatus );
			
			// success or failure, always kill the file
			if ( mParams.getDeployFile() != null )
			{
				//trace( "DeployThread.run: deleting deploy file: " + mParams.getDeployFile() );
				mParams.getDeployFile().delete();
			}
			
			// success or failure, always kill the file
			if ( mParams.getPlanFile() != null )
			{
				//trace( "DeployThread.run: deleting plan file: " + mParams.getPlanFile() );
				mParams.getPlanFile().delete();
			}
		}
		finally
		{
			mDoneMillis	= System.currentTimeMillis();
			mDone	= true;
		}
		
		//trace( "DeployThread.run: done with: " + getID() );
	
public voidsetParams(DeployThreadParams params)

		if ( mParams != null )
		{
			throw new IllegalArgumentException();
		}
		
		mParams	= params;
	
public javax.management.Notification[]takeNotifications()

		Notification[]	notifs	= null;
		
		synchronized( mQueuedNotifications )
		{
			notifs	= new Notification[ mQueuedNotifications.size() ];
			mQueuedNotifications.toArray( notifs );
			mQueuedNotifications.clear();
		}
		
		return( notifs );
	
private static voidtrace(java.lang.Object o)

		System.out.println( o.toString() );