Skip to content
Permalink
Browse files

[JENKINS-26130] Way to print progress from pickles.

  • Loading branch information...
jglick committed Jun 9, 2016
1 parent f749920 commit cbd00d462ebfb8d320e87228f88baf6d6f0f90f3
@@ -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;
@@ -100,14 +101,18 @@ 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();

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 +127,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 cbd00d4

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.