Search in sources :

Example 1 with Configurable

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);
    }
}
Also used : Context(org.apache.flume.Context) Storage(org.apache.apex.malhar.flume.storage.Storage) NetletRuntimeException(com.datatorrent.netlet.NetletThrowable.NetletRuntimeException) ServiceConfigurationError(java.util.ServiceConfigurationError) IOError(java.io.IOError) NetletThrowable(com.datatorrent.netlet.NetletThrowable) Configurable(org.apache.flume.conf.Configurable)

Aggregations

NetletThrowable (com.datatorrent.netlet.NetletThrowable)1 NetletRuntimeException (com.datatorrent.netlet.NetletThrowable.NetletRuntimeException)1 IOError (java.io.IOError)1 ServiceConfigurationError (java.util.ServiceConfigurationError)1 Storage (org.apache.apex.malhar.flume.storage.Storage)1 Context (org.apache.flume.Context)1 Configurable (org.apache.flume.conf.Configurable)1