| 1 | /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
| 2 | * |
| 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 | |
| 7 | package org.mozilla.javascript; |
| 8 | |
| 9 | /** |
| 10 | * Exception thrown by |
| 11 | * {@link org.mozilla.javascript.Context#executeScriptWithContinuations(Script, Scriptable)} |
| 12 | * and {@link org.mozilla.javascript.Context#callFunctionWithContinuations(Callable, Scriptable, Object[])} |
| 13 | * when execution encounters a continuation captured by |
| 14 | * {@link org.mozilla.javascript.Context#captureContinuation()}. |
| 15 | * Exception will contain the captured state needed to restart the continuation |
| 16 | * with {@link org.mozilla.javascript.Context#resumeContinuation(Object, Scriptable, Object)}. |
| 17 | * @author Norris Boyd |
| 18 | */ |
| 19 | public class ContinuationPending extends RuntimeException { |
| 20 | private static final long serialVersionUID = 4956008116771118856L; |
| 21 | private NativeContinuation continuationState; |
| 22 | private Object applicationState; |
| 23 | |
| 24 | /** |
| 25 | * Construct a ContinuationPending exception. Internal call only; |
| 26 | * users of the API should get continuations created on their behalf by |
| 27 | * calling {@link org.mozilla.javascript.Context#executeScriptWithContinuations(Script, Scriptable)} |
| 28 | * and {@link org.mozilla.javascript.Context#callFunctionWithContinuations(Callable, Scriptable, Object[])} |
| 29 | * Creating subclasses allowed. |
| 30 | * @param continuationState Internal Continuation object |
| 31 | */ |
| 32 | protected ContinuationPending(NativeContinuation continuationState) { |
| 33 | this.continuationState = continuationState; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Get continuation object. The only |
| 38 | * use for this object is to be passed to |
| 39 | * {@link org.mozilla.javascript.Context#resumeContinuation(Object, Scriptable, Object)}. |
| 40 | * @return continuation object |
| 41 | */ |
| 42 | public Object getContinuation() { |
| 43 | return continuationState; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Set continuation object. Allows subclasses to modify the internal state. |
| 48 | * @param continuation object |
| 49 | */ |
| 50 | public void setContinuation(NativeContinuation continuation) { |
| 51 | this.continuationState = continuation; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @return internal continuation state |
| 56 | */ |
| 57 | NativeContinuation getContinuationState() { |
| 58 | return continuationState; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Store an arbitrary object that applications can use to associate |
| 63 | * their state with the continuation. |
| 64 | * @param applicationState arbitrary application state |
| 65 | */ |
| 66 | public void setApplicationState(Object applicationState) { |
| 67 | this.applicationState = applicationState; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @return arbitrary application state |
| 72 | */ |
| 73 | public Object getApplicationState() { |
| 74 | return applicationState; |
| 75 | } |
| 76 | } |