Search in sources :

Example 6 with ProgressObject

use of javax.enterprise.deploy.spi.status.ProgressObject in project Payara by payara.

the class ProgressObjectSink method handleProgressEvent.

/**
 * receives notification of a progress event from one of our
 * registered interface.
 */
public void handleProgressEvent(ProgressEvent progressEvent) {
    ProgressEvent forwardedEvent;
    DeploymentStatus forwardedDS = progressEvent.getDeploymentStatus();
    // we intercept all events...
    if (!forwardedDS.isRunning()) {
        // this mean we are either completed or failed...
        if (forwardedDS.isFailed()) {
            /*
                 *Once at least one operation fails, we know that the aggregate state will have
                 *to be failed.
                 */
            finalStateType = StateType.FAILED;
        }
        // since this is the completion event
        // we are done with that progress listener;
        Object source = progressEvent.getSource();
        if (source instanceof ProgressObject) {
            ProgressObject po = (ProgressObject) source;
            po.removeProgressListener(this);
            sources.remove(source);
            if (forwardedDS.isCompleted()) {
                TargetModuleID[] ids = po.getResultTargetModuleIDs();
                for (int i = 0; i < ids.length; i++) {
                    targetModuleIDs.add(ids[i]);
                }
            }
        } else {
            throw new RuntimeException(localStrings.getLocalString("enterprise.deployment.client.noprogressobject", "Progress event does not contain a ProgressObject source"));
        }
        /*
             *Update the completionStatus by adding a stage to it and recording the completion
             *of this event as the newest stage.
             */
        updateCompletedStatus(forwardedDS);
        // now we change our event state to running.  We always forward every event from a
        // source to the listeners with "running" status because the sink is not yet completely
        // finished.  We will also send a final aggregate completion event
        // if this is a completion event from our last source (see below).
        DeploymentStatusImpl forwardedStatus = new DeploymentStatusImpl();
        forwardedStatus.setState(StateType.RUNNING);
        forwardedStatus.setMessage(forwardedDS.getMessage());
        forwardedStatus.setCommand(forwardedDS.getCommand());
        forwardedEvent = new ProgressEvent(this, progressEvent.getTargetModuleID(), forwardedStatus);
    } else {
        // This is a "running" event from one of our sources, so we just need to swap the source...
        forwardedEvent = new ProgressEvent(this, progressEvent.getTargetModuleID(), forwardedDS);
    }
    // we need to fire the received event to our listeners
    Collection clone;
    ProgressEvent finalEvent = null;
    synchronized (registeredPL) {
        clone = (Collection) registeredPL.clone();
        deliveredEvents.add(forwardedEvent);
        /*
             *If we are done with all of our sources, let's wrap up by creating a final event that will
             *be broadcast to the listeners along with the forwarded event.  Also create the completed status
             *that meets the requirements of the JESProgressObject interface.
             */
        if (sources.isEmpty()) {
            prepareCompletedStatus();
            DeploymentStatusImpl status = new DeploymentStatusImpl();
            status.setState(finalStateType);
            if (finalStateType.equals(StateType.FAILED)) {
                status.setMessage(localStrings.getLocalString("enterprise.deployment.client.aggregatefailure", "At least one operation failed"));
            } else {
                status.setMessage(localStrings.getLocalString("enterprise.deployment.client.aggregatesuccess", "All operations completed successfully"));
            }
            finalEvent = new ProgressEvent(this, progressEvent.getTargetModuleID(), status);
            deliveredEvents.add(finalEvent);
        }
    }
    for (Iterator itr = clone.iterator(); itr.hasNext(); ) {
        ProgressListener pl = (ProgressListener) itr.next();
        pl.handleProgressEvent(forwardedEvent);
    }
    /*
         *Send the final event if there is one.
         */
    if (finalEvent != null) {
        for (Iterator itr = clone.iterator(); itr.hasNext(); ) {
            ProgressListener pl = (ProgressListener) itr.next();
            pl.handleProgressEvent(finalEvent);
        }
    }
}
Also used : ProgressListener(javax.enterprise.deploy.spi.status.ProgressListener) TargetModuleID(javax.enterprise.deploy.spi.TargetModuleID) Iterator(java.util.Iterator) Collection(java.util.Collection) DFProgressObject(org.glassfish.deployment.client.DFProgressObject) ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject) ProgressEvent(javax.enterprise.deploy.spi.status.ProgressEvent) DFProgressObject(org.glassfish.deployment.client.DFProgressObject) ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject) DFDeploymentStatus(org.glassfish.deployment.client.DFDeploymentStatus) DeploymentStatus(javax.enterprise.deploy.spi.status.DeploymentStatus)

