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.utils;
20  
21  import org.apache.hadoop.io.Writable;
22  import org.apache.hadoop.io.WritableComparable;
23  
24  import java.io.DataOutput;
25  import java.io.IOException;
26  
27  /** Verbose Error mesage for ByteArray based messages */
28  public class VerboseByteStructMessageWrite {
29    /**
30     * Private Constructor
31     */
32    private VerboseByteStructMessageWrite() {
33    }
34  
35    /**
36     * verboseWriteCurrentMessage
37     * de-serialize, then write messages
38     *
39     * @param iterator iterator
40     * @param out DataOutput
41     * @param <I> vertexId
42     * @param <M> message
43     * @throws IOException
44     * @throws RuntimeException
45     */
46    public static <I extends WritableComparable, M extends Writable> void
47    verboseWriteCurrentMessage(VertexIdMessageIterator<I, M> iterator,
48      DataOutput out) throws IOException {
49      try {
50        iterator.getCurrentMessage().write(out);
51      } catch (NegativeArraySizeException e) {
52        handleNegativeArraySize(iterator.getCurrentVertexId());
53      }
54    }
55  
56    /**
57     * message to present on NegativeArraySizeException
58     *
59     * @param vertexId vertexId
60     * @param <I> vertexId type
61     */
62    public static <I extends WritableComparable> void handleNegativeArraySize(
63        I vertexId) {
64      throw new RuntimeException("The numbers of bytes sent to vertex " +
65          vertexId + " exceeded the max capacity of " +
66          "its ExtendedDataOutput. Please consider setting " +
67          "giraph.useBigDataIOForMessages=true. If there are super-vertices" +
68          " in the graph which receive a lot of messages (total serialized " +
69          "size of messages goes beyond the maximum size of a byte array), " +
70          "setting this option to true will remove that limit");
71    }
72  }