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, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.apache.hadoop.yarn.api.records; 020 021import org.apache.hadoop.classification.InterfaceAudience; 022import org.apache.hadoop.classification.InterfaceStability; 023import org.apache.hadoop.yarn.util.Records; 024 025/** 026 * An object that encapsulates an updated container and the 027 * type of Update. 028 */ 029@InterfaceAudience.Public 030@InterfaceStability.Unstable 031public abstract class UpdatedContainer { 032 033 /** 034 * Static Factory method. 035 * 036 * @param updateType ContainerUpdateType 037 * @param container Container 038 * @return UpdatedContainer 039 */ 040 @InterfaceAudience.Public 041 @InterfaceStability.Unstable 042 public static UpdatedContainer newInstance(ContainerUpdateType updateType, 043 Container container) { 044 UpdatedContainer updatedContainer = 045 Records.newRecord(UpdatedContainer.class); 046 updatedContainer.setUpdateType(updateType); 047 updatedContainer.setContainer(container); 048 return updatedContainer; 049 } 050 051 /** 052 * Get the <code>ContainerUpdateType</code>. 053 * @return ContainerUpdateType 054 */ 055 public abstract ContainerUpdateType getUpdateType(); 056 057 /** 058 * Set the <code>ContainerUpdateType</code>. 059 * @param updateType ContainerUpdateType 060 */ 061 public abstract void setUpdateType(ContainerUpdateType updateType); 062 063 /** 064 * Get the <code>Container</code>. 065 * @return Container 066 */ 067 public abstract Container getContainer(); 068 069 /** 070 * Set the <code>Container</code>. 071 * @param container Container 072 */ 073 public abstract void setContainer(Container container); 074 075 @Override 076 public int hashCode() { 077 final int prime = 2153; 078 int result = 2459; 079 ContainerUpdateType updateType = getUpdateType(); 080 Container container = getContainer(); 081 result = prime * result + ((updateType == null) ? 0 : 082 updateType.hashCode()); 083 result = prime * result + ((container == null) ? 0 : container.hashCode()); 084 return result; 085 } 086 087 @Override 088 public boolean equals(Object obj) { 089 if (this == obj) { 090 return true; 091 } 092 if (obj == null) { 093 return false; 094 } 095 if (getClass() != obj.getClass()) { 096 return false; 097 } 098 UpdatedContainer other = (UpdatedContainer) obj; 099 ContainerUpdateType updateType = getUpdateType(); 100 if (updateType == null) { 101 if (other.getUpdateType() != null) { 102 return false; 103 } 104 } else if (updateType != other.getUpdateType()) { 105 return false; 106 } 107 Container container = getContainer(); 108 if (container == null) { 109 if (other.getContainer() != null) { 110 return false; 111 } 112 } else if (!container.equals(other.getContainer())) { 113 return false; 114 } 115 return true; 116 } 117 118}