Search in sources :

Example 1 with Storage

use of org.apache.apex.malhar.flume.storage.Storage 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)

Example 2 with Storage

use of org.apache.apex.malhar.flume.storage.Storage in project apex-malhar by apache.

the class FlumeSink method configure.

/* End implementing Flume Sink interface */
/* Begin Configurable Interface */
@Override
public void configure(Context context) {
    hostname = context.getString(HOSTNAME_STRING, HOSTNAME_DEFAULT);
    port = context.getInteger("port", 0);
    id = context.getString("id");
    if (id == null) {
        id = getName();
    }
    acceptedTolerance = context.getLong("acceptedTolerance", ACCEPTED_TOLERANCE);
    sleepMillis = context.getLong("sleepMillis", 5L);
    throughputAdjustmentFactor = context.getInteger("throughputAdjustmentPercent", 5) / 100.0;
    maximumEventsPerTransaction = context.getInteger("maximumEventsPerTransaction", 10000);
    minimumEventsPerTransaction = context.getInteger("minimumEventsPerTransaction", 100);
    commitEventTimeoutMillis = context.getLong("commitEventTimeoutMillis", Long.MAX_VALUE);
    @SuppressWarnings("unchecked") Discovery<byte[]> ldiscovery = configure("discovery", Discovery.class, context);
    if (ldiscovery == null) {
        logger.warn("Discovery agent not configured for the sink!");
        discovery = new Discovery<byte[]>() {

            @Override
            public void unadvertise(Service<byte[]> service) {
                logger.debug("Sink {} stopped listening on {}:{}", service.getId(), service.getHost(), service.getPort());
            }

            @Override
            public void advertise(Service<byte[]> service) {
                logger.debug("Sink {} started listening on {}:{}", service.getId(), service.getHost(), service.getPort());
            }

            @Override
            @SuppressWarnings("unchecked")
            public Collection<Service<byte[]>> discover() {
                return Collections.EMPTY_SET;
            }
        };
    } else {
        discovery = ldiscovery;
    }
    storage = configure("storage", Storage.class, context);
    if (storage == null) {
        logger.warn("storage key missing... FlumeSink may lose data!");
        storage = new Storage() {

            @Override
            public byte[] store(Slice slice) {
                return null;
            }

            @Override
            public byte[] retrieve(byte[] identifier) {
                return null;
            }

            @Override
            public byte[] retrieveNext() {
                return null;
            }

            @Override
            public void clean(byte[] identifier) {
            }

            @Override
            public void flush() {
            }
        };
    }
    @SuppressWarnings("unchecked") StreamCodec<Event> lCodec = configure("codec", StreamCodec.class, context);
    if (lCodec == null) {
        codec = new EventCodec();
    } else {
        codec = lCodec;
    }
}
Also used : Storage(org.apache.apex.malhar.flume.storage.Storage) Slice(com.datatorrent.netlet.util.Slice) Collection(java.util.Collection) Event(org.apache.flume.Event) EventCodec(org.apache.apex.malhar.flume.storage.EventCodec)

Aggregations

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