Coverage Report - org.apache.giraph.graph.MutableVertex
 
Classes in this File Line Coverage Branch Coverage Complexity
MutableVertex
100%
13/13
N/A
1
 
 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.graph;
 20  
 
 21  
 import org.apache.hadoop.io.Writable;
 22  
 import org.apache.hadoop.io.WritableComparable;
 23  
 
 24  
 import java.io.IOException;
 25  
 import java.util.Map;
 26  
 
 27  
 /**
 28  
  * Interface used by VertexReader to set the properties of a new vertex
 29  
  * or mutate the graph.
 30  
  *
 31  
  * @param <I> Vertex id
 32  
  * @param <V> Vertex data
 33  
  * @param <E> Edge data
 34  
  * @param <M> Message data
 35  
  */
 36  
 @SuppressWarnings("rawtypes")
 37  524
 public abstract class MutableVertex<I extends WritableComparable,
 38  
     V extends Writable, E extends Writable, M extends Writable>
 39  
     extends Vertex<I, V, E, M> {
 40  
   /**
 41  
    * Add an edge for this vertex (happens immediately)
 42  
    *
 43  
    * @param targetVertexId target vertex
 44  
    * @param value value of the edge
 45  
    * @return Return true if succeeded, false otherwise
 46  
    */
 47  
   public abstract boolean addEdge(I targetVertexId, E value);
 48  
 
 49  
   /**
 50  
    * Removes an edge for this vertex (happens immediately).
 51  
    *
 52  
    * @param targetVertexId the target vertex id of the edge to be removed.
 53  
    * @return the value of the edge which was removed (or null if no
 54  
    *         edge existed to targetVertexId)
 55  
    */
 56  
   public abstract E removeEdge(I targetVertexId);
 57  
 
 58  
   /**
 59  
    * Create a vertex to add to the graph.  Calls initialize() for the vertex
 60  
    * as well.
 61  
    *
 62  
    * @param vertexId Id of the new vertex.
 63  
    * @param vertexValue Value of the new vertex.
 64  
    * @param edges Map of edges to be added to this vertex.
 65  
    * @param messages Messages to be added to the vertex (typically empty)
 66  
    * @return A new vertex for adding to the graph
 67  
    */
 68  
   public Vertex<I, V, E, M> instantiateVertex(
 69  
       I vertexId, V vertexValue, Map<I, E> edges, Iterable<M> messages) {
 70  10
     MutableVertex<I, V, E, M> mutableVertex =
 71  
         (MutableVertex<I, V, E, M>) BspUtils
 72  
         .<I, V, E, M>createVertex(getContext().getConfiguration());
 73  10
     mutableVertex.setGraphState(getGraphState());
 74  10
     mutableVertex.initialize(vertexId, vertexValue, edges, messages);
 75  10
     return mutableVertex;
 76  
   }
 77  
 
 78  
   /**
 79  
    * Sends a request to create a vertex that will be available during the
 80  
    * next superstep.  Use instantiateVertex() to do the instantiation.
 81  
    *
 82  
    * @param vertex User created vertex
 83  
    */
 84  
   public void addVertexRequest(Vertex<I, V, E, M> vertex)
 85  
     throws IOException {
 86  10
     getGraphState().getWorkerCommunications().
 87  
         addVertexRequest(vertex);
 88  10
   }
 89  
 
 90  
   /**
 91  
    * Request to remove a vertex from the graph
 92  
    * (applied just prior to the next superstep).
 93  
    *
 94  
    * @param vertexId Id of the vertex to be removed.
 95  
    */
 96  
   public void removeVertexRequest(I vertexId) throws IOException {
 97  10
     getGraphState().getWorkerCommunications().
 98  
         removeVertexRequest(vertexId);
 99  10
   }
 100  
 
 101  
   /**
 102  
    * Request to add an edge of a vertex in the graph
 103  
    * (processed just prior to the next superstep)
 104  
    *
 105  
    * @param sourceVertexId Source vertex id of edge
 106  
    * @param edge Edge to add
 107  
    */
 108  
   public void addEdgeRequest(I sourceVertexId, Edge<I, E> edge)
 109  
     throws IOException {
 110  10
     getGraphState().getWorkerCommunications().
 111  
         addEdgeRequest(sourceVertexId, edge);
 112  10
   }
 113  
 
 114  
   /**
 115  
    * Request to remove an edge of a vertex from the graph
 116  
    * (processed just prior to the next superstep).
 117  
    *
 118  
    * @param sourceVertexId Source vertex id of edge
 119  
    * @param targetVertexId Destination vertex id of edge
 120  
    */
 121  
   public void removeEdgeRequest(I sourceVertexId, I targetVertexId)
 122  
     throws IOException {
 123  20
     getGraphState().getWorkerCommunications().
 124  
         removeEdgeRequest(sourceVertexId, targetVertexId);
 125  20
   }
 126  
 }