Support Questions

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

InvokeScriptedProcessor template for jython?

avatar
Contributor

Hello.

I have seen that for there is a way to get more speed from the script that we use in an executescript processor, Matt Burgess comments that it is possible to use the InvokeScriptedProcessor processor to get it.

In fact there is a template generated in groovy to be able to insert the imports and code of our script.

////////////////////////////////////////////////////////////
// imports go here
////////////////////////////////////////////////////////////


class E{ void executeScript(session, context, log, REL_SUCCESS, REL_FAILURE) 
    {
        ////////////////////////////////////////////////////////////
        // your code goes here
        ////////////////////////////////////////////////////////////
    }
}


class GroovyProcessor implements Processor {
    def REL_SUCCESS = new Relationship.Builder().name("success").description('FlowFiles that were successfully processed are routed here').build()
    def REL_FAILURE = new Relationship.Builder().name("failure").description('FlowFiles that were not successfully processed are routed here').build()
    def ComponentLog log
    def e = new E()   
    void initialize(ProcessorInitializationContext context) { log = context.logger }
    Set<Relationship> getRelationships() { return [REL_FAILURE, REL_SUCCESS] as Set }
    Collection<ValidationResult> validate(ValidationContext context) { null }
    PropertyDescriptor getPropertyDescriptor(String name) { null }
    void onPropertyModified(PropertyDescriptor descriptor, String oldValue, String newValue) { }
    List<PropertyDescriptor> getPropertyDescriptors() { null }
    String getIdentifier() { null }    
    void onTrigger(ProcessContext context, ProcessSessionFactory sessionFactory) throws ProcessException {
        def session = sessionFactory.createSession()
        try {
            e.executeScript(session, context, log, REL_SUCCESS, REL_FAILURE)
            session.commit()
        } catch (final Throwable t) {
            log.error('{} failed to process due to {}; rolling back session', [this, t] as Object[])
            session.rollback(true)
            throw t
}}}
processor = new GroovyProcessor()

Unfortunately I haven't been able to find the same template but for jython. You know where the template is located or if possible someone could generate a template that can be used for jython code.

Thank you very much.

I enclose the link to Matt Burgess' article in case anyone would like to go into more detail.

Link

1 ACCEPTED SOLUTION

avatar
Master Guru

Although you may not see the same performance gains from ISP using Jython as you would by using Groovy (Jython is slower in general), this is still a good idea, so I revisited my blog post and created an ISP template in Jython. Please let me know if it works for you!

View solution in original post

2 REPLIES 2

avatar
Master Guru

Although you may not see the same performance gains from ISP using Jython as you would by using Groovy (Jython is slower in general), this is still a good idea, so I revisited my blog post and created an ISP template in Jython. Please let me know if it works for you!

avatar
Contributor

Thanks Matt, I'll be running tests today, thank you very much for your answer.