blob: a13f3f1e3677cc18ec1b75d937e85412f81729d0 [file] [log] [blame]
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.tez.runtime.library.common;
import org.apache.hadoop.classification.InterfaceAudience.Private;
/**
* Container for a task number and an attempt number for the task.
*/
@Private
public class InputAttemptIdentifier {
private final InputIdentifier inputIdentifier;
private final int attemptNumber;
private String pathComponent;
public InputAttemptIdentifier(int taskIndex, int attemptNumber) {
this(new InputIdentifier(taskIndex), attemptNumber, null);
}
public InputAttemptIdentifier(InputIdentifier inputIdentifier, int attemptNumber, String pathComponent) {
this.inputIdentifier = inputIdentifier;
this.attemptNumber = attemptNumber;
this.pathComponent = pathComponent;
}
public InputAttemptIdentifier(int taskIndex, int attemptNumber, String pathComponent) {
this(new InputIdentifier(taskIndex), attemptNumber, pathComponent);
}
public InputIdentifier getInputIdentifier() {
return this.inputIdentifier;
}
public int getAttemptNumber() {
return attemptNumber;
}
public String getPathComponent() {
return pathComponent;
}
// PathComponent does not need to be part of the hashCode and equals computation.
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + attemptNumber;
result = prime * result
+ ((inputIdentifier == null) ? 0 : inputIdentifier.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
InputAttemptIdentifier other = (InputAttemptIdentifier) obj;
if (attemptNumber != other.attemptNumber)
return false;
if (inputIdentifier == null) {
if (other.inputIdentifier != null)
return false;
} else if (!inputIdentifier.equals(other.inputIdentifier))
return false;
return true;
}
@Override
public String toString() {
return "InputAttemptIdentifier [inputIdentifier=" + inputIdentifier
+ ", attemptNumber=" + attemptNumber + ", pathComponent="
+ pathComponent + "]";
}
}