View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.client;
21  
22  import java.util.concurrent.ExecutorService;
23  
24  import org.apache.hadoop.hbase.TableName;
25  import org.apache.hadoop.hbase.classification.InterfaceAudience;
26  import org.apache.hadoop.hbase.classification.InterfaceStability;
27  
28  /**
29   * Parameters for instantiating a {@link BufferedMutator}.
30   */
31  @InterfaceAudience.Public
32  @InterfaceStability.Evolving
33  public class BufferedMutatorParams {
34  
35    static final int UNSET = -1;
36  
37    private final TableName tableName;
38    private long writeBufferSize = UNSET;
39    private int maxKeyValueSize = UNSET;
40    private ExecutorService pool = null;
41    private BufferedMutator.ExceptionListener listener = new BufferedMutator.ExceptionListener() {
42      @Override
43      public void onException(RetriesExhaustedWithDetailsException exception,
44          BufferedMutator bufferedMutator)
45          throws RetriesExhaustedWithDetailsException {
46        throw exception;
47      }
48    };
49  
50    public BufferedMutatorParams(TableName tableName) {
51      this.tableName = tableName;
52    }
53  
54    public TableName getTableName() {
55      return tableName;
56    }
57  
58    public long getWriteBufferSize() {
59      return writeBufferSize;
60    }
61  
62    /**
63     * Override the write buffer size specified by the provided {@link Connection}'s
64     * {@link org.apache.hadoop.conf.Configuration} instance, via the configuration key
65     * {@code hbase.client.write.buffer}.
66     */
67    public BufferedMutatorParams writeBufferSize(long writeBufferSize) {
68      this.writeBufferSize = writeBufferSize;
69      return this;
70    }
71  
72    public int getMaxKeyValueSize() {
73      return maxKeyValueSize;
74    }
75  
76    /**
77     * Override the maximum key-value size specified by the provided {@link Connection}'s
78     * {@link org.apache.hadoop.conf.Configuration} instance, via the configuration key
79     * {@code hbase.client.keyvalue.maxsize}.
80     */
81    public BufferedMutatorParams maxKeyValueSize(int maxKeyValueSize) {
82      this.maxKeyValueSize = maxKeyValueSize;
83      return this;
84    }
85  
86    public ExecutorService getPool() {
87      return pool;
88    }
89  
90    /**
91     * Override the default executor pool defined by the {@code hbase.htable.threads.*}
92     * configuration values.
93     */
94    public BufferedMutatorParams pool(ExecutorService pool) {
95      this.pool = pool;
96      return this;
97    }
98  
99    public BufferedMutator.ExceptionListener getListener() {
100     return listener;
101   }
102 
103   /**
104    * Override the default error handler. Default handler simply rethrows the exception.
105    */
106   public BufferedMutatorParams listener(BufferedMutator.ExceptionListener listener) {
107     this.listener = listener;
108     return this;
109   }
110 }