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 HttpURLConnection openInFiber(final OkUrlFactory factory, final URL url) throws InterruptedException { return FiberUtil.runInFiberRuntime ( new SuspendableCallable<HttpURLConnection>() { @Override public HttpURLConnection run() throws SuspendExecution, InterruptedException { return factory.open(url); } } ); }
/** * Blocks on the input fibers and creates a new list from the results. The result list is the same order as the * input list. * * @param fibers to combine */ @SuppressWarnings("unchecked") public static <V> List<V> get(Fiber<V>... fibers) throws InterruptedException { return FiberUtil.get(fibers); }
/** * Runs an action in a new fiber and awaits the fiber's termination. * The new fiber is scheduled by the {@link DefaultFiberScheduler default scheduler}. * . * * @param target the operation * @throws ExecutionException * @throws InterruptedException */ public static void runInFiber(SuspendableRunnable target) throws ExecutionException, InterruptedException { FiberUtil.runInFiber(target); }
/** * 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 { try { new Fiber<Void>(scheduler, target).start().join(); } catch (ExecutionException ex) { throw throwChecked(ex, exceptionType); } }
/** * Turns a fiber into a {@link Future}. * * @param <V> * @param fiber the fiber * @return a {@link Future} representing the fiber. */ public static <V> Future<V> toFuture(Fiber<V> fiber) { return FiberUtil.toFuture(fiber); }
/** * Runs an action in a new fiber and awaits the fiber's termination. * * @param scheduler the {@link FiberScheduler} to use when scheduling the fiber. * @param target the operation * @throws ExecutionException * @throws InterruptedException */ public static void runInFiber(FiberScheduler scheduler, SuspendableRunnable target) throws ExecutionException, InterruptedException { FiberUtil.runInFiber(scheduler, target); }
/** * 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 { try { return new Fiber<V>(scheduler, target).start().get(); } catch (ExecutionException ex) { throw throwChecked(ex, exceptionType); } }
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}. * The new fiber is scheduled by the {@link DefaultFiberScheduler default scheduler}. * * @param target the operation * @throws InterruptedException */ public static void runInFiberRuntime(SuspendableRunnable target) throws InterruptedException { FiberUtil.runInFiberRuntime(target); }
/** * Blocks on the input fibers and creates a new list from the results. The result list is the same order as the * input list. * * @param fibers to combine */ public static <V> List<V> get(List<Fiber<V>> fibers) throws InterruptedException { return FiberUtil.get(fibers); }
/** * Runs an action in a new fiber, awaits the fiber's termination, and returns its result. * * @param <V> * @param scheduler the {@link FiberScheduler} to use when scheduling the fiber. * @param target the operation * @return the operations return value * @throws ExecutionException * @throws InterruptedException */ public static <V> V runInFiber(FiberScheduler scheduler, SuspendableCallable<V> target) throws ExecutionException, InterruptedException { return FiberUtil.runInFiber(scheduler, target); }
/** * 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 and awaits the fiber's termination. * Unlike {@link #runInFiber(FiberScheduler, SuspendableRunnable) runInFiber} this method does not throw {@link ExecutionException}, but wraps * any checked exception thrown by the operation in a {@link RuntimeException}. * * @param scheduler the {@link FiberScheduler} to use when scheduling the fiber. * @param target the operation * @throws InterruptedException */ public static void runInFiberRuntime(FiberScheduler scheduler, SuspendableRunnable target) throws InterruptedException { FiberUtil.runInFiberRuntime(scheduler, target); }
/** * Blocks on the input fibers and creates a new list from the results. The result list is the same order as the * input list. * * @param timeout to wait for all requests to complete * @param unit the time is in * @param fibers to combine */ public static <V> List<V> get(long timeout, TimeUnit unit, List<Fiber<V>> fibers) throws InterruptedException, TimeoutException { return FiberUtil.get(timeout, unit, fibers); }
/** * Runs an action in a new fiber, awaits the fiber's termination, and returns its result. * The new fiber is scheduled by the {@link DefaultFiberScheduler default scheduler}. * * @param <V> * @param target the operation * @return the operations return value * @throws ExecutionException * @throws InterruptedException */ public static <V> V runInFiber(SuspendableCallable<V> target) throws ExecutionException, InterruptedException { return FiberUtil.runInFiber(target); }
/** * 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(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> V runInFiberRuntime(SuspendableCallable<V> target) throws InterruptedException { return FiberUtil.runInFiberRuntime(target); }
/** * Blocks on the input fibers and creates a new list from the results. The result list is the same order as the * input list. * * @param time to wait for all requests to complete * @param unit the time is in * @param fibers to combine */ @SuppressWarnings("unchecked") public static <V> List<V> get(long time, TimeUnit unit, Fiber<V>... fibers) throws InterruptedException, TimeoutException { return FiberUtil.get(time, unit, fibers); }
/** * Runs an action in a new fiber and awaits the fiber's termination. * The new fiber is scheduled by the {@link DefaultFiberScheduler default scheduler}. * . * * @param target the operation * @throws ExecutionException * @throws InterruptedException */ public static void runInFiber(SuspendableRunnable target) throws ExecutionException, InterruptedException { runInFiber(DefaultFiberScheduler.getInstance(), target); }