This project has retired. For details please refer to its Attic page.
Source code
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.common;
020
021import org.apache.commons.lang3.tuple.ImmutableTriple;
022import org.apache.commons.lang3.tuple.Triple;
023import org.apache.reef.annotations.Unstable;
024import org.apache.reef.annotations.audience.Private;
025import org.apache.reef.vortex.api.VortexAggregateFunction;
026import org.apache.reef.vortex.api.VortexAggregatePolicy;
027import org.apache.reef.vortex.api.VortexFunction;
028
029import javax.annotation.concurrent.ThreadSafe;
030import javax.inject.Inject;
031import java.util.concurrent.ConcurrentHashMap;
032import java.util.concurrent.ConcurrentMap;
033
034/**
035 * A repository for {@link VortexAggregateFunction} and its associated {@link VortexFunction},
036 * used to pass functions between VortexMaster and RunningWorkers, as well as used to cache functions
037 * for VortexWorkers on AggregateRequests and AggregateExecutionRequests.
038 */
039@ThreadSafe
040@Unstable
041@Private
042public final class AggregateFunctionRepository {
043  private final ConcurrentMap<Integer, Triple<VortexAggregateFunction, VortexFunction, VortexAggregatePolicy>>
044      aggregateFunctionMap = new ConcurrentHashMap<>();
045
046  @Inject
047  private AggregateFunctionRepository() {
048  }
049
050  /**
051   * Associates an aggregate function ID with a {@link VortexAggregateFunction} and a {@link VortexFunction}.
052   */
053  public Triple<VortexAggregateFunction, VortexFunction, VortexAggregatePolicy> put(
054      final int aggregateFunctionId,
055      final VortexAggregateFunction aggregateFunction,
056      final VortexFunction function,
057      final VortexAggregatePolicy policy) {
058    return aggregateFunctionMap.put(aggregateFunctionId, new ImmutableTriple<>(aggregateFunction, function, policy));
059  }
060
061  /**
062   * Gets the {@link VortexAggregateFunction} associated with the aggregate function ID.
063   */
064  public VortexAggregateFunction getAggregateFunction(final int aggregateFunctionId) {
065    return aggregateFunctionMap.get(aggregateFunctionId).getLeft();
066  }
067
068  /**
069   * Gets the {@link VortexFunction} associated with the aggregate function ID.
070   */
071  public VortexFunction getFunction(final int aggregateFunctionId) {
072    return aggregateFunctionMap.get(aggregateFunctionId).getMiddle();
073  }
074
075  /**
076   * Gets the {@link VortexAggregatePolicy} associated with the aggregate function ID.
077   */
078  public VortexAggregatePolicy getPolicy(final int aggregateFunctionId) {
079    return aggregateFunctionMap.get(aggregateFunctionId).getRight();
080  }
081}