@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(); } } }
sourceChannels, selectorConfig); ChannelProcessor channelProcessor = new ChannelProcessor(selector); Configurables.configure(channelProcessor, config); sourceChannels, selectorConfig); ChannelProcessor channelProcessor = new ChannelProcessor(selector); Configurables.configure(channelProcessor, context); source.setChannelProcessor(channelProcessor);
@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); } }
source.setChannelProcessor(new ChannelProcessor(cs));
@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(); } } }
Context selectorContext = new Context(selectorProperties); selector.configure(selectorContext); ChannelProcessor cp = new ChannelProcessor(selector); avroSource.setChannelProcessor(cp);
public void initSyslogServer() { eventProcessor = Executors.newSingleThreadExecutor(); source = new SyslogUDPSource(); localChannel = new PerfMonChannel(); localChannel.start(); eventProcessor.submit(() -> { Event event = null; while (true) { try { event = localChannel.take(); processEvent(event); Thread.sleep(10); } catch (Exception e) { e.printStackTrace(); } } }); LocalChannelSelector selector = new LocalChannelSelector(); selector.setChannels(Arrays.asList(localChannel)); ChannelProcessor processor = new ChannelProcessor(selector); source.setChannelProcessor(processor); source.setName("syslogSource"); Context context = new Context(); context.put("host", "0.0.0.0"); context.put("port", "5140"); source.configure(context); source.start(); logger.info("Syslog server initalized"); }
Context selectorContext = new Context(selectorProperties); selector.configure(selectorContext); ChannelProcessor cp = new ChannelProcessor(selector); avroSource.setChannelProcessor(cp);
sourceChannels, selectorConfig); ChannelProcessor channelProcessor = new ChannelProcessor(selector); Configurables.configure(channelProcessor, config); sourceChannels, selectorConfig); ChannelProcessor channelProcessor = new ChannelProcessor(selector); Configurables.configure(channelProcessor, context); source.setChannelProcessor(channelProcessor);
@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); } }
@Before public void setUp() throws Exception { eventSource = new AvroSource(); channel = new MemoryChannel(); Configurables.configure(channel, new Context()); avroLogger = (Logger) LogManager.getLogger("avrologger"); /* * Clear out all other appenders associated with this logger to ensure * we're only hitting the Avro appender. */ removeAppenders(avroLogger); final Context context = new Context(); testPort = String.valueOf(AvailablePortFinder.getNextAvailable()); context.put("port", testPort); context.put("bind", "0.0.0.0"); Configurables.configure(eventSource, context); final List<Channel> channels = new ArrayList<>(); channels.add(channel); final ChannelSelector cs = new ReplicatingChannelSelector(); cs.setChannels(channels); eventSource.setChannelProcessor(new ChannelProcessor(cs)); eventSource.start(); Assert.assertTrue("Reached start or error", LifecycleController .waitForOneOf(eventSource, LifecycleState.START_OR_ERROR)); Assert.assertEquals("Server is started", LifecycleState.START, eventSource.getLifecycleState()); }