This project has retired. For details please refer to its Attic page.
Source code
001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.io.network.group.impl;
020
021import org.apache.reef.io.network.group.impl.utils.Utils;
022import org.apache.reef.io.network.proto.ReefNetworkGroupCommProtos;
023
024import java.util.Arrays;
025
026/**
027 * Group Communication Message.
028 */
029public class GroupCommunicationMessage {
030  private final String groupName;
031  private final String operName;
032  private final ReefNetworkGroupCommProtos.GroupCommMessage.Type msgType;
033  private final String from;
034  private final int srcVersion;
035  private final String to;
036  private final int dstVersion;
037  private final byte[][] data;
038
039  private final String simpleGroupName;
040  private final String simpleOperName;
041
042  public GroupCommunicationMessage(
043      final String groupName,
044      final String operName,
045      final ReefNetworkGroupCommProtos.GroupCommMessage.Type msgType,
046      final String from, final int srcVersion,
047      final String to, final int dstVersion,
048      final byte[][] data) {
049    super();
050    this.groupName = groupName;
051    this.operName = operName;
052    this.msgType = msgType;
053    this.from = from;
054    this.srcVersion = srcVersion;
055    this.to = to;
056    this.dstVersion = dstVersion;
057    this.data = data;
058    this.simpleGroupName = Utils.simpleName(Utils.getClass(groupName));
059    this.simpleOperName = Utils.simpleName(Utils.getClass(operName));
060  }
061
062  public String getGroupname() {
063    return groupName;
064  }
065
066  public String getOperatorname() {
067    return operName;
068  }
069
070  public String getSimpleOperName() {
071    return simpleOperName;
072  }
073
074  public ReefNetworkGroupCommProtos.GroupCommMessage.Type getType() {
075    return msgType;
076  }
077
078  public String getSrcid() {
079    return from;
080  }
081
082  public int getSrcVersion() {
083    return srcVersion;
084  }
085
086  public String getDestid() {
087    return to;
088  }
089
090  public int getVersion() {
091    return dstVersion;
092  }
093
094  public String getSource() {
095    return "(" + getSrcid() + "," + getSrcVersion() + ")";
096  }
097
098  public String getDestination() {
099    return "(" + getDestid() + "," + getVersion() + ")";
100  }
101
102  public byte[][] getData() {
103    return data;
104  }
105
106  public int getMsgsCount() {
107    return data.length;
108  }
109
110  public boolean hasVersion() {
111    return true;
112  }
113
114  public boolean hasSrcVersion() {
115    return true;
116  }
117
118  @Override
119  public String toString() {
120    return "[" + msgType + " from " + getSource() + " to " + getDestination() + " for " + simpleGroupName + ":" +
121        simpleOperName + "]";
122  }
123
124  @Override
125  public boolean equals(final Object obj) {
126    if (this != obj) {
127      if (obj instanceof GroupCommunicationMessage) {
128        final GroupCommunicationMessage that = (GroupCommunicationMessage) obj;
129        if (!this.groupName.equals(that.groupName)) {
130          return false;
131        }
132        if (!this.operName.equals(that.operName)) {
133          return false;
134        }
135        if (!this.from.equals(that.from)) {
136          return false;
137        }
138        if (this.srcVersion != that.srcVersion) {
139          return false;
140        }
141        if (!this.to.equals(that.to)) {
142          return false;
143        }
144        if (this.dstVersion != that.dstVersion) {
145          return false;
146        }
147        if (!this.msgType.equals(that.msgType)) {
148          return false;
149        }
150        if (this.data.length != that.data.length) {
151          return false;
152        }
153        for (int i = 0; i < data.length; i++) {
154          if (!Arrays.equals(this.data[i], that.data[i])) {
155            return false;
156          }
157        }
158
159        return true;
160      } else {
161        return false;
162      }
163    } else {
164      return true;
165    }
166
167  }
168
169  @Override
170  public int hashCode() {
171    int result = groupName.hashCode();
172    result = 31 * result + operName.hashCode();
173    result = 31 * result + msgType.hashCode();
174    result = 31 * result + from.hashCode();
175    result = 31 * result + srcVersion;
176    result = 31 * result + to.hashCode();
177    result = 31 * result + dstVersion;
178    result = 31 * result + Arrays.deepHashCode(data);
179    return result;
180  }
181}