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.checkpoint.fs; 020 021import org.apache.hadoop.fs.Path; 022import org.apache.hadoop.io.Text; 023import org.apache.reef.io.checkpoint.CheckpointID; 024 025import java.io.DataInput; 026import java.io.DataOutput; 027import java.io.IOException; 028 029/** 030 * A FileSystem based checkpoint ID contains reference to the Path 031 * where the checkpoint has been saved. 032 */ 033public class FSCheckpointID implements CheckpointID { 034 035 private Path path; 036 037 // CheckpointID extends Hadoop Writable interface that enables serialization 038 // Java serialization requires a (potentially empty) public default constructor 039 public FSCheckpointID(){} 040 041 public FSCheckpointID(final Path path) { 042 this.path = path; 043 } 044 045 public Path getPath() { 046 return path; 047 } 048 049 @Override 050 public String toString() { 051 return path.toString(); 052 } 053 054 @Override 055 public void write(final DataOutput out) throws IOException { 056 Text.writeString(out, path.toString()); 057 } 058 059 @Override 060 public void readFields(final DataInput in) throws IOException { 061 this.path = new Path(Text.readString(in)); 062 } 063 064 @Override 065 public boolean equals(final Object other) { 066 return (other instanceof FSCheckpointID) 067 && path.equals(((FSCheckpointID) other).path); 068 } 069 070 @Override 071 public int hashCode() { 072 return path.hashCode(); 073 } 074 075}