This project has retired. For details please refer to its Attic page.
Partition 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.partition;
20  
21  import org.apache.giraph.conf.ImmutableClassesGiraphConfigurable;
22  import org.apache.giraph.graph.Vertex;
23  import org.apache.giraph.utils.VertexIterator;
24  import org.apache.hadoop.io.Writable;
25  import org.apache.hadoop.io.WritableComparable;
26  import org.apache.hadoop.util.Progressable;
27  
28  /**
29   * A generic container that stores vertices.  Vertex ids will map to exactly
30   * one partition.
31   *
32   * @param <I> Vertex id
33   * @param <V> Vertex data
34   * @param <E> Edge data
35   */
36  @SuppressWarnings("rawtypes")
37  public interface Partition<I extends WritableComparable,
38      V extends Writable, E extends Writable>
39      extends Writable, ImmutableClassesGiraphConfigurable<I, V, E>,
40      Iterable<Vertex<I, V, E>> {
41    /**
42     * Initialize the partition.  Guaranteed to be called before used.
43     *
44     * @param partitionId Partition id
45     * @param progressable Progressable to call progress
46     */
47    void initialize(int partitionId, Progressable progressable);
48  
49    /**
50     * Get the vertex for this vertex index.
51     *
52     * @param vertexIndex Vertex index to search for
53     * @return Vertex if it exists, null otherwise
54     */
55    Vertex<I, V, E> getVertex(I vertexIndex);
56  
57    /**
58     * Put a vertex into the Partition
59     *
60     * @param vertex Vertex to put in the Partition
61     * @return old vertex value (i.e. null if none existed prior)
62     */
63    Vertex<I, V, E> putVertex(Vertex<I, V, E> vertex);
64  
65    /**
66     * Remove a vertex from the Partition
67     *
68     * @param vertexIndex Vertex index to remove
69     * @return The removed vertex.
70     */
71    Vertex<I, V, E> removeVertex(I vertexIndex);
72  
73    /**
74     * Add a partition's vertices.  If a vertex to be added doesn't exist,
75     * add it.  If the vertex already exists, use the
76     * VertexValueCombiner to combine them.
77     *
78     * @param partition Partition to add
79     */
80    void addPartition(Partition<I, V, E> partition);
81  
82    /**
83     * Put this vertex or combine it
84     *
85     * @param vertex Vertex to put or combine
86     * @return True if the vertex was put (hint to release object)
87     */
88    boolean putOrCombine(Vertex<I, V, E> vertex);
89  
90    /**
91     * Add vertices to a partition.  If a vertex to be added doesn't exist,
92     * add it.  If the vertex already exists, use the
93     * VertexValueCombiner to combine them.
94     *
95     * @param vertexIterator Vertices to add
96     */
97    void addPartitionVertices(VertexIterator<I, V, E> vertexIterator);
98  
99    /**
100    * Get the number of vertices in this partition
101    *
102    * @return Number of vertices
103    */
104   long getVertexCount();
105 
106   /**
107    * Get the number of edges in this partition.
108    *
109    * @return Number of edges.
110    */
111   long getEdgeCount();
112 
113   /**
114    * Get the partition id.
115    *
116    * @return Id of this partition.
117    */
118   int getId();
119 
120   /**
121    * Set the partition id.
122    *
123    * @param id Id of this partition
124    */
125   void setId(int id);
126 
127   /**
128    * Report progress.
129    */
130   void progress();
131 
132   /**
133    * Set the context.
134    *
135    * @param progressable Progressable
136    */
137   void setProgressable(Progressable progressable);
138 
139   /**
140    * Save potentially modified vertex back to the partition.
141    *
142    * @param vertex Vertex to save
143    */
144   void saveVertex(Vertex<I, V, E> vertex);
145 }