Package com.cloudbees.groovy.cps

Examples of com.cloudbees.groovy.cps.Outcome


        boolean changed;    // used to see if we need to loop over
        do {
            changed = false;
            for (CpsThread t : threads.values().toArray(new CpsThread[threads.size()])) {
                if (t.isRunnable()) {
                    Outcome o = t.runNextChunk();
                    if (o.isFailure()) {
                        assert !t.isAlive();    // failed thread is non-resumable

                        // workflow produced an exception
                        Result result = Result.FAILURE;
                        Throwable error = o.getAbnormal();
                        if (error instanceof FlowInterruptedException) {
                            result = ((FlowInterruptedException) error).getResult();
                        }
                        execution.setResult(result);
                        t.head.get().addAction(new ErrorAction(error));
View Full Code Here


    private void propagateErrorToWorkflow(Throwable t) {
        // it's not obvious which thread to blame, so as a heuristics, pick up the last one,
        // as that's the ony more likely to have caused the problem.
        // TODO: when we start tracking which thread is just waiting for the body, then
        // that information would help. or maybe we should just remember the thread that has run the last time
        threads.lastEntry().getValue().resume(new Outcome(null,t));
    }
View Full Code Here

     */
    @Nonnull Outcome runNextChunk() throws IOException {
        assert program!=null;

        while (true) {
            Outcome outcome;

            final CpsThread old = CURRENT.get();
            CURRENT.set(this);

            try {
                LOGGER.log(FINE, "runNextChunk on {0}", resumeValue);
                Outcome o = resumeValue;
                resumeValue = null;
                outcome = program.run0(o);
                if (outcome.getAbnormal() != null) {
                    LOGGER.log(FINE, "ran and produced error", outcome.getAbnormal());
                } else {
View Full Code Here

    public Outcome run0(final Outcome cn) {
        try {
            return GroovySandbox.runInSandbox(new Callable<Outcome>() {
                @Override
                public Outcome call() {
                    Outcome outcome = SandboxContinuable.super.run0(cn);
                    Throwable t = outcome.getAbnormal();
                    if (t instanceof RejectedAccessException) {
                        ScriptApproval.get().accessRejected((RejectedAccessException) t, ApprovalContext.create());
                    }
                    return outcome;
                }
View Full Code Here

    public synchronized void onFailure(Throwable t) {
        if (t==null)
            throw new IllegalArgumentException();
        if (isCompleted())
            throw new IllegalStateException("Already completed", t);
        this.outcome = new Outcome(null,t);

        scheduleNextRun();
    }
View Full Code Here

    }

    public synchronized void onSuccess(Object returnValue) {
        if (isCompleted())
            throw new IllegalStateException("Already completed");
        this.outcome = new Outcome(returnValue,null);

        scheduleNextRun();
    }
View Full Code Here

     * Start running the new thread unless the stop is requested, in which case the thread gets aborted right away.
     */
    @CpsVmThreadOnly
    /*package*/ synchronized void startExecution(CpsThread t) {
        // either get the new thread going normally, or abort from the beginning
        t.resume(new Outcome(null, stopped));

        assert this.thread==null;
        this.thread = t;

    }
View Full Code Here

    public void prependCallback(FutureCallback<Object> callback) {
        if (!(callback instanceof Serializable))
            throw new IllegalStateException("Callback must be persistable, but got "+callback.getClass());

        Outcome o;
        synchronized (this) {
            if (callbacks != null) {
                callbacks.add(0,callback);
                return;
            }
View Full Code Here

    public void addCallback(FutureCallback<Object> callback) {
        if (!(callback instanceof Serializable))
            throw new IllegalStateException("Callback must be persistable, but got "+callback.getClass());

        Outcome o;
        synchronized (this) {
            if (callbacks != null) {
                callbacks.add(callback);
                return;
            }
View Full Code Here

        return r;
    }

    @Override
    public void onSuccess(Object result) {
        for (FutureCallback<Object> c : grabCallbacks(new Outcome(result,null))) {
            c.onSuccess(result);
        }
    }
View Full Code Here

TOP

Related Classes of com.cloudbees.groovy.cps.Outcome

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.