use of javax.enterprise.deploy.spi.status.ProgressListener in project Payara by payara.
the class ProgressObjectImpl method fireProgressEvent.
/**
* Notifies all listeners that have registered interest for ProgressEvent notification.
*
* @param progressEvent {@link ProgressEvent}
*/
protected void fireProgressEvent(ProgressEvent progressEvent) {
// Bug 4977764
// Iteration failed due to concurrent modification of the vector. Even though the add,
// remove, and fire methods synchronize on the listeners vector, a listener could
// conceivably invoke add or remove recursively, thereby triggering the concurrent
// modification exception.
// Fix: clone the listeners vector and iterate through the clone.
//
final Vector<ProgressListener> currentListeners;
synchronized (listeners) {
currentListeners = (Vector<ProgressListener>) listeners.clone();
// The following add must remain inside the synchronized block. Otherwise, there will be
// a small window in which a new listener's registration could interleave with
// fireProgressEvent, registering itself after the listeners vector had been cloned
// (thus excluding the new listener from the iteration a few lines below) but before
// the list of previously-delivered events had been updated.
// This would cause the new listener to miss the event that was firing.
// Keeping the following add inside the synchronized block ensures that updates to
// the listeners vector by addProgressListener and to deliveredEvents
// by fireProgressEvent do not interleave and therefore all listeners will receive all
// events.
deliveredEvents.add(progressEvent);
}
for (ProgressListener element : currentListeners) {
element.handleProgressEvent(progressEvent);
}
}
use of javax.enterprise.deploy.spi.status.ProgressListener 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);
}
}
}
use of javax.enterprise.deploy.spi.status.ProgressListener in project Payara by payara.
the class SimpleProgressObjectImpl method fireProgressEvent.
/**
* Notifies all listeners that have registered interest for ProgressEvent notification.
*/
protected void fireProgressEvent(ProgressEvent progressEvent) {
Vector currentListeners = null;
synchronized (listeners) {
currentListeners = (Vector) listeners.clone();
deliveredEvents.add(progressEvent);
}
for (Iterator listenersItr = currentListeners.iterator(); listenersItr.hasNext(); ) {
((ProgressListener) listenersItr.next()).handleProgressEvent(progressEvent);
}
}
Aggregations