/** * Get the future result of an operation. Should be called in conjunction with {@link #asynchronous(Object)}. * * @param operation the operation * @param <T> the result type * @return the future result * @throws IllegalStateException if the operation is not appropriately given */ @SuppressWarnings("unchecked") public static <T> Future<T> getFutureResult(final T operation) throws IllegalStateException { if (operation != null) { return new FinishedFuture<T>(operation); } final ThreadLocal<Future<?>> futureResult = FUTURE_RESULT; try { final Future<?> future = futureResult.get(); if (future == null) throw log.noAsyncInProgress(); return (Future<T>) future; } finally { futureResult.remove(); } }
/** * Get the future result of an operation. Should be called in conjunction with {@link #asynchronous(Object)}. * * @param operation the operation * @param <T> the result type * @return the future result * @throws IllegalStateException if the operation is not appropriately given */ @SuppressWarnings("unchecked") public static <T> Future<T> getFutureResult(final T operation) throws IllegalStateException { if (operation != null) { return new FinishedFuture<T>(operation); } final ThreadLocal<Future<?>> futureResult = FUTURE_RESULT; try { final Future<?> future = futureResult.get(); if (future == null) throw log.noAsyncInProgress(); return (Future<T>) future; } finally { futureResult.remove(); } }
/** * Get the future result of an operation. Should be called in conjunction with {@link #asynchronous(Object)}. * * @param operation the operation * @param <T> the result type * @return the future result * @throws IllegalStateException if the operation is not appropriately given */ @SuppressWarnings("unchecked") public static <T> Future<T> getFutureResult(final T operation) throws IllegalStateException { if (operation != null) { return new FinishedFuture<T>(operation); } final ThreadLocal<Future<?>> futureResult = FUTURE_RESULT; try { final Future<?> future = futureResult.get(); if (future == null) throw log.noAsyncInProgress(); return (Future<T>) future; } finally { futureResult.remove(); } }