/** * Static factory method to instantiate a source runner implementation that * corresponds to the type of {@link Source} specified. * * @param source The source to run * @return A runner that can run the specified source * @throws IllegalArgumentException if the specified source does not implement * a supported derived interface of {@link SourceRunner}. */ public static SourceRunner forSource(Source source) { SourceRunner runner = null; if (source instanceof PollableSource) { runner = new PollableSourceRunner(); ((PollableSourceRunner) runner).setSource((PollableSource) source); } else if (source instanceof EventDrivenSource) { runner = new EventDrivenSourceRunner(); ((EventDrivenSourceRunner) runner).setSource((EventDrivenSource) source); } else { throw new IllegalArgumentException("No known runner type for source " + source); } return runner; }
@Override public void onTrigger(ProcessContext context, ProcessSessionFactory sessionFactory) throws ProcessException { if (source instanceof PollableSource) { super.onTrigger(context, sessionFactory); } else if (source instanceof EventDrivenSource) { ProcessSessionFactory old = sessionFactoryRef.getAndSet(sessionFactory); if (old != sessionFactory) { if (runnerRef.get() != null) { stopped(); sessionFactoryRef.set(sessionFactory); } runnerRef.set(new EventDrivenSourceRunner()); eventDrivenSourceChannelRef.set(new NifiSessionFactoryChannel(sessionFactoryRef.get(), SUCCESS)); eventDrivenSourceChannelRef.get().start(); source.setChannelProcessor(new ChannelProcessor( new NifiChannelSelector(eventDrivenSourceChannelRef.get()))); runnerRef.get().setSource(source); runnerRef.get().start(); } } }
/** * Static factory method to instantiate a source runner implementation that * corresponds to the type of {@link Source} specified. * * @param source The source to run * @return A runner that can run the specified source * @throws IllegalArgumentException if the specified source does not implement * a supported derived interface of {@link SourceRunner}. */ public static SourceRunner forSource(Source source) { SourceRunner runner = null; if (source instanceof PollableSource) { runner = new PollableSourceRunner(); ((PollableSourceRunner) runner).setSource((PollableSource) source); } else if (source instanceof EventDrivenSource) { runner = new EventDrivenSourceRunner(); ((EventDrivenSourceRunner) runner).setSource((EventDrivenSource) source); } else { throw new IllegalArgumentException("No known runner type for source " + source); } return runner; }
@Override public void onTrigger(ProcessContext context, ProcessSessionFactory sessionFactory) throws ProcessException { if (source instanceof PollableSource) { super.onTrigger(context, sessionFactory); } else if (source instanceof EventDrivenSource) { ProcessSessionFactory old = sessionFactoryRef.getAndSet(sessionFactory); if (old != sessionFactory) { if (runnerRef.get() != null) { stopped(); sessionFactoryRef.set(sessionFactory); } runnerRef.set(new EventDrivenSourceRunner()); eventDrivenSourceChannelRef.set(new NifiSessionFactoryChannel(sessionFactoryRef.get(), SUCCESS)); eventDrivenSourceChannelRef.get().start(); source.setChannelProcessor(new ChannelProcessor( new NifiChannelSelector(eventDrivenSourceChannelRef.get()))); runnerRef.get().setSource(source); runnerRef.get().start(); } } }