This project has retired. For details please refer to its Attic page.
AggregatorWriter xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.giraph.aggregators;
20  
21  import java.io.IOException;
22  import java.util.Map.Entry;
23  
24  import org.apache.giraph.conf.ImmutableClassesGiraphConfigurable;
25  import org.apache.hadoop.io.Writable;
26  import org.apache.hadoop.mapreduce.Mapper.Context;
27  
28  /**
29   *  An AggregatorWriter is used to export Aggregators during or at the end of
30   *  each computation. It runs on the master and it's called at the end of each
31   *  superstep. The special signal {@link AggregatorWriter#LAST_SUPERSTEP} is
32   *  passed to {@link AggregatorWriter#writeAggregator(Iterable, long)} as the
33   *  superstep value to signal the end of computation.
34   */
35  public interface AggregatorWriter extends ImmutableClassesGiraphConfigurable {
36    /** Signal for last superstep */
37    int LAST_SUPERSTEP = -1;
38  
39    /**
40     * The method is called at the initialization of the AggregatorWriter.
41     * More precisely, the aggregatorWriter is initialized each time a new
42     * master is elected.
43     *
44     * @param context Mapper Context where the master is running on
45     * @param applicationAttempt ID of the applicationAttempt, used to
46     *        disambiguate aggregator writes for different attempts
47     * @throws IOException
48     */
49    @SuppressWarnings("rawtypes")
50    void initialize(Context context, long applicationAttempt) throws IOException;
51  
52    /**
53     * The method is called at the end of each superstep. The user might decide
54     * whether to write the aggregators values for the current superstep. For
55     * the last superstep, {@link AggregatorWriter#LAST_SUPERSTEP} is passed.
56     *
57     * @param aggregatorMap Map from aggregator name to aggregator value
58     * @param superstep Current superstep
59     * @throws IOException
60     */
61    void writeAggregator(
62        Iterable<Entry<String, Writable>> aggregatorMap,
63        long superstep) throws IOException;
64  
65    /**
66     * The method is called at the end of a successful computation. The method
67     * is not called when the job fails and a new master is elected. For this
68     * reason it's advised to flush data at the end of
69     * {@link AggregatorWriter#writeAggregator(Iterable, long)}.
70     *
71     * @throws IOException
72     */
73    void close() throws IOException;
74  }