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 Boolean dropBehind; // null = use server defaults 025 private 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 CachingStrategy duplicate() { 036 return new CachingStrategy(this.dropBehind, this.readahead); 037 } 038 039 public CachingStrategy(Boolean dropBehind, Long readahead) { 040 this.dropBehind = dropBehind; 041 this.readahead = readahead; 042 } 043 044 public Boolean getDropBehind() { 045 return dropBehind; 046 } 047 048 public void setDropBehind(Boolean dropBehind) { 049 this.dropBehind = dropBehind; 050 } 051 052 public Long getReadahead() { 053 return readahead; 054 } 055 056 public void setReadahead(Long readahead) { 057 this.readahead = readahead; 058 } 059 060 public String toString() { 061 return "CachingStrategy(dropBehind=" + dropBehind + 062 ", readahead=" + readahead + ")"; 063 } 064 }