001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.vortex.api;
020
021import org.apache.reef.annotations.Unstable;
022import org.apache.reef.annotations.audience.ClientSide;
023import org.apache.reef.annotations.audience.Public;
024import org.apache.reef.util.Optional;
025
026import java.util.List;
027
028/**
029 * The synchronous result of an aggregate, returned by {@link VortexAggregateFuture#get()}.
030 */
031@Public
032@ClientSide
033@Unstable
034public final class AggregateResultSynchronous<TInput, TOutput> {
035  private final AggregateResult<TInput, TOutput> result;
036  private final boolean hasNext;
037
038  AggregateResultSynchronous(final AggregateResult<TInput, TOutput> result, final boolean hasNext) {
039    this.result = result;
040    this.hasNext = hasNext;
041  }
042
043  /**
044   * @return the output of an aggregation, throws the Exception if a Tasklet or an aggregation fails.
045   * If an aggregation fails, {@link VortexAggregateException} will be thrown, otherwise
046   * the Exception that caused the Tasklet to fail will be thrown directly.
047   * @throws VortexAggregateException the Exception that caused the Tasklet or aggregation failure.
048   */
049  public TOutput getAggregateResult() throws VortexAggregateException {
050    return result.getAggregateResult();
051  }
052
053  /**
054   * @return the associated inputs of an aggregation
055   */
056  public List<TInput> getAggregatedInputs() {
057    return result.getAggregatedInputs();
058  }
059
060  /**
061   * If an aggregation fails, {@link VortexAggregateException} will be thrown, otherwise
062   * the Exception that caused the Tasklet to fail will be thrown directly.
063   * @return the Exception that caused the Tasklet or aggregation failure, if any.
064   */
065  public Optional<Exception> getException() {
066    return result.getException();
067  }
068
069  /**
070   * @return true if more results will be available, false otherwise.
071   */
072  public boolean hasNext() {
073    return hasNext;
074  }
075}