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 */1819package org.apache.giraph.bsp;
2021import java.io.DataInput;
22import java.io.DataOutput;
23import java.io.IOException;
2425import org.apache.hadoop.io.Writable;
26import org.apache.hadoop.mapreduce.InputSplit;
2728/**29 * This InputSplit will not give any ordering or location data.30 * It is used internally by BspInputFormat (which determines31 * how many tasks to run the application on). Users should not use this32 * directly.33 */34publicclassBspInputSplitextends InputSplit implements Writable {
35/** Number of splits */36privateint numSplits = -1;
37/** Split index */38privateint splitIndex = -1;
3940/**41 * Reflection constructor.42 */43publicBspInputSplit() { }
4445/**46 * Constructor used by {@link BspInputFormat}.47 *48 * @param splitIndex Index of this split.49 * @param numSplits Total number of splits.50 */51publicBspInputSplit(int splitIndex, int numSplits) {
52this.splitIndex = splitIndex;
53this.numSplits = numSplits;
54 }
5556 @Override
57publiclong getLength() throws IOException, InterruptedException {
58return 0;
59 }
6061 @Override
62public String[] getLocations() throws IOException, InterruptedException {
63returnnew String[]{};
64 }
6566 @Override
67publicvoid readFields(DataInput in) throws IOException {
68 splitIndex = in.readInt();
69 numSplits = in.readInt();
70 }
7172 @Override
73publicvoid write(DataOutput out) throws IOException {
74 out.writeInt(splitIndex);
75 out.writeInt(numSplits);
76 }
7778/**79 * Get the index of this split.80 *81 * @return Index of this split.82 */83publicint getSplitIndex() {
84return splitIndex;
85 }
8687/**88 * Get the number of splits for this application.89 *90 * @return Total number of splits.91 */92publicint getNumSplits() {
93return numSplits;
94 }
9596 @Override
97public String toString() {
98return"'" + getClass().getCanonicalName() +
99", index=" + getSplitIndex() + ", num=" + getNumSplits();
100 }
101 }