001/** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020package org.apache.hadoop.hbase.client; 021 022import java.util.concurrent.ExecutorService; 023import org.apache.hadoop.hbase.TableName; 024import org.apache.yetus.audience.InterfaceAudience; 025 026/** 027 * Parameters for instantiating a {@link BufferedMutator}. 028 */ 029@InterfaceAudience.Public 030public class BufferedMutatorParams implements Cloneable { 031 032 static final int UNSET = -1; 033 034 private final TableName tableName; 035 private long writeBufferSize = UNSET; 036 private long writeBufferPeriodicFlushTimeoutMs = UNSET; 037 private long writeBufferPeriodicFlushTimerTickMs = UNSET; 038 private int maxKeyValueSize = UNSET; 039 private ExecutorService pool = null; 040 private String implementationClassName = null; 041 private int rpcTimeout = UNSET; 042 private int operationTimeout = UNSET; 043 private BufferedMutator.ExceptionListener listener = new BufferedMutator.ExceptionListener() { 044 @Override 045 public void onException(RetriesExhaustedWithDetailsException exception, 046 BufferedMutator bufferedMutator) 047 throws RetriesExhaustedWithDetailsException { 048 throw exception; 049 } 050 }; 051 052 public BufferedMutatorParams(TableName tableName) { 053 this.tableName = tableName; 054 } 055 056 public TableName getTableName() { 057 return tableName; 058 } 059 060 public long getWriteBufferSize() { 061 return writeBufferSize; 062 } 063 064 public BufferedMutatorParams rpcTimeout(final int rpcTimeout) { 065 this.rpcTimeout = rpcTimeout; 066 return this; 067 } 068 069 public int getRpcTimeout() { 070 return rpcTimeout; 071 } 072 073 public BufferedMutatorParams operationTimeout(final int operationTimeout) { 074 this.operationTimeout = operationTimeout; 075 return this; 076 } 077 078 /** 079 * @deprecated Since 2.3.0, will be removed in 4.0.0. Use {@link #operationTimeout(int)} 080 */ 081 @Deprecated 082 public BufferedMutatorParams opertationTimeout(final int operationTimeout) { 083 this.operationTimeout = operationTimeout; 084 return this; 085 } 086 087 public int getOperationTimeout() { 088 return operationTimeout; 089 } 090 091 /** 092 * Override the write buffer size specified by the provided {@link Connection}'s 093 * {@link org.apache.hadoop.conf.Configuration} instance, via the configuration key 094 * {@code hbase.client.write.buffer}. 095 */ 096 public BufferedMutatorParams writeBufferSize(long writeBufferSize) { 097 this.writeBufferSize = writeBufferSize; 098 return this; 099 } 100 101 public long getWriteBufferPeriodicFlushTimeoutMs() { 102 return writeBufferPeriodicFlushTimeoutMs; 103 } 104 105 /** 106 * Set the max timeout before the buffer is automatically flushed. 107 */ 108 public BufferedMutatorParams setWriteBufferPeriodicFlushTimeoutMs(long timeoutMs) { 109 this.writeBufferPeriodicFlushTimeoutMs = timeoutMs; 110 return this; 111 } 112 113 public long getWriteBufferPeriodicFlushTimerTickMs() { 114 return writeBufferPeriodicFlushTimerTickMs; 115 } 116 117 /** 118 * Set the TimerTick how often the buffer timeout if checked. 119 */ 120 public BufferedMutatorParams setWriteBufferPeriodicFlushTimerTickMs(long timerTickMs) { 121 this.writeBufferPeriodicFlushTimerTickMs = timerTickMs; 122 return this; 123 } 124 125 public int getMaxKeyValueSize() { 126 return maxKeyValueSize; 127 } 128 129 /** 130 * Override the maximum key-value size specified by the provided {@link Connection}'s 131 * {@link org.apache.hadoop.conf.Configuration} instance, via the configuration key 132 * {@code hbase.client.keyvalue.maxsize}. 133 */ 134 public BufferedMutatorParams maxKeyValueSize(int maxKeyValueSize) { 135 this.maxKeyValueSize = maxKeyValueSize; 136 return this; 137 } 138 139 public ExecutorService getPool() { 140 return pool; 141 } 142 143 /** 144 * Override the default executor pool defined by the {@code hbase.htable.threads.*} 145 * configuration values. 146 */ 147 public BufferedMutatorParams pool(ExecutorService pool) { 148 this.pool = pool; 149 return this; 150 } 151 152 /** 153 * @return Name of the class we will use when we construct a 154 * {@link BufferedMutator} instance or null if default implementation. 155 */ 156 public String getImplementationClassName() { 157 return this.implementationClassName; 158 } 159 160 /** 161 * Specify a BufferedMutator implementation other than the default. 162 * @param implementationClassName Name of the BufferedMutator implementation class 163 */ 164 public BufferedMutatorParams implementationClassName(String implementationClassName) { 165 this.implementationClassName = implementationClassName; 166 return this; 167 } 168 169 public BufferedMutator.ExceptionListener getListener() { 170 return listener; 171 } 172 173 /** 174 * Override the default error handler. Default handler simply rethrows the exception. 175 */ 176 public BufferedMutatorParams listener(BufferedMutator.ExceptionListener listener) { 177 this.listener = listener; 178 return this; 179 } 180 181 /* 182 * (non-Javadoc) 183 * 184 * @see java.lang.Object#clone() 185 */ 186 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="CN_IDIOM_NO_SUPER_CALL", 187 justification="The clone below is complete") 188 @Override 189 public BufferedMutatorParams clone() { 190 BufferedMutatorParams clone = new BufferedMutatorParams(this.tableName); 191 clone.writeBufferSize = this.writeBufferSize; 192 clone.writeBufferPeriodicFlushTimeoutMs = this.writeBufferPeriodicFlushTimeoutMs; 193 clone.writeBufferPeriodicFlushTimerTickMs = this.writeBufferPeriodicFlushTimerTickMs; 194 clone.maxKeyValueSize = this.maxKeyValueSize; 195 clone.pool = this.pool; 196 clone.listener = this.listener; 197 clone.implementationClassName = this.implementationClassName; 198 return clone; 199 } 200}