org.glassfish.deployapi.ProgressObjectSink Maven / Gradle / Ivy
Show all versions of payara-embedded-all Show documentation
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
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