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 package org.apache.hadoop.hdfs.server.datanode;
019
020 /**
021 * The caching strategy we should use for an HDFS read or write operation.
022 */
023 public class CachingStrategy {
024 private final Boolean dropBehind; // null = use server defaults
025 private final Long readahead; // null = use server defaults
026
027 public static CachingStrategy newDefaultStrategy() {
028 return new CachingStrategy(null, null);
029 }
030
031 public static CachingStrategy newDropBehind() {
032 return new CachingStrategy(true, null);
033 }
034
035 public static class Builder {
036 private Boolean dropBehind;
037 private Long readahead;
038
039 public Builder(CachingStrategy prev) {
040 this.dropBehind = prev.dropBehind;
041 this.readahead = prev.readahead;
042 }
043
044 public Builder setDropBehind(Boolean dropBehind) {
045 this.dropBehind = dropBehind;
046 return this;
047 }
048
049 public Builder setReadahead(Long readahead) {
050 this.readahead = readahead;
051 return this;
052 }
053
054 public CachingStrategy build() {
055 return new CachingStrategy(dropBehind, readahead);
056 }
057 }
058
059 public CachingStrategy(Boolean dropBehind, Long readahead) {
060 this.dropBehind = dropBehind;
061 this.readahead = readahead;
062 }
063
064 public Boolean getDropBehind() {
065 return dropBehind;
066 }
067
068 public Long getReadahead() {
069 return readahead;
070 }
071
072 public String toString() {
073 return "CachingStrategy(dropBehind=" + dropBehind +
074 ", readahead=" + readahead + ")";
075 }
076 }