public static HttpResponse executeInFiber(final OkApacheClient client, final HttpRequestBase req) throws InterruptedException, IOException { return FiberUtil.runInFiberChecked ( new SuspendableCallable<HttpResponse>() { @Override public HttpResponse run() throws SuspendExecution, InterruptedException { try { return client.execute(req); } catch (IOException ex) { throw new RuntimeException(ex); } } }, IOException.class ); }
public static Response executeInFiber(final Call call) throws InterruptedException, IOException { return FiberUtil.runInFiberChecked ( new SuspendableCallable<Response>() { @Override public Response run() throws SuspendExecution, InterruptedException { try { return call.execute(); } catch (IOException ex) { throw new RuntimeException(ex); } } }, IOException.class ); }
/** * Runs an action in a new fiber and awaits the fiber's termination. * Unlike {@link #runInFiber(SuspendableRunnable) runInFiber} this method does not throw {@link ExecutionException}, but wraps * any checked exception thrown by the operation in a {@link RuntimeException}, unless it is of the given {@code exception type}, in * which case the checked exception is thrown as-is. * * @param scheduler the {@link FiberScheduler} to use when scheduling the fiber. * @param target the operation * @param exceptionType a checked exception type that will not be wrapped if thrown by the operation, but thrown as-is. * @throws InterruptedException */ public static <X extends Exception> void runInFiberChecked(FiberScheduler scheduler, SuspendableRunnable target, Class<X> exceptionType) throws X, InterruptedException { FiberUtil.runInFiberChecked(scheduler, target, exceptionType); }
/** * Runs an action in a new fiber and awaits the fiber's termination. * Unlike {@link #runInFiber(SuspendableRunnable) runInFiber} this method does not throw {@link ExecutionException}, but wraps * any checked exception thrown by the operation in a {@link RuntimeException}, unless it is of the given {@code exception type}, in * which case the checked exception is thrown as-is. * The new fiber is scheduled by the {@link DefaultFiberScheduler default scheduler}. * * @param target the operation * @param exceptionType a checked exception type that will not be wrapped if thrown by the operation, but thrown as-is. * @throws InterruptedException */ public static <X extends Exception> void runInFiberChecked(SuspendableRunnable target, Class<X> exceptionType) throws X, InterruptedException { FiberUtil.runInFiberChecked(target, exceptionType); }
/** * Runs an action in a new fiber, awaits the fiber's termination, and returns its result. * Unlike {@link #runInFiber(SuspendableCallable) runInFiber} this method does not throw {@link ExecutionException}, but wraps * any checked exception thrown by the operation in a {@link RuntimeException}. * The new fiber is scheduled by the {@link DefaultFiberScheduler default scheduler}. * * @param <V> * @param target the operation * @return the operations return value * @throws InterruptedException */ public static <V, X extends Exception> V runInFiberChecked(SuspendableCallable<V> target, Class<X> exceptionType) throws X, InterruptedException { return FiberUtil.runInFiberChecked(target, exceptionType); }
/** * Runs an action in a new fiber, awaits the fiber's termination, and returns its result. * Unlike {@link #runInFiber(FiberScheduler, SuspendableCallable) runInFiber} this method does not throw {@link ExecutionException}, but wraps * any checked exception thrown by the operation in a {@link RuntimeException}, unless it is of the given {@code exception type}, in * which case the checked exception is thrown as-is. * * @param <V> * @param scheduler the {@link FiberScheduler} to use when scheduling the fiber. * @param target the operation * @param exceptionType a checked exception type that will not be wrapped if thrown by the operation, but thrown as-is. * @return the operations return value * @throws InterruptedException */ public static <V, X extends Exception> V runInFiberChecked(FiberScheduler scheduler, SuspendableCallable<V> target, Class<X> exceptionType) throws X, InterruptedException { return FiberUtil.runInFiberChecked(scheduler, target, exceptionType); }
/** * Runs an action in a new fiber, awaits the fiber's termination, and returns its result. * Unlike {@link #runInFiber(SuspendableCallable) runInFiber} this method does not throw {@link ExecutionException}, but wraps * any checked exception thrown by the operation in a {@link RuntimeException}. * The new fiber is scheduled by the {@link DefaultFiberScheduler default scheduler}. * * @param <V> * @param target the operation * @return the operations return value * @throws InterruptedException */ public static <V, X extends Exception> V runInFiberChecked(SuspendableCallable<V> target, Class<X> exceptionType) throws X, InterruptedException { return runInFiberChecked(DefaultFiberScheduler.getInstance(), target, exceptionType); }
/** * Runs an action in a new fiber and awaits the fiber's termination. * Unlike {@link #runInFiber(SuspendableRunnable) runInFiber} this method does not throw {@link ExecutionException}, but wraps * any checked exception thrown by the operation in a {@link RuntimeException}, unless it is of the given {@code exception type}, in * which case the checked exception is thrown as-is. * The new fiber is scheduled by the {@link DefaultFiberScheduler default scheduler}. * * @param target the operation * @param exceptionType a checked exception type that will not be wrapped if thrown by the operation, but thrown as-is. * @throws InterruptedException */ public static <X extends Exception> void runInFiberChecked(SuspendableRunnable target, Class<X> exceptionType) throws X, InterruptedException { runInFiberChecked(DefaultFiberScheduler.getInstance(), target, exceptionType); }