View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.io.hfile;
19  
20  import org.apache.hadoop.hbase.HConstants;
21  import org.apache.hadoop.hbase.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.io.compress.Compression.Algorithm;
23  import org.apache.hadoop.hbase.io.crypto.Encryption;
24  import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
25  import org.apache.hadoop.hbase.util.ChecksumType;
26  
27  /**
28   * A builder that helps in building up the HFileContext 
29   */
30  @InterfaceAudience.Private
31  public class HFileContextBuilder {
32  
33    public static final int DEFAULT_BYTES_PER_CHECKSUM = 16 * 1024;
34  
35    /** Whether checksum is enabled or not **/
36    private boolean usesHBaseChecksum = true;
37    /** Whether mvcc is to be included in the Read/Write **/
38    private boolean includesMvcc = true;
39    /** Whether tags are to be included in the Read/Write **/
40    private boolean includesTags = false;
41    /** Compression algorithm used **/
42    private Algorithm compression = Algorithm.NONE;
43    /** Whether tags to be compressed or not **/
44    private boolean compressTags = false;
45    /** the checksum type **/
46    private ChecksumType checksumType = ChecksumType.getDefaultChecksumType();
47    /** the number of bytes per checksum value **/
48    private int bytesPerChecksum = DEFAULT_BYTES_PER_CHECKSUM;
49    /** Number of uncompressed bytes we allow per block. */
50    private int blocksize = HConstants.DEFAULT_BLOCKSIZE;
51    private DataBlockEncoding encoding = DataBlockEncoding.NONE;
52    /** Crypto context */
53    private Encryption.Context cryptoContext = Encryption.Context.NONE;
54    private long fileCreateTime = 0;
55  
56    private String hfileName = null;
57  
58    public HFileContextBuilder withHBaseCheckSum(boolean useHBaseCheckSum) {
59      this.usesHBaseChecksum = useHBaseCheckSum;
60      return this;
61    }
62  
63    public HFileContextBuilder withIncludesMvcc(boolean includesMvcc) {
64      this.includesMvcc = includesMvcc;
65      return this;
66    }
67  
68    public HFileContextBuilder withIncludesTags(boolean includesTags) {
69      this.includesTags = includesTags;
70      return this;
71    }
72  
73    public HFileContextBuilder withCompression(Algorithm compression) {
74      this.compression = compression;
75      return this;
76    }
77  
78    public HFileContextBuilder withCompressTags(boolean compressTags) {
79      this.compressTags = compressTags;
80      return this;
81    }
82  
83    public HFileContextBuilder withChecksumType(ChecksumType checkSumType) {
84      this.checksumType = checkSumType;
85      return this;
86    }
87  
88    public HFileContextBuilder withBytesPerCheckSum(int bytesPerChecksum) {
89      this.bytesPerChecksum = bytesPerChecksum;
90      return this;
91    }
92  
93    public HFileContextBuilder withBlockSize(int blockSize) {
94      this.blocksize = blockSize;
95      return this;
96    }
97  
98    public HFileContextBuilder withDataBlockEncoding(DataBlockEncoding encoding) {
99      this.encoding = encoding;
100     return this;
101   }
102 
103   public HFileContextBuilder withEncryptionContext(Encryption.Context cryptoContext) {
104     this.cryptoContext = cryptoContext;
105     return this;
106   }
107 
108   public HFileContextBuilder withCreateTime(long fileCreateTime) {
109     this.fileCreateTime = fileCreateTime;
110     return this;
111   }
112 
113   public HFileContextBuilder withHFileName(String name) {
114     this.hfileName = name;
115     return this;
116   }
117 
118   public HFileContext build() {
119     return new HFileContext(usesHBaseChecksum, includesMvcc, includesTags, compression,
120         compressTags, checksumType, bytesPerChecksum, blocksize, encoding, cryptoContext,
121         fileCreateTime, hfileName);
122   }
123 }