Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Processor init method called twice, first time with MockProcessor

avatar
New Contributor

Hello all,

 

I'm working with a custom processor, and among other things, I added to the init() method two things : I register an MBean and I start a new thread.

When testing I noticed that I got 2 MBeans registered and 2 threads created. When digging a bit further, I saw that one MBean and one thread were linked to a processor whose id was "mock-processor", and when looking at Nifi's source code it looks like this is part of the initialization of all processors (https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nif...), but I'm not sure, and I didn't find anything about that in the documentation.

 

I have two questions:

  • Is this standard behaviour? Are all processors initialized this way or is there something weird going on with the one I'm using?
  • If this is standard behaviour, am I doing something wrong or against best practices by doing this kind of things (registering MBean, starting new thread) inside the init method? Where should these things go?

 

 

Cheers!

1 REPLY 1

avatar
New Contributor

After further testing, it looks like this only happens when the first processor instance of a given type is added to the canvas. When adding another instance, only 1 thread starts and 1 MBean is registered. However, even after deleting all instances, the mock processor is not removed, so the associated MBean and thread remain. That is not really problematic, but if anyone knows why Nifi works that way, I'd be interested to know.