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.hbase.client; 019 020import java.util.concurrent.ExecutorService; 021import org.apache.hadoop.hbase.TableName; 022import org.apache.yetus.audience.InterfaceAudience; 023 024/** 025 * Parameters for instantiating a {@link BufferedMutator}. 026 */ 027@InterfaceAudience.Public 028public class BufferedMutatorParams implements Cloneable { 029 030 static final int UNSET = -1; 031 032 private final TableName tableName; 033 private long writeBufferSize = UNSET; 034 private long writeBufferPeriodicFlushTimeoutMs = UNSET; 035 private long writeBufferPeriodicFlushTimerTickMs = UNSET; 036 private int maxKeyValueSize = UNSET; 037 private ExecutorService pool = null; 038 private String implementationClassName = null; 039 private int rpcTimeout = UNSET; 040 private int operationTimeout = UNSET; 041 private BufferedMutator.ExceptionListener listener = new BufferedMutator.ExceptionListener() { 042 @Override 043 public void onException(RetriesExhaustedWithDetailsException exception, 044 BufferedMutator bufferedMutator) throws RetriesExhaustedWithDetailsException { 045 throw exception; 046 } 047 }; 048 049 public BufferedMutatorParams(TableName tableName) { 050 this.tableName = tableName; 051 } 052 053 public TableName getTableName() { 054 return tableName; 055 } 056 057 public long getWriteBufferSize() { 058 return writeBufferSize; 059 } 060 061 public BufferedMutatorParams rpcTimeout(final int rpcTimeout) { 062 this.rpcTimeout = rpcTimeout; 063 return this; 064 } 065 066 public int getRpcTimeout() { 067 return rpcTimeout; 068 } 069 070 public BufferedMutatorParams operationTimeout(final int operationTimeout) { 071 this.operationTimeout = operationTimeout; 072 return this; 073 } 074 075 /** 076 * @deprecated Since 2.3.0, will be removed in 4.0.0. Use {@link #operationTimeout(int)} 077 */ 078 @Deprecated 079 public BufferedMutatorParams opertationTimeout(final int operationTimeout) { 080 this.operationTimeout = operationTimeout; 081 return this; 082 } 083 084 public int getOperationTimeout() { 085 return operationTimeout; 086 } 087 088 /** 089 * Override the write buffer size specified by the provided {@link Connection}'s 090 * {@link org.apache.hadoop.conf.Configuration} instance, via the configuration key 091 * {@code hbase.client.write.buffer}. 092 */ 093 public BufferedMutatorParams writeBufferSize(long writeBufferSize) { 094 this.writeBufferSize = writeBufferSize; 095 return this; 096 } 097 098 public long getWriteBufferPeriodicFlushTimeoutMs() { 099 return writeBufferPeriodicFlushTimeoutMs; 100 } 101 102 /** 103 * Set the max timeout before the buffer is automatically flushed. 104 */ 105 public BufferedMutatorParams setWriteBufferPeriodicFlushTimeoutMs(long timeoutMs) { 106 this.writeBufferPeriodicFlushTimeoutMs = timeoutMs; 107 return this; 108 } 109 110 public long getWriteBufferPeriodicFlushTimerTickMs() { 111 return writeBufferPeriodicFlushTimerTickMs; 112 } 113 114 /** 115 * Set the TimerTick how often the buffer timeout if checked. 116 */ 117 public BufferedMutatorParams setWriteBufferPeriodicFlushTimerTickMs(long timerTickMs) { 118 this.writeBufferPeriodicFlushTimerTickMs = timerTickMs; 119 return this; 120 } 121 122 public int getMaxKeyValueSize() { 123 return maxKeyValueSize; 124 } 125 126 /** 127 * Override the maximum key-value size specified by the provided {@link Connection}'s 128 * {@link org.apache.hadoop.conf.Configuration} instance, via the configuration key 129 * {@code hbase.client.keyvalue.maxsize}. 130 */ 131 public BufferedMutatorParams maxKeyValueSize(int maxKeyValueSize) { 132 this.maxKeyValueSize = maxKeyValueSize; 133 return this; 134 } 135 136 public ExecutorService getPool() { 137 return pool; 138 } 139 140 /** 141 * Override the default executor pool defined by the {@code hbase.htable.threads.*} configuration 142 * values. 143 */ 144 public BufferedMutatorParams pool(ExecutorService pool) { 145 this.pool = pool; 146 return this; 147 } 148 149 /** 150 * Returns Name of the class we will use when we construct a {@link BufferedMutator} instance or 151 * null if default implementation. 152 */ 153 public String getImplementationClassName() { 154 return this.implementationClassName; 155 } 156 157 /** 158 * Specify a BufferedMutator implementation other than the default. 159 * @param implementationClassName Name of the BufferedMutator implementation class 160 */ 161 public BufferedMutatorParams implementationClassName(String implementationClassName) { 162 this.implementationClassName = implementationClassName; 163 return this; 164 } 165 166 public BufferedMutator.ExceptionListener getListener() { 167 return listener; 168 } 169 170 /** 171 * Override the default error handler. Default handler simply rethrows the exception. 172 */ 173 public BufferedMutatorParams listener(BufferedMutator.ExceptionListener listener) { 174 this.listener = listener; 175 return this; 176 } 177 178 /* 179 * (non-Javadoc) 180 * @see java.lang.Object#clone() 181 */ 182 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "CN_IDIOM_NO_SUPER_CALL", 183 justification = "The clone below is complete") 184 @Override 185 public BufferedMutatorParams clone() { 186 BufferedMutatorParams clone = new BufferedMutatorParams(this.tableName); 187 clone.writeBufferSize = this.writeBufferSize; 188 clone.writeBufferPeriodicFlushTimeoutMs = this.writeBufferPeriodicFlushTimeoutMs; 189 clone.writeBufferPeriodicFlushTimerTickMs = this.writeBufferPeriodicFlushTimerTickMs; 190 clone.maxKeyValueSize = this.maxKeyValueSize; 191 clone.pool = this.pool; 192 clone.listener = this.listener; 193 clone.implementationClassName = this.implementationClassName; 194 return clone; 195 } 196}