/** * Returns a new call initialiser for calls executed in the specified state * context {@code stateContext} that use return buffers initialised by the specified * factory {@code returnBufferFactory}. * * @param stateContext the state context, must not be {@code null} * @param returnBufferFactory the return buffer factory, must not be {@code null} * @return a new call initialiser for {@code stateContext} * * @throws NullPointerException if {@code stateContext} or {@code returnBufferFactory} * is {@code null} */ public static RuntimeCallInitialiser forState(StateContext stateContext, ReturnBufferFactory returnBufferFactory) { return new RuntimeCallInitialiser(stateContext, returnBufferFactory); }
/** * Returns a new call initialiser for calls executed in the specified state * context {@code stateContext}, and using the default return buffer factory * (see {@link ReturnBuffers#defaultFactory()}). * * @param stateContext the state context, must not be {@code null} * @return a new call initialiser for {@code stateContext} * * @throws NullPointerException if {@code stateContext} is {@code null} */ public static RuntimeCallInitialiser forState(StateContext stateContext) { return forState(stateContext, ReturnBuffers.defaultFactory()); }
/** * Calls {@code fn(args...)} in the current thread in the state context {@code stateContext}, * returning the call result once the call completes. * * <p>The call result will be passed in a freshly-allocated array, and may therefore * be manipulated freely by the caller of this method.</p> * * @param stateContext state context of the call, must not be {@code null} * @param fn the call target, may be {@code null} * @param args call arguments, must not be {@code null} * @return the call result * * @throws CallException if the call terminated abnormally * @throws CallPausedException if the call initiated a pause * @throws InterruptedException when the current thread is interrupted while waiting * for an asynchronous operation to be completed * @throws NullPointerException if {@code stateContext} or {@code args} is {@code null} */ public Object[] call(StateContext stateContext, Object fn, Object... args) throws CallException, CallPausedException, InterruptedException { CallInitialiser initialiser = RuntimeCallInitialiser.forState( stateContext, returnBufferFactory); return resume(initialiser.newCall( performJavaConversions ? Conversions.canonicalRepresentationOf(fn) : fn, performJavaConversions ? Conversions.copyAsCanonicalValues(args) : args)); }