use of org.apache.flume.conf.Configurable in project apex-malhar by apache.
the class FlumeSink method configure.
/* End Configurable Interface */
@SuppressWarnings({ "UseSpecificCatch", "BroadCatchBlock", "TooBroadCatch" })
private static <T> T configure(String key, Class<T> clazz, Context context) {
String classname = context.getString(key);
if (classname == null) {
return null;
}
try {
Class<?> loadClass = Thread.currentThread().getContextClassLoader().loadClass(classname);
if (clazz.isAssignableFrom(loadClass)) {
@SuppressWarnings("unchecked") T object = (T) loadClass.newInstance();
if (object instanceof Configurable) {
Context context1 = new Context(context.getSubProperties(key + '.'));
String id = context1.getString(Storage.ID);
if (id == null) {
id = context.getString(Storage.ID);
logger.debug("{} inherited id={} from sink", key, id);
context1.put(Storage.ID, id);
}
((Configurable) object).configure(context1);
}
return object;
} else {
logger.error("key class {} does not implement {} interface", classname, Storage.class.getCanonicalName());
throw new Error("Invalid storage " + classname);
}
} catch (Error error) {
throw error;
} catch (RuntimeException re) {
throw re;
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
Aggregations