Skip to content
Permalink
Browse files

Merge pull request #5 from jglick/PPPP-JENKINS-26130

[JENKINS-26130] Way to print progress from pickles
  • Loading branch information...
jglick committed Jun 16, 2016
2 parents f749920 + d2cc2eb commit d85f3c2d60f7d4a7f0f4e2687f6e31069b6d0f28
@@ -19,9 +19,11 @@

import java.io.File;
import java.io.IOException;
import java.nio.channels.CancelledKeyException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
@@ -167,7 +169,7 @@ public static FlowExecutionList get() {

@Override
public void onLoaded() {
for (FlowExecution e : list) {
for (final FlowExecution e : list) {
LOGGER.log(FINE, "Eager loading {0}", e);
Futures.addCallback(e.getCurrentExecutions(false), new FutureCallback<List<StepExecution>>() {
@Override
@@ -180,7 +182,11 @@ public void onSuccess(List<StepExecution> result) {

@Override
public void onFailure(Throwable t) {
LOGGER.log(WARNING, null, t);
if (t instanceof CancellationException) {
LOGGER.log(Level.FINE, "Cancelled load of " + e, t);
} else {
LOGGER.log(WARNING, "Failed to load " + e, t);
}
}
});
}
@@ -26,6 +26,7 @@

import hudson.model.Queue;
import hudson.model.Run;
import hudson.model.TaskListener;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
@@ -34,6 +35,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import jenkins.model.TransientActionFactory;
import org.jenkinsci.plugins.workflow.steps.StepContext;

/**
* We need something that's serializable in small moniker that helps us find THE instance
@@ -100,14 +102,22 @@ public String getUrlOfExecution() throws IOException {
* {@link FlowExecutionOwner}s are equal to one another if and only if
* they point to the same {@link FlowExecution} object.
*/
public abstract boolean equals(Object o);
@Override public abstract boolean equals(Object o);

/**
* Needs to be overridden as the {@link #equals(Object)} method is overridden.
*/
@Override
public abstract int hashCode();

/**
* Gets a listener to which we may print general messages.
* Normally {@link StepContext#get} should be used, but in some cases there is no associated step.
*/
public @Nonnull TaskListener getListener() throws IOException {
return TaskListener.NULL;
}

/**
* Marker interface for queue executables from {@link #getExecutable}.
* A reasonable target type for {@link TransientActionFactory}.
@@ -122,4 +132,33 @@ public String getUrlOfExecution() throws IOException {

}

/**
* A placeholder implementation for use in compatibility stubs.
*/
public static FlowExecutionOwner dummyOwner() {
return new DummyOwner();
}

private static class DummyOwner extends FlowExecutionOwner {
DummyOwner() {}
@Override public FlowExecution get() throws IOException {
throw new IOException("not implemented");
}
@Override public File getRootDir() throws IOException {
throw new IOException("not implemented");
}
@Override public Queue.Executable getExecutable() throws IOException {
throw new IOException("not implemented");
}
@Override public String getUrl() throws IOException {
throw new IOException("not implemented");
}
@Override public boolean equals(Object o) {
return o instanceof DummyOwner;
}
@Override public int hashCode() {
return 0;
}
}

}
@@ -26,8 +26,10 @@

import com.google.common.util.concurrent.ListenableFuture;
import hudson.FilePath;
import hudson.Util;

import java.io.Serializable;
import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner;

/**
* Handle value objects to replace another stateful objects that cannot be serialized on its own,
@@ -36,12 +38,27 @@
* @author Kohsuke Kawaguchi
*/
public abstract class Pickle implements Serializable {

@Deprecated
public ListenableFuture<?> rehydrate() {
return rehydrate(FlowExecutionOwner.dummyOwner());
}

/**
* Start preparing rehydration of this value, and when it's ready or fail, report that to the
* given call.
* An implementation should return quickly and avoid acquiring locks in this method itself (as opposed to the future).
* {@link ListenableFuture#cancel} should be implemented if possible.
* @param owner an owner handle on which you may, for example, call {@link FlowExecutionOwner#getListener}
*/
public abstract ListenableFuture<?> rehydrate();
public ListenableFuture<?> rehydrate(FlowExecutionOwner owner) {
if (Util.isOverridden(Pickle.class, getClass(), "rehydrate")) {
return rehydrate();
} else {
throw new AbstractMethodError(getClass().getName() + " must implement rehydrate");
}
}

private static final long serialVersionUID = 1L;

}

0 comments on commit d85f3c2

Please sign in to comment.
You can’t perform that action at this time.