use of org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverReader in project workflow-cps-plugin by jenkinsci.
the class CpsFlowExecution method loadProgramAsync.
/**
* Deserializes {@link CpsThreadGroup} from {@link #getProgramDataFile()} if necessary.
*
* This moves us into the PREPARING state.
* @param programDataFile
*/
public void loadProgramAsync(File programDataFile) {
final SettableFuture<CpsThreadGroup> result = SettableFuture.create();
programPromise = result;
try {
scriptClass = parseScript().getClass();
final RiverReader r = new RiverReader(programDataFile, scriptClass.getClassLoader(), owner);
Futures.addCallback(r.restorePickles(pickleFutures = new ArrayList<>()), new FutureCallback<Unmarshaller>() {
public void onSuccess(Unmarshaller u) {
pickleFutures = null;
try {
CpsFlowExecution old = PROGRAM_STATE_SERIALIZATION.get();
PROGRAM_STATE_SERIALIZATION.set(CpsFlowExecution.this);
try {
CpsThreadGroup g = (CpsThreadGroup) u.readObject();
result.set(g);
try {
if (g.isPaused()) {
owner.getListener().getLogger().println("Still paused");
} else {
owner.getListener().getLogger().println("Ready to run at " + new Date());
// In case we last paused execution due to Jenkins.isQuietingDown, make sure we do something after we restart.
g.scheduleRun();
}
} catch (IOException x) {
LOGGER.log(Level.WARNING, null, x);
}
} catch (Throwable t) {
onFailure(t);
} finally {
PROGRAM_STATE_SERIALIZATION.set(old);
}
} finally {
r.close();
}
}
public void onFailure(Throwable t) {
// Note: not calling result.setException(t) since loadProgramFailed in fact sets a result
try {
loadProgramFailed(t, result);
} finally {
r.close();
}
}
});
} catch (Exception | GroovyBugError e) {
loadProgramFailed(e, result);
}
}
Aggregations