This project has retired. For details please refer to its Attic page.
BrachaTouegDeadlockMessage 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.examples.utils;
20  
21  import java.io.DataInput;
22  import java.io.DataOutput;
23  import java.io.IOException;
24  
25  import org.apache.hadoop.io.Writable;
26  
27  /**
28   * Data sent via a message that includes the source vertex id.
29   */
30  public class BrachaTouegDeadlockMessage implements Writable {
31    /**
32     * Bracha-Toueg NOTICE message. This message is sent by a vertex on all its
33     * outgoing edges.
34     */
35    public static final long NOTIFY = 1;
36    /**
37     * Bracha-Toueg GRANT message. This message is sent by a vertex on all its
38     * incoming edges.
39     */
40    public static final long GRANT = 1 << 1;
41    /**
42     * Bracha-Toueg ACK message. This message is sent by a vertex on its
43     * outgoing edges.
44     */
45    public static final long ACK = 1 << 2;
46    /**
47     * Bracha-Toueg DONE message. This message is sent by a vertex on its
48     * incoming edges.
49     */
50    public static final long DONE = 1 << 3;
51    /** Bracha-Toueg control incoming-edge message */
52    public static final long CTRL_IN_EDGE = 1 << 4;
53  
54    /** Vertex ID of the sender. */
55    private long  senderId;
56    /** Message type. */
57    private long  type;
58  
59    /** Default empty constructor. */
60    public BrachaTouegDeadlockMessage() { /* no action */ }
61  
62    /**
63     * @param id        id of the vertex
64     * @param type      actual message content
65     */
66    public BrachaTouegDeadlockMessage(long id, long type) {
67      this.senderId = id;
68      this.type = type;
69    }
70  
71    @Override
72    public void readFields(DataInput input) throws IOException {
73      senderId = input.readLong();
74      this.type = input.readLong();
75    }
76  
77    @Override
78    public void write(DataOutput output) throws IOException {
79      output.writeLong(senderId);
80      output.writeLong(this.type);
81    }
82  
83    /**
84     * @return long the id
85     */
86    public long getSenderId() {
87      return senderId;
88    }
89  
90    /**
91     * @return long the type
92     */
93    public long getType() {
94      return type;
95    }
96  
97    @Override
98    public String toString() {
99      StringBuffer buffer = new StringBuffer();
100 
101     buffer.append("Message ");
102     buffer.append("{ sender: " +  this.senderId + "; type: ");
103     if (this.type == BrachaTouegDeadlockMessage.NOTIFY) {
104       buffer.append("notify");
105     } else if (this.type == BrachaTouegDeadlockMessage.GRANT) {
106       buffer.append("grant");
107     } else if (this.type == BrachaTouegDeadlockMessage.ACK) {
108       buffer.append("ack");
109     } else if (this.type == BrachaTouegDeadlockMessage.DONE) {
110       buffer.append("done");
111     } else if (this.type == BrachaTouegDeadlockMessage.CTRL_IN_EDGE) {
112       buffer.append("<ctrl>");
113     } else {
114       buffer.append("unknown");
115     }
116     buffer.append(" }");
117 
118     return buffer.toString();
119   }
120 }