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.group.impl.utils.Utils; 023import org.apache.reef.tang.annotations.Name; 024 025/** 026 * Helper class to wrap msg and the operator name in the msg. 027 */ 028public class IndexedMsg { 029 private final Class<? extends Name<String>> operName; 030 private final GroupCommunicationMessage msg; 031 032 public IndexedMsg(final GroupCommunicationMessage msg) { 033 super(); 034 this.operName = Utils.getClass(msg.getOperatorname()); 035 this.msg = msg; 036 } 037 038 public Class<? extends Name<String>> getOperName() { 039 return operName; 040 } 041 042 public GroupCommunicationMessage getMsg() { 043 return msg; 044 } 045 046 @Override 047 public int hashCode() { 048 return operName.getName().hashCode(); 049 } 050 051 @Override 052 public boolean equals(final Object obj) { 053 if (this == obj) { 054 return true; 055 } 056 if (!(obj instanceof IndexedMsg)) { 057 return false; 058 } 059 final IndexedMsg that = (IndexedMsg) obj; 060 if (this.operName == that.operName) { 061 return true; 062 } 063 return false; 064 } 065 066 @Override 067 public String toString() { 068 return operName.getSimpleName(); 069 } 070 071}