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

DeployThread

public final class DeployThread extends Thread

Fields Summary
private DeployThreadParams
mParams
private final Object
mDeployID
private String
moduleID
private final DeploymentCallback
mDeploymentCallback
private boolean
mQuit
private boolean
mDone
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;
	mDone = false;
		
        mQuit = false;
		
        mDoneMillis = 0;
		
        mQueuedNotifications = new ArrayList<Notification>();
		
    
Methods Summary
private com.sun.appserv.management.deploy.DeploymentStatusImpldeploy(DeployThreadParams params, DeploymentCallback callback)

        try { 
            Map options = params.getOptions();
            
            File deployFile = params.getDeployFile();
            File planFile = params.getPlanFile();

            if (deployFile == null) {
                DeploymentSource deploySource = params.getDeploymentSource();
                if (deploySource != null) {
                    deployFile = deploySource.getArchive();
                }
                DeploymentSource deployPlan = params.getDeploymentPlan();
                if (deployPlan != null) {
                    planFile = deployPlan.getArchive();
                }
            }

            DeploymentProperties dProps = new DeploymentProperties(options);
            String archiveName = dProps.getArchiveName();
            if (archiveName == null && deployFile != null) {
                archiveName = deployFile.getAbsolutePath();
                if (deployFile.isDirectory()) {
                    moduleID = dProps.getName(archiveName);
                } else {
                    //In case the archive was passed in as an MemoryArchive, 
                    //ie. no file name available to a default moduleID, ask 
                    //the backend to supply a computed moduleID (using display 
                    //name in dd)
                    String computedID = 
                        DeploymentService.getDeploymentService().getModuleIDFromDD(deployFile);
                    moduleID = dProps.getProperty(
                        DeploymentProperties.NAME, computedID);
                }
            } else {
                moduleID = dProps.getName(archiveName);
            }

            com.sun.enterprise.deployment.backend.DeploymentStatus ds = DeploymentService.getDeploymentService().deploy(deployFile, planFile, archiveName, moduleID, dProps, callback);
            ds.setStageStatus(ds.getStatus()); // This is done for the AMX clients to get complete status
            
            DeploymentRequestRegistry.getRegistry().removeDeploymentRequest(
                moduleID);
            
            final Map<String,Serializable> m    =
                TypeCast.checkMap( ds.asMap(), String.class, Serializable.class );
            
            return new DeploymentStatusImpl( m );
        } catch(Exception e) {
            com.sun.enterprise.deployment.backend.DeploymentStatus ds =
                new com.sun.enterprise.deployment.backend.DeploymentStatus();
            ds.setStageException(e);
            ds.setStageStatus(com.sun.enterprise.deployment.backend.DeploymentStatus.FAILURE);      
            ds.setStageStatusMessage(e.getMessage());
            ds.setStageDescription("Deployment");
            DeploymentRequestRegistry.getRegistry().removeDeploymentRequest(
                moduleID); 
            
            final Map<String,Serializable> m    =
                TypeCast.checkMap( ds.asMap(), String.class, Serializable.class );
            return new DeploymentStatusImpl( m );
        }   
    
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 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;
        return DeploymentService.getDeploymentService().quit(moduleID);
    
public voidrun()

	mDone = false;

        trace( "DeployThread.run: starting: " + getID() );

        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()  );

	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();
	}
		
	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 voidtrace(java.lang.Object o)

    	final String	name	= this.getClass().getName();
        Logger.getLogger( name ).fine( o.toString() );