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.quotas; 019 020import java.util.Objects; 021import org.apache.hadoop.conf.Configuration; 022import org.apache.yetus.audience.InterfaceAudience; 023 024/** 025 * Factory for creating {@link SpaceQuotaSnapshotNotifier} implementations. Implementations must 026 * have a no-args constructor. 027 */ 028@InterfaceAudience.Private 029public class SpaceQuotaSnapshotNotifierFactory { 030 private static final SpaceQuotaSnapshotNotifierFactory INSTANCE = 031 new SpaceQuotaSnapshotNotifierFactory(); 032 033 public static final String SNAPSHOT_NOTIFIER_KEY = "hbase.master.quota.snapshot.notifier.impl"; 034 public static final Class<? extends SpaceQuotaSnapshotNotifier> SNAPSHOT_NOTIFIER_DEFAULT = 035 TableSpaceQuotaSnapshotNotifier.class; 036 037 // Private 038 private SpaceQuotaSnapshotNotifierFactory() { 039 } 040 041 public static SpaceQuotaSnapshotNotifierFactory getInstance() { 042 return INSTANCE; 043 } 044 045 /** 046 * Instantiates the {@link SpaceQuotaSnapshotNotifier} implementation as defined in the 047 * configuration provided. 048 * @param conf Configuration object 049 * @return The SpaceQuotaSnapshotNotifier implementation 050 * @throws IllegalArgumentException if the class could not be instantiated 051 */ 052 public SpaceQuotaSnapshotNotifier create(Configuration conf) { 053 Class<? extends SpaceQuotaSnapshotNotifier> clz = Objects.requireNonNull(conf) 054 .getClass(SNAPSHOT_NOTIFIER_KEY, SNAPSHOT_NOTIFIER_DEFAULT, SpaceQuotaSnapshotNotifier.class); 055 try { 056 return clz.getDeclaredConstructor().newInstance(); 057 } catch (Exception e) { 058 throw new IllegalArgumentException("Failed to instantiate the implementation", e); 059 } 060 } 061}