mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

matthew_swift
28.47.2010 f2160f4bd1c8ac67e5a86a6710d431e8932877f9
sdk/src/com/sun/opends/sdk/util/FutureResultTransformer.java
@@ -39,18 +39,17 @@
/**
 * An implementation of the {@code FutureResult} interface which
 * transforms the result of an asynchronous operation from one type to
 * another. The implementation ensures that the transformed is computed
 * only once.
 * An implementation of the {@code FutureResult} interface which transforms the
 * result of an asynchronous operation from one type to another. The
 * implementation ensures that the transformed is computed only once.
 *
 * @param <M>
 *          The type of the inner result.
 * @param <N>
 *          The type of the outer result.
 */
public abstract class FutureResultTransformer<M, N> implements
    FutureResult<N>, ResultHandler<M>
public abstract class FutureResultTransformer<M, N> implements FutureResult<N>,
    ResultHandler<M>
{
  private final ResultHandler<? super N> handler;
@@ -66,13 +65,13 @@
  /**
   * Creates a new result transformer which will transform the results
   * of an inner asynchronous request.
   * Creates a new result transformer which will transform the results of an
   * inner asynchronous request.
   *
   * @param handler
   *          The outer result handler.
   */
  protected FutureResultTransformer(ResultHandler<? super N> handler)
  protected FutureResultTransformer(final ResultHandler<? super N> handler)
  {
    this.handler = handler;
  }
@@ -82,7 +81,7 @@
  /**
   * {@inheritDoc}
   */
  public final boolean cancel(boolean mayInterruptIfRunning)
  public final boolean cancel(final boolean mayInterruptIfRunning)
  {
    return future.cancel(mayInterruptIfRunning);
  }
@@ -92,8 +91,7 @@
  /**
   * {@inheritDoc}
   */
  public final N get() throws ErrorResultException,
      InterruptedException
  public final N get() throws ErrorResultException, InterruptedException
  {
    future.get();
@@ -106,9 +104,8 @@
  /**
   * {@inheritDoc}
   */
  public final N get(long timeout, TimeUnit unit)
      throws ErrorResultException, TimeoutException,
      InterruptedException
  public final N get(final long timeout, final TimeUnit unit)
      throws ErrorResultException, TimeoutException, InterruptedException
  {
    future.get(timeout, unit);
@@ -131,7 +128,7 @@
  /**
   * {@inheritDoc}
   */
  public final void handleErrorResult(ErrorResultException error)
  public final void handleErrorResult(final ErrorResultException error)
  {
    transformedErrorResult = transformErrorResult(error);
    if (handler != null)
@@ -145,7 +142,7 @@
  /**
   * {@inheritDoc}
   */
  public final void handleResult(M result)
  public final void handleResult(final M result)
  {
    try
    {
@@ -188,19 +185,49 @@
  /**
   * Sets the inner future for this result transformer. This must be
   * done before this future is published.
   * Sets the inner future for this result transformer. This must be done before
   * this future is published.
   *
   * @param future
   *          The inner future.
   */
  public final void setFutureResult(FutureResult<? extends M> future)
  public final void setFutureResult(final FutureResult<? extends M> future)
  {
    this.future = future;
  }
  /**
   * Transforms the inner error result to an outer error result. The default
   * implementation is to return the inner error result.
   *
   * @param errorResult
   *          The inner error result.
   * @return The outer error result.
   */
  protected ErrorResultException transformErrorResult(
      final ErrorResultException errorResult)
  {
    return errorResult;
  }
  /**
   * Transforms the inner result to an outer result, possibly throwing an
   * {@code ErrorResultException} if the transformation fails for some reason.
   *
   * @param result
   *          The inner result.
   * @return The outer result.
   * @throws ErrorResultException
   *           If the transformation fails for some reason.
   */
  protected abstract N transformResult(M result) throws ErrorResultException;
  private N get0() throws ErrorResultException
  {
    if (transformedErrorResult != null)
@@ -213,36 +240,4 @@
    }
  }
  /**
   * Transforms the inner error result to an outer error result. The
   * default implementation is to return the inner error result.
   *
   * @param errorResult
   *          The inner error result.
   * @return The outer error result.
   */
  protected ErrorResultException transformErrorResult(
      ErrorResultException errorResult)
  {
    return errorResult;
  }
  /**
   * Transforms the inner result to an outer result, possibly throwing
   * an {@code ErrorResultException} if the transformation fails for
   * some reason.
   *
   * @param result
   *          The inner result.
   * @return The outer result.
   * @throws ErrorResultException
   *           If the transformation fails for some reason.
   */
  protected abstract N transformResult(M result)
      throws ErrorResultException;
}