/** * Returns thread-safe {@link FutureImpl} implementation. (Based on the JDK {@link java.util.concurrent.FutureTask}). * * @return thread-safe {@link FutureImpl} implementation. */ public static <R> FutureImpl<R> createSafeFuture() { return SafeFutureImpl.create(); }
/** * Construct {@link SafeFutureImpl}. */ @SuppressWarnings("unchecked") public static <R> SafeFutureImpl<R> create() { return new SafeFutureImpl<R>(); }
/** * Protected method invoked when this task transitions to state * <tt>isDone</tt> (whether normally or via cancellation). The * default implementation does nothing. Subclasses may override * this method to invoke completion callbacks or perform * bookkeeping. Note that you can query status inside the * implementation of this method to determine whether this task * has been cancelled. */ protected void done() { notifyCompletionHandlers(); onComplete(); }
/** * {@inheritDoc} */ @Override public void addCompletionHandler(final CompletionHandler<R> completionHandler) { if (isDone()) { notifyCompletionHandler(completionHandler); } else { synchronized (chSync) { if (!isDone()) { if (completionHandlers == null) { completionHandlers = new HashSet<CompletionHandler<R>>(2); } completionHandlers.add(completionHandler); return; } } notifyCompletionHandler(completionHandler); } }
/** * Notify single {@link CompletionHandler} about the result. */ private void notifyCompletionHandler(final CompletionHandler<R> completionHandler) { if (isCancelled()) { completionHandler.cancelled(); } else { try { final R result = get(); try { completionHandler.completed(result); } catch (Exception ignored) { } } catch (ExecutionException e) { completionHandler.failed(e.getCause()); } catch (Exception e) { completionHandler.failed(e); } } }
assert isDone(); final boolean isCancelled = isCancelled(); final R result = sync.result; final Throwable error = sync.exception;
final SafeFutureImpl<File> future = SafeFutureImpl.create(); final File temp = File.createTempFile("grizzly-download-", ".tmp"); temp.deleteOnExit(); client.connect("localhost", PORT); long start = System.currentTimeMillis(); BigInteger testSum = getMDSum(future.get(10, TimeUnit.SECONDS)); long stop = System.currentTimeMillis(); BigInteger controlSum = getMDSum(f);
/** * Notify single {@link CompletionHandler} about the result. */ private void notifyCompletionHandler(final CompletionHandler<R> completionHandler) { if (isCancelled()) { completionHandler.cancelled(); } else { try { final R result = get(); try { completionHandler.completed(result); } catch (Exception ignored) { } } catch (ExecutionException e) { completionHandler.failed(e.getCause()); } catch (Exception e) { completionHandler.failed(e); } } }
/** * Protected method invoked when this task transitions to state * <tt>isDone</tt> (whether normally or via cancellation). The * default implementation does nothing. Subclasses may override * this method to invoke completion callbacks or perform * bookkeeping. Note that you can query status inside the * implementation of this method to determine whether this task * has been cancelled. */ protected void done() { notifyCompletionHandlers(); onComplete(); }
/** * {@inheritDoc} */ @Override public void addCompletionHandler(final CompletionHandler<R> completionHandler) { if (isDone()) { notifyCompletionHandler(completionHandler); } else { synchronized (chSync) { if (!isDone()) { if (completionHandlers == null) { completionHandlers = new HashSet<CompletionHandler<R>>(2); } completionHandlers.add(completionHandler); return; } } notifyCompletionHandler(completionHandler); } }
assert isDone(); final boolean isCancelled = isCancelled(); final R result = sync.result; final Throwable error = sync.exception;
/** * Returns thread-safe {@link FutureImpl} implementation. (Based on the JDK {@link java.util.concurrent.FutureTask}). * * @return thread-safe {@link FutureImpl} implementation. */ public static <R> FutureImpl<R> createSafeFuture() { return SafeFutureImpl.create(); }
/** * Notify single {@link CompletionHandler} about the result. */ private void notifyCompletionHandler(final CompletionHandler<R> completionHandler) { if (isCancelled()) { completionHandler.cancelled(); } else { try { final R result = get(); try { completionHandler.completed(result); } catch (Exception ignored) { } } catch (ExecutionException e) { completionHandler.failed(e.getCause()); } catch (Exception e) { completionHandler.failed(e); } } }
/** * Protected method invoked when this task transitions to state * <tt>isDone</tt> (whether normally or via cancellation). The * default implementation does nothing. Subclasses may override * this method to invoke completion callbacks or perform * bookkeeping. Note that you can query status inside the * implementation of this method to determine whether this task * has been cancelled. */ protected void done() { notifyCompletionHandlers(); onComplete(); }
/** * {@inheritDoc} */ @Override public void addCompletionHandler(final CompletionHandler<R> completionHandler) { if (isDone()) { notifyCompletionHandler(completionHandler); } else { synchronized (chSync) { if (!isDone()) { if (completionHandlers == null) { completionHandlers = new HashSet<CompletionHandler<R>>(2); } completionHandlers.add(completionHandler); return; } } notifyCompletionHandler(completionHandler); } }
assert isDone(); final boolean isCancelled = isCancelled(); final R result = sync.result; final Throwable error = sync.exception;
/** * Construct {@link SafeFutureImpl}. */ @SuppressWarnings("unchecked") public static <R> SafeFutureImpl<R> create() { return new SafeFutureImpl<R>(); }
/** * Returns thread-safe {@link FutureImpl} implementation. (Based on the JDK {@link java.util.concurrent.FutureTask}). * * @return thread-safe {@link FutureImpl} implementation. */ public static <R> FutureImpl<R> createSafeFuture() { return SafeFutureImpl.create(); }