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 */ 018package org.apache.hadoop.hdfs; 019 020import org.apache.hadoop.classification.InterfaceAudience; 021import org.apache.hadoop.classification.InterfaceStability; 022import org.apache.hadoop.conf.Configuration; 023 024/** 025 * The public API for creating a new ReplicaAccessor. 026 */ 027@InterfaceAudience.Public 028@InterfaceStability.Stable 029public abstract class ReplicaAccessorBuilder { 030 /** 031 * Set the file name which is being opened. Provided for debugging purposes. 032 */ 033 public abstract ReplicaAccessorBuilder setFileName(String fileName); 034 035 /** Set the block ID and block pool ID which are being opened. */ 036 public abstract ReplicaAccessorBuilder 037 setBlock(long blockId, String blockPoolId); 038 039 /** 040 * Set whether checksums must be verified. Checksums should be skipped if 041 * the user has disabled checksum verification in the configuration. Users 042 * may wish to do this if their software does checksum verification at a 043 * higher level than HDFS. 044 */ 045 public abstract ReplicaAccessorBuilder 046 setVerifyChecksum(boolean verifyChecksum); 047 048 /** Set the name of the HDFS client. Provided for debugging purposes. */ 049 public abstract ReplicaAccessorBuilder setClientName(String clientName); 050 051 /** 052 * Set whether short-circuit is enabled. Short-circuit may be disabled if 053 * the user has set dfs.client.read.shortcircuit to false, or if the block 054 * being read is under construction. The fact that this bit is enabled does 055 * not mean that the user has permission to do short-circuit reads or to 056 * access the replica-- that must be checked separately by the 057 * ReplicaAccessorBuilder implementation. 058 */ 059 public abstract ReplicaAccessorBuilder 060 setAllowShortCircuitReads(boolean allowShortCircuit); 061 062 /** 063 * Set the length of the replica which is visible to this client. If bytes 064 * are added later, they will not be visible to the ReplicaAccessor we are 065 * building. In order to see more of the replica, the client must re-open 066 * this HDFS file. The visible length provides an upper bound, but not a 067 * lower one. If the replica is deleted or truncated, fewer bytes may be 068 * visible than specified here. 069 */ 070 public abstract ReplicaAccessorBuilder setVisibleLength(long visibleLength); 071 072 /** 073 * Set the configuration to use. ReplicaAccessorBuilder subclasses should 074 * define their own configuration prefix. For example, the foobar plugin 075 * could look for configuration keys like foo.bar.parameter1, 076 * foo.bar.parameter2. 077 */ 078 public abstract ReplicaAccessorBuilder setConfiguration(Configuration conf); 079 080 /** 081 * Set the block access token to use. 082 */ 083 public abstract ReplicaAccessorBuilder setBlockAccessToken(byte[] token); 084 085 /** 086 * Build a new ReplicaAccessor. 087 * 088 * The implementation must perform any necessary access checks before 089 * constructing the ReplicaAccessor. If there is a hardware-level or 090 * network-level setup operation that could fail, it should be done here. If 091 * the implementation returns a ReplicaAccessor, we will assume that it works 092 * and not attempt to construct a normal BlockReader. 093 * 094 * If the ReplicaAccessor could not be built, implementations may wish to log 095 * a message at TRACE level indicating why. 096 * 097 * @return null if the ReplicaAccessor could not be built; the 098 * ReplicaAccessor otherwise. 099 */ 100 public abstract ReplicaAccessor build(); 101}