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.protocol;
019
020import org.apache.hadoop.classification.InterfaceAudience;
021import org.apache.hadoop.classification.InterfaceStability;
022
023/**
024 * Describes a path-based cache directive.
025 */
026@InterfaceStability.Evolving
027@InterfaceAudience.Public
028public class CacheDirectiveStats {
029  public static class Builder {
030    private long bytesNeeded;
031    private long bytesCached;
032    private long filesNeeded;
033    private long filesCached;
034    private boolean hasExpired;
035
036    /**
037     * Builds a new CacheDirectiveStats populated with the set properties.
038     * 
039     * @return New CacheDirectiveStats.
040     */
041    public CacheDirectiveStats build() {
042      return new CacheDirectiveStats(bytesNeeded, bytesCached, filesNeeded,
043          filesCached, hasExpired);
044    }
045
046    /**
047     * Creates an empty builder.
048     */
049    public Builder() {
050    }
051
052    /**
053     * Sets the bytes needed by this directive.
054     * 
055     * @param bytesNeeded The bytes needed.
056     * @return This builder, for call chaining.
057     */
058    public Builder setBytesNeeded(long bytesNeeded) {
059      this.bytesNeeded = bytesNeeded;
060      return this;
061    }
062
063    /**
064     * Sets the bytes cached by this directive.
065     * 
066     * @param bytesCached The bytes cached.
067     * @return This builder, for call chaining.
068     */
069    public Builder setBytesCached(long bytesCached) {
070      this.bytesCached = bytesCached;
071      return this;
072    }
073
074    /**
075     * Sets the files needed by this directive.
076     * @param filesNeeded The number of files needed
077     * @return This builder, for call chaining.
078     */
079    public Builder setFilesNeeded(long filesNeeded) {
080      this.filesNeeded = filesNeeded;
081      return this;
082    }
083
084    /**
085     * Sets the files cached by this directive.
086     * 
087     * @param filesCached The number of files cached.
088     * @return This builder, for call chaining.
089     */
090    public Builder setFilesCached(long filesCached) {
091      this.filesCached = filesCached;
092      return this;
093    }
094
095    /**
096     * Sets whether this directive has expired.
097     * 
098     * @param hasExpired if this directive has expired
099     * @return This builder, for call chaining.
100     */
101    public Builder setHasExpired(boolean hasExpired) {
102      this.hasExpired = hasExpired;
103      return this;
104    }
105  }
106
107  private final long bytesNeeded;
108  private final long bytesCached;
109  private final long filesNeeded;
110  private final long filesCached;
111  private final boolean hasExpired;
112
113  private CacheDirectiveStats(long bytesNeeded, long bytesCached,
114      long filesNeeded, long filesCached, boolean hasExpired) {
115    this.bytesNeeded = bytesNeeded;
116    this.bytesCached = bytesCached;
117    this.filesNeeded = filesNeeded;
118    this.filesCached = filesCached;
119    this.hasExpired = hasExpired;
120  }
121
122  /**
123   * @return The bytes needed.
124   */
125  public long getBytesNeeded() {
126    return bytesNeeded;
127  }
128
129  /**
130   * @return The bytes cached.
131   */
132  public long getBytesCached() {
133    return bytesCached;
134  }
135
136  /**
137   * @return The number of files needed.
138   */
139  public long getFilesNeeded() {
140    return filesNeeded;
141  }
142
143  /**
144   * @return The number of files cached.
145   */
146  public long getFilesCached() {
147    return filesCached;
148  }
149
150  /**
151   * @return Whether this directive has expired.
152   */
153  public boolean hasExpired() {
154    return hasExpired;
155  }
156
157  @Override
158  public String toString() {
159    StringBuilder builder = new StringBuilder();
160    builder.append("{");
161    builder.append("bytesNeeded: ").append(bytesNeeded);
162    builder.append(", ").append("bytesCached: ").append(bytesCached);
163    builder.append(", ").append("filesNeeded: ").append(filesNeeded);
164    builder.append(", ").append("filesCached: ").append(filesCached);
165    builder.append(", ").append("hasExpired: ").append(hasExpired);
166    builder.append("}");
167    return builder.toString();
168  }
169};