HBASE-14658 Addendum; Allow loading a MonkeyFactory by class name

This commit is contained in:
Elliott Clark 2015-10-22 11:22:53 -07:00
parent 619a240ebd
commit 35660b4f5c
1 changed files with 6 additions and 3 deletions

View File

@ -93,13 +93,16 @@ public abstract class MonkeyFactory {
public static MonkeyFactory getFactory(String factoryName) {
MonkeyFactory fact = FACTORIES.get(factoryName);
if (fact == null) {
if (fact == null && factoryName != null && !factoryName.isEmpty()) {
Class klass = null;
try {
klass = Class.forName(factoryName);
fact = (MonkeyFactory) ReflectionUtils.newInstance(klass);
} catch (ClassNotFoundException e) {
if (klass != null) {
fact = (MonkeyFactory) ReflectionUtils.newInstance(klass);
}
} catch (Exception e) {
LOG.error("Error trying to create " + factoryName + " could not load it by class name");
return null;
}
}
return fact;