Search in sources :

Example 1 with PollableSource

use of org.apache.flume.PollableSource in project nifi by apache.

the class ExecuteFlumeSource method stopped.

@OnStopped
public void stopped() {
    if (source instanceof PollableSource) {
        source.stop();
    } else {
        EventDrivenSourceRunner runner = runnerRef.get();
        if (runner != null) {
            runner.stop();
            runnerRef.compareAndSet(runner, null);
        }
        NifiSessionFactoryChannel eventDrivenSourceChannel = eventDrivenSourceChannelRef.get();
        if (eventDrivenSourceChannel != null) {
            eventDrivenSourceChannel.stop();
            eventDrivenSourceChannelRef.compareAndSet(eventDrivenSourceChannel, null);
        }
    }
    sessionFactoryRef.set(null);
}
Also used : EventDrivenSourceRunner(org.apache.flume.source.EventDrivenSourceRunner) PollableSource(org.apache.flume.PollableSource) OnStopped(org.apache.nifi.annotation.lifecycle.OnStopped)

Example 2 with PollableSource

use of org.apache.flume.PollableSource in project nifi by apache.

the class ExecuteFlumeSource method onTrigger.

@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    if (source instanceof PollableSource) {
        PollableSource pollableSource = (PollableSource) source;
        try {
            pollableSourceChannel.setSession(session);
            pollableSource.process();
        } catch (EventDeliveryException ex) {
            throw new ProcessException("Error processing pollable source", ex);
        }
    } else {
        throw new ProcessException("Invalid source type: " + source.getClass().getSimpleName());
    }
}
Also used : ProcessException(org.apache.nifi.processor.exception.ProcessException) EventDeliveryException(org.apache.flume.EventDeliveryException) PollableSource(org.apache.flume.PollableSource)

Example 3 with PollableSource

use of org.apache.flume.PollableSource in project nifi by apache.

the class ExecuteFlumeSource method onScheduled.

@OnScheduled
public void onScheduled(final ProcessContext context) {
    try {
        source = SOURCE_FACTORY.create(context.getProperty(SOURCE_NAME).getValue(), context.getProperty(SOURCE_TYPE).getValue());
        String flumeConfig = context.getProperty(FLUME_CONFIG).getValue();
        String agentName = context.getProperty(AGENT_NAME).getValue();
        String sourceName = context.getProperty(SOURCE_NAME).getValue();
        Configurables.configure(source, getFlumeSourceContext(flumeConfig, agentName, sourceName));
        if (source instanceof PollableSource) {
            source.setChannelProcessor(new ChannelProcessor(new NifiChannelSelector(pollableSourceChannel)));
            source.start();
        }
    } catch (Throwable th) {
        getLogger().error("Error creating source", th);
        throw Throwables.propagate(th);
    }
}
Also used : ChannelProcessor(org.apache.flume.channel.ChannelProcessor) PollableSource(org.apache.flume.PollableSource) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Aggregations

PollableSource (org.apache.flume.PollableSource)3 EventDeliveryException (org.apache.flume.EventDeliveryException)1 ChannelProcessor (org.apache.flume.channel.ChannelProcessor)1 EventDrivenSourceRunner (org.apache.flume.source.EventDrivenSourceRunner)1 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)1 OnStopped (org.apache.nifi.annotation.lifecycle.OnStopped)1 ProcessException (org.apache.nifi.processor.exception.ProcessException)1