1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */18package org.apache.giraph.io.gora;
1920import java.io.IOException;
2122import org.apache.giraph.edge.Edge;
23import org.apache.giraph.io.gora.generated.GEdgeResult;
24import org.apache.gora.persistency.Persistent;
25import org.apache.hadoop.io.DoubleWritable;
26import org.apache.hadoop.io.FloatWritable;
27import org.apache.hadoop.io.LongWritable;
28import org.apache.hadoop.mapreduce.TaskAttemptContext;
2930/**31 * Implementation of a specific writer for a generated data bean.32 */33publicclassGoraGEdgeEdgeOutputFormat34extends GoraEdgeOutputFormat<LongWritable, DoubleWritable,
35 FloatWritable> {
3637/**38 * Default constructor39 */40publicGoraGEdgeEdgeOutputFormat() {
41 }
4243 @Override
44publicGoraEdgeWriter createEdgeWriter(
45 TaskAttemptContext context) throws IOException, InterruptedException {
46returnnewGoraGEdgeEdgeWriter();
47 }
4849/**50 * Gora edge writer.51 */52protectedclassGoraGEdgeEdgeWriter53extendsGoraEdgeWriter {
5455 @Override
56protected Persistent getGoraEdge(LongWritable srcId,
57 DoubleWritable srcValue, Edge<LongWritable, FloatWritable> edge) {
58GEdgeResult tmpGEdge = newGEdgeResult();
59 tmpGEdge.setEdgeId(srcId.toString());
60 tmpGEdge.setEdgeWeight(edge.getValue().get());
61 tmpGEdge.setVertexOutId(edge.getTargetVertexId().toString());
62 getLogger().debug("GoraObject created: " + tmpGEdge.toString());
63return tmpGEdge;
64 }
6566 @Override
67protected Object getGoraKey(LongWritable srcId,
68 DoubleWritable srcValue, Edge<LongWritable, FloatWritable> edge) {
69 String goraKey = String.valueOf(
70 edge.getTargetVertexId().get() + edge.getValue().get());
71return goraKey;
72 }
7374 }
75 }