Example 7 with ProgressObject

use of javax.enterprise.deploy.spi.status.ProgressObject in project Payara by payara.

the class ProgressObjectSink method cancel.

public void cancel() throws OperationUnsupportedException {
    if (!isCancelSupported()) {
        throw new OperationUnsupportedException("cancel");
    }
    for (Iterator itr = getSources().iterator(); itr.hasNext(); ) {
        ProgressObject source = (ProgressObject) itr.next();
        source.cancel();
    }
}
Also used : Iterator(java.util.Iterator) OperationUnsupportedException(javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException) DFProgressObject(org.glassfish.deployment.client.DFProgressObject) ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject)

Example 8 with ProgressObject

use of javax.enterprise.deploy.spi.status.ProgressObject in project Payara by payara.

the class SunDeploymentManager method deploy.

/**
 * Deploy the specified module to the list of targets.
 * The deployment plan archive can be null.
 *
 * @param targetList the targets to which to deploy the module
 * @param moduleArchive the archive to be deployed
 * @param planArchive the (optional) deployment plan
 * @param options set by the caller to override and augment any settings made here
 * @return ProgressObject to communicate progress and results of the deployment
 * @throws IllegalStateException if the DeploymentManager has disconnected
 */
private ProgressObject deploy(Target[] targetList, ReadableArchive moduleArchive, ReadableArchive planArchive, Properties presetOptions) throws IllegalStateException {
    verifyConnected();
    ProgressObject progressObj = null;
    try {
        DFDeploymentProperties options = getProperties();
        // override or augment the just-assigned set.
        if (presetOptions != null) {
            options.putAll(presetOptions);
        }
        progressObj = deploymentFacility.deploy(targetList, moduleArchive, planArchive, options);
    } catch (Throwable e) {
        // Prepare a progress object with a deployment status "wrapper" around this exception.
        progressObj = prepareErrorProgressObject(CommandType.DISTRIBUTE, e);
    }
    return progressObj;
}
Also used : ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject) DFDeploymentProperties(org.glassfish.deployment.client.DFDeploymentProperties)

Example 9 with ProgressObject

use of javax.enterprise.deploy.spi.status.ProgressObject in project Payara by payara.

the class ProgressObjectSink method stop.

public void stop() throws OperationUnsupportedException {
    if (!isStopSupported()) {
        throw new OperationUnsupportedException("stop");
    }
    for (Iterator itr = getSources().iterator(); itr.hasNext(); ) {
        ProgressObject source = (ProgressObject) itr.next();
        source.stop();
    }
}
Also used : Iterator(java.util.Iterator) OperationUnsupportedException(javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException) DFProgressObject(org.glassfish.deployment.client.DFProgressObject) ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject)

Aggregations

ProgressObject (javax.enterprise.deploy.spi.status.ProgressObject)9 Iterator (java.util.Iterator)3 DeployableObject (javax.enterprise.deploy.model.DeployableObject)3 DFDeploymentProperties (org.glassfish.deployment.client.DFDeploymentProperties)3 DFProgressObject (org.glassfish.deployment.client.DFProgressObject)3 IOException (java.io.IOException)2 OperationUnsupportedException (javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException)2 ArchiveFactory (com.sun.enterprise.deploy.shared.ArchiveFactory)1 MalformedURLException (java.net.MalformedURLException)1 Collection (java.util.Collection)1 TargetModuleID (javax.enterprise.deploy.spi.TargetModuleID)1 DConfigBeanVersionUnsupportedException (javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException)1 InvalidModuleException (javax.enterprise.deploy.spi.exceptions.InvalidModuleException)1 TargetException (javax.enterprise.deploy.spi.exceptions.TargetException)1 DeploymentStatus (javax.enterprise.deploy.spi.status.DeploymentStatus)1 ProgressEvent (javax.enterprise.deploy.spi.status.ProgressEvent)1 ProgressListener (javax.enterprise.deploy.spi.status.ProgressListener)1 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 DFDeploymentStatus (org.glassfish.deployment.client.DFDeploymentStatus)1