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.driver; 020 021import org.apache.reef.io.network.group.impl.GroupCommunicationMessage; 022import org.apache.reef.io.network.proto.ReefNetworkGroupCommProtos; 023 024/** 025 * The key object used in map to aggregate msgs from. 026 * all the operators before updating state on driver 027 */ 028public class MsgKey { 029 private final String src; 030 private final String dst; 031 private final ReefNetworkGroupCommProtos.GroupCommMessage.Type msgType; 032 033 public MsgKey(final String src, final String dst, final ReefNetworkGroupCommProtos.GroupCommMessage.Type msgType) { 034 this.src = src; 035 this.dst = dst; 036 this.msgType = msgType; 037 } 038 039 public MsgKey(final GroupCommunicationMessage msg) { 040 this.src = msg.getSrcid() + ":" + msg.getSrcVersion(); 041 this.dst = msg.getDestid() + ":" + msg.getVersion(); 042 this.msgType = msg.getType(); 043 } 044 045 public String getSrc() { 046 return src.split(":", 2)[0]; 047 } 048 049 public String getDst() { 050 return dst.split(":", 2)[0]; 051 } 052 053 public ReefNetworkGroupCommProtos.GroupCommMessage.Type getMsgType() { 054 return msgType; 055 } 056 057 @Override 058 public String toString() { 059 return "(" + src + "," + dst + "," + msgType + ")"; 060 } 061 062 @Override 063 public boolean equals(final Object obj) { 064 if (this == obj) { 065 return true; 066 } 067 if (!(obj instanceof MsgKey)) { 068 return false; 069 } 070 final MsgKey that = (MsgKey) obj; 071 if (!this.src.equals(that.src)) { 072 return false; 073 } 074 if (!this.dst.equals(that.dst)) { 075 return false; 076 } 077 if (!this.msgType.equals(that.msgType)) { 078 return false; 079 } 080 return true; 081 } 082 083 @Override 084 public int hashCode() { 085 int result = src.hashCode(); 086 result = 31 * result + dst.hashCode(); 087 result = 31 * result + msgType.hashCode(); 088 return result; 089 } 090}