![JAR search and dependency download from the Maven repository](/logo.png)
org.glassfish.deployapi.ProgressObjectSink Maven / Gradle / Ivy
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.deployapi;
import java.util.Collection;
import java.util.Vector;
import java.util.Iterator;
import javax.enterprise.deploy.spi.status.ProgressListener;
import javax.enterprise.deploy.spi.status.ProgressEvent;
import javax.enterprise.deploy.spi.status.ProgressObject;
import javax.enterprise.deploy.spi.status.DeploymentStatus;
import javax.enterprise.deploy.spi.TargetModuleID;
import javax.enterprise.deploy.shared.StateType;
import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException;
import org.glassfish.deployment.client.DFProgressObject;
import org.glassfish.deployment.client.DFDeploymentStatus;
import org.glassfish.deployment.client.DFDeploymentStatus.Status;
import com.sun.enterprise.util.LocalStringManagerImpl;
/**
* This class acts as a sink for ProgressObject. It registers itself
* as ProgressObject listener for multiple deployment actions and
* tunnel all events to registered ProgressObject listener.
*
*Whenever this class receives a progress event from one of its sources (one of the deploymentFacility
*actions) it forwards that event on to the sink's listeners, changing the state of the event to
*"running." Then, after the sink receives the completion or failure event from the last source,
*it forwards that event as running (as it had all earlier events) and then sends one final
*aggregate completion or failure event.
*
*The sink always follows this pattern, even if it encapsulates only a single source. JSR88 clients should
*be aware of this behavior.
*
* @author Jerome Dochez
*/
public class ProgressObjectSink extends DFProgressObject implements ProgressListener {
private static String LINE_SEPARATOR = System.getProperty("line.separator");
private Vector registeredPL = new Vector();
private Vector deliveredEvents = new Vector();
/* aggregate state starts as successful and is changed only if at least one source operation fails */
private StateType finalStateType = StateType.COMPLETED;
private String finalMessage;
private Vector targetModuleIDs = new Vector();
private Vector sources = new Vector();
private static LocalStringManagerImpl localStrings =
new LocalStringManagerImpl(ProgressObjectSink.class);
DFDeploymentStatus completedStatus = new DFDeploymentStatus();
private boolean completedStatusReady = false;
/**
* register to a new ProgressObject for ProgressEvent notifications
*/
public void sinkProgressObject(ProgressObject source) {
/*
*The following two statements must appear in the order shown. Otherwise, a race condition can exist.
*/
sources.add(source);
source.addProgressListener(this);
}
/**
* 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