Search in sources :

Example 1 with RiverReader

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);
    }
}
Also used : GroovyBugError(org.codehaus.groovy.GroovyBugError) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Date(java.util.Date) UsernameNotFoundException(org.acegisecurity.userdetails.UsernameNotFoundException) InterruptedIOException(java.io.InterruptedIOException) AbortException(hudson.AbortException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) FlowInterruptedException(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException) RiverReader(org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverReader) Unmarshaller(org.jboss.marshalling.Unmarshaller)

Aggregations

AbortException (hudson.AbortException)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 Date (java.util.Date)1 ExecutionException (java.util.concurrent.ExecutionException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 UsernameNotFoundException (org.acegisecurity.userdetails.UsernameNotFoundException)1 GroovyBugError (org.codehaus.groovy.GroovyBugError)1 Unmarshaller (org.jboss.marshalling.Unmarshaller)1 FlowInterruptedException (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException)1 RiverReader (org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverReader)1