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 opertationTimeout(final int operationTimeout) { 074 this.operationTimeout = operationTimeout; 075 return this; 076 } 077 078 public int getOperationTimeout() { 079 return operationTimeout; 080 } 081 082 /** 083 * Override the write buffer size specified by the provided {@link Connection}'s 084 * {@link org.apache.hadoop.conf.Configuration} instance, via the configuration key 085 * {@code hbase.client.write.buffer}. 086 */ 087 public BufferedMutatorParams writeBufferSize(long writeBufferSize) { 088 this.writeBufferSize = writeBufferSize; 089 return this; 090 } 091 092 public long getWriteBufferPeriodicFlushTimeoutMs() { 093 return writeBufferPeriodicFlushTimeoutMs; 094 } 095 096 /** 097 * Set the max timeout before the buffer is automatically flushed. 098 */ 099 public BufferedMutatorParams setWriteBufferPeriodicFlushTimeoutMs(long timeoutMs) { 100 this.writeBufferPeriodicFlushTimeoutMs = timeoutMs; 101 return this; 102 } 103 104 public long getWriteBufferPeriodicFlushTimerTickMs() { 105 return writeBufferPeriodicFlushTimerTickMs; 106 } 107 108 /** 109 * Set the TimerTick how often the buffer timeout if checked. 110 */ 111 public BufferedMutatorParams setWriteBufferPeriodicFlushTimerTickMs(long timerTickMs) { 112 this.writeBufferPeriodicFlushTimerTickMs = timerTickMs; 113 return this; 114 } 115 116 public int getMaxKeyValueSize() { 117 return maxKeyValueSize; 118 } 119 120 /** 121 * Override the maximum key-value size specified by the provided {@link Connection}'s 122 * {@link org.apache.hadoop.conf.Configuration} instance, via the configuration key 123 * {@code hbase.client.keyvalue.maxsize}. 124 */ 125 public BufferedMutatorParams maxKeyValueSize(int maxKeyValueSize) { 126 this.maxKeyValueSize = maxKeyValueSize; 127 return this; 128 } 129 130 public ExecutorService getPool() { 131 return pool; 132 } 133 134 /** 135 * Override the default executor pool defined by the {@code hbase.htable.threads.*} 136 * configuration values. 137 */ 138 public BufferedMutatorParams pool(ExecutorService pool) { 139 this.pool = pool; 140 return this; 141 } 142 143 /** 144 * @return Name of the class we will use when we construct a 145 * {@link BufferedMutator} instance or null if default implementation. 146 */ 147 public String getImplementationClassName() { 148 return this.implementationClassName; 149 } 150 151 /** 152 * Specify a BufferedMutator implementation other than the default. 153 * @param implementationClassName Name of the BufferedMutator implementation class 154 */ 155 public BufferedMutatorParams implementationClassName(String implementationClassName) { 156 this.implementationClassName = implementationClassName; 157 return this; 158 } 159 160 public BufferedMutator.ExceptionListener getListener() { 161 return listener; 162 } 163 164 /** 165 * Override the default error handler. Default handler simply rethrows the exception. 166 */ 167 public BufferedMutatorParams listener(BufferedMutator.ExceptionListener listener) { 168 this.listener = listener; 169 return this; 170 } 171 172 /* 173 * (non-Javadoc) 174 * 175 * @see java.lang.Object#clone() 176 */ 177 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="CN_IDIOM_NO_SUPER_CALL", 178 justification="The clone below is complete") 179 @Override 180 public BufferedMutatorParams clone() { 181 BufferedMutatorParams clone = new BufferedMutatorParams(this.tableName); 182 clone.writeBufferSize = this.writeBufferSize; 183 clone.writeBufferPeriodicFlushTimeoutMs = this.writeBufferPeriodicFlushTimeoutMs; 184 clone.writeBufferPeriodicFlushTimerTickMs = this.writeBufferPeriodicFlushTimerTickMs; 185 clone.maxKeyValueSize = this.maxKeyValueSize; 186 clone.pool = this.pool; 187 clone.listener = this.listener; 188 clone.implementationClassName = this.implementationClassName; 189 return clone; 190 } 191}