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.utils;
2021import java.io.DataOutput;
22import java.io.IOException;
2324import org.apache.hadoop.io.Writable;
25import org.apache.hadoop.io.WritableComparable;
2627/** Verbose Error mesage for ByteArray based messages */28publicclassVerboseByteStructMessageWrite {
29/**30 * Private Constructor31 */32privateVerboseByteStructMessageWrite() {
33 }
3435/**36 * verboseWriteCurrentMessage37 * de-serialize, then write messages38 *39 * @param iterator iterator40 * @param out DataOutput41 * @param <I> vertexId42 * @param <M> message43 * @throws IOException44 * @throws RuntimeException45 */46publicstatic <I extends WritableComparable, M extends Writable>
47void verboseWriteCurrentMessage(
48 VertexIdMessageIterator<I, M> iterator,
49 DataOutput out
50 ) throws IOException {
51 verboseWriteCurrentMessage(
52 iterator.getCurrentVertexId(), iterator.getCurrentMessage(), out);
53 }
5455/**56 * verboseWriteCurrentMessage57 * de-serialize, then write messages58 *59 * @param vertexId vertexId60 * @param message message61 * @param out DataOutput62 * @param <I> vertexId63 * @param <M> message64 * @throws IOException65 * @throws RuntimeException66 */67publicstatic <I extends WritableComparable, M extends Writable>
68void verboseWriteCurrentMessage(
69 I vertexId,
70 M message,
71 DataOutput out
72 ) throws IOException {
73try {
74 message.write(out);
75 } catch (NegativeArraySizeException e) {
76 handleNegativeArraySize(vertexId);
77 }
78 }
7980/**81 * message to present on NegativeArraySizeException82 *83 * @param vertexId vertexId84 * @param <I> vertexId type85 */86publicstatic <I extends WritableComparable>
87void handleNegativeArraySize(I vertexId) {
88thrownew RuntimeException("The number of bytes sent to vertex " +
89 vertexId + " exceeded the max capacity of its buffer. Please consider" +
90" setting giraph.useBigDataIOForMessages to true. You can do" +
91" this by adding the following option to your command line:" +
92" -Dgiraph.useBigDataIOForMessages=true." +
93" If there are super-vertices in the graph that receive many messages," +
94" setting this option will remove that limit");
95 }
96 }