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.examples.utils;
2021import java.io.DataInput;
22import java.io.DataOutput;
23import java.io.IOException;
2425import org.apache.hadoop.io.Writable;
2627/**28 * Data sent via a message that includes the source vertex id.29 */30publicclassBrachaTouegDeadlockMessageimplements Writable {
31/**32 * Bracha-Toueg NOTICE message. This message is sent by a vertex on all its33 * outgoing edges.34 */35publicstaticfinallong NOTIFY = 1;
36/**37 * Bracha-Toueg GRANT message. This message is sent by a vertex on all its38 * incoming edges.39 */40publicstaticfinallong GRANT = 1 << 1;
41/**42 * Bracha-Toueg ACK message. This message is sent by a vertex on its43 * outgoing edges.44 */45publicstaticfinallong ACK = 1 << 2;
46/**47 * Bracha-Toueg DONE message. This message is sent by a vertex on its48 * incoming edges.49 */50publicstaticfinallong DONE = 1 << 3;
51/** Bracha-Toueg control incoming-edge message */52publicstaticfinallong CTRL_IN_EDGE = 1 << 4;
5354/** Vertex ID of the sender. */55privatelong senderId;
56/** Message type. */57privatelong type;
5859/** Default empty constructor. */60publicBrachaTouegDeadlockMessage() { /* no action */ }6162/**63 * @param id id of the vertex64 * @param type actual message content65 */66publicBrachaTouegDeadlockMessage(long id, long type) {
67this.senderId = id;
68this.type = type;
69 }
7071 @Override
72publicvoid readFields(DataInput input) throws IOException {
73 senderId = input.readLong();
74this.type = input.readLong();
75 }
7677 @Override
78publicvoid write(DataOutput output) throws IOException {
79 output.writeLong(senderId);
80 output.writeLong(this.type);
81 }
8283/**84 * @return long the id85 */86publiclong getSenderId() {
87return senderId;
88 }
8990/**91 * @return long the type92 */93publiclong getType() {
94return type;
95 }
9697 @Override
98public String toString() {
99 StringBuffer buffer = new StringBuffer();
100101 buffer.append("Message ");
102 buffer.append("{ sender: " + this.senderId + "; type: ");
103if (this.type == BrachaTouegDeadlockMessage.NOTIFY) {
104 buffer.append("notify");
105 } elseif (this.type == BrachaTouegDeadlockMessage.GRANT) {
106 buffer.append("grant");
107 } elseif (this.type == BrachaTouegDeadlockMessage.ACK) {
108 buffer.append("ack");
109 } elseif (this.type == BrachaTouegDeadlockMessage.DONE) {
110 buffer.append("done");
111 } elseif (this.type == BrachaTouegDeadlockMessage.CTRL_IN_EDGE) {
112 buffer.append("<ctrl>");
113 } else {
114 buffer.append("unknown");
115 }
116 buffer.append(" }");
117118return buffer.toString();
119 }
120 }