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.regionserver;
19
20 import org.apache.hadoop.conf.Configurable;
21 import org.apache.hadoop.conf.Configuration;
22 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
23 import org.apache.hadoop.hbase.classification.InterfaceAudience;
24 import org.apache.hadoop.hbase.classification.InterfaceStability;
25 import org.apache.hadoop.hbase.util.ReflectionUtils;
26
27 /**
28 * A factory for creating SplitTransactions, which execute region split as a "transaction".
29 * See {@link SplitTransaction}
30 */
31 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
32 @InterfaceStability.Evolving
33 public class SplitTransactionFactory implements Configurable {
34
35 public static final String SPLIT_TRANSACTION_IMPL_KEY =
36 "hbase.regionserver.split.transaction.impl";
37
38 private Configuration conf;
39
40 public SplitTransactionFactory(Configuration conf) {
41 this.conf = conf;
42 }
43
44 @Override
45 public Configuration getConf() {
46 return conf;
47 }
48
49 @Override
50 public void setConf(Configuration conf) {
51 this.conf = conf;
52 }
53
54 /**
55 * Create a split transaction
56 * @param r the region to split
57 * @param splitrow the split point in the keyspace
58 * @return transaction instance
59 */
60 public SplitTransaction create(final Region r, final byte [] splitrow) {
61 return ReflectionUtils.instantiateWithCustomCtor(
62 // The implementation class must extend SplitTransactionImpl, not only
63 // implement the SplitTransaction interface like you might expect,
64 // because various places such as AssignmentManager use static methods
65 // from SplitTransactionImpl. Whatever we use for implementation must
66 // be compatible, so it's safest to require ? extends SplitTransactionImpl.
67 // If not compatible we will throw a runtime exception from here.
68 conf.getClass(SPLIT_TRANSACTION_IMPL_KEY, SplitTransactionImpl.class,
69 SplitTransactionImpl.class).getName(),
70 new Class[] { Region.class, byte[].class },
71 new Object[] { r, splitrow });
72 }
73
74 }