This project has retired. For details please refer to its Attic page.
KryoWrappedReduceOperation 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  package org.apache.giraph.reducers.impl;
19  
20  import java.io.DataInput;
21  import java.io.DataOutput;
22  import java.io.IOException;
23  
24  import org.apache.giraph.reducers.ReduceOperation;
25  import org.apache.giraph.writable.kryo.KryoWritableWrapper;
26  
27  /**
28   * Reduce operation which wraps reduced value in KryoWritableWrapper,
29   * so we don't need to worry about it being writable
30   *
31   * @param <S> Single value type
32   * @param <R> Reduced value type
33   */
34  public abstract class KryoWrappedReduceOperation<S, R>
35      implements ReduceOperation<S, KryoWritableWrapper<R>> {
36    /**
37     * Look at ReduceOperation.reduce.
38     *
39     * @param reduceInto Partial value into which to reduce and store the result
40     * @param valueToReduce Single value to be reduced
41     */
42    public abstract void reduce(R reduceInto, S valueToReduce);
43  
44    /**
45     * Look at ReduceOperation.reduceMerge.
46     *
47     * @param reduceInto Partial value into which to reduce and store the result
48     * @param valueToReduce Partial value to be reduced
49     */
50    public abstract void reduceMerge(R reduceInto, R valueToReduce);
51  
52    /**
53     * Look at ReduceOperation.createValue.
54     *
55     * @return Neutral value
56     */
57    public abstract R createValue();
58  
59    @Override
60    public final KryoWritableWrapper<R> createInitialValue() {
61      return new KryoWritableWrapper<>(createValue());
62    }
63  
64    @Override
65    public final KryoWritableWrapper<R> reduce(
66        KryoWritableWrapper<R> wrapper, S value) {
67      reduce(wrapper.get(), value);
68      return wrapper;
69    }
70  
71    @Override
72    public final KryoWritableWrapper<R> reduceMerge(
73        KryoWritableWrapper<R> wrapper,
74        KryoWritableWrapper<R> wrapperToReduce) {
75      reduceMerge(wrapper.get(), wrapperToReduce.get());
76      return wrapper;
77    }
78  
79    @Override
80    public void write(DataOutput dataOutput) throws IOException {
81    }
82  
83    @Override
84    public void readFields(DataInput dataInput) throws IOException {
85    }
86  }