4 Replies Latest reply on Oct 30, 2013 2:40 AM by swiderski.maciej

    A couple of questions about custom WorkItems

    mylos78

      Hi all!

      I'm going to design a BPM system and I'm evaluating jBPM5. My workflows include some interaction with external systems so I think that custom WorkItems could match pertectly with my needs. I'd just a clarification about this:

      1) Is it possible to use standard Java EE resources in a WorkItem Handler (basically I'd need to use JPA and @Inject EJBs) ?

      2) Is it possible as well to collect process variables in the WorkItem Handler class?

      Thanks a lot in advance

      Mylos

        • 1. Re: A couple of questions about custom WorkItems
          mylos78

          None knows it ? :-(

          Well in the meantime I have elaborated the following options. In order to use Java EE resources I could:

          1) Invoke a Web service in the WorkItem Handler and use Java EE resources in the Web Services. I don't like that too much as it could add a lot of unneeded overhead, yet I think it is feasible to do it

          2) Register a Stateful Session Bean as WorkItem handler. I don't know at all if this is possible, however I think I could try with

               ksession.getWorkItemManager().registerWorkItemHandler("HelloProcessExtension", mySFSBs);

          I don't see other alternatives at the moment. Please is there any jBPM expert that can give me an advice ?

          Thanks

          Mylos

          • 2. Re: A couple of questions about custom WorkItems
            bwallis42

            Mylos Kathos wrote:

             

            1) Invoke a Web service in the WorkItem Handler and use Java EE resources in the Web Services. I don't like that too much as it could add a lot of unneeded overhead, yet I think it is feasible to do it

            We have done this, calling a rest service but in another application. Works fine.

            2) Register a Stateful Session Bean as WorkItem handler. I don't know at all if this is possible, however I think I could try with

                 ksession.getWorkItemManager().registerWorkItemHandler("HelloProcessExtension", mySFSBs);

            I don't see other alternatives at the moment. Please is there any jBPM expert that can give me an advice ?

            I'm no expert but I think you would need to register a simple class that looks up the ejb (via jndi) and then invokes the required method(s) on the bean to do what you need. That would work fine and isn't a particularly heavy weight operation. You wouldn't be able to just register an ejb reference directly with the workitem handler. Stateless beans are allocated from a pool of beans and are not meant to be kept for long periods, just for the duration of your current operation. Stateful beans can be kept over multiple operations (a conversation?) but they are not persistent so you would loose the state whenever the workflow engine is restarted. They are really only meant for short term usage.

             

            The only one that might work is a singleton bean but I don't think this would be a good approach either.  The lifecycle for all of the beans is managed by the container and you don't have one where you are registering it with the workflow engine so who is going to manage the lifecycle.

            • 3. Re: A couple of questions about custom WorkItems
              mylos78

              Thanks for your reply. Yes I agree with your points. Actually, even if I am not able to use all the Java EE resources from within jBPM5 objects, I'd need at least access to an EntityManager or an Hibernate Session. I remember I could easily access the Hibernate Session from my jBPM 3 workflow action handlers- it would be a real pity if I need to use a third party Connection pool library (e.g. PoolingDataSource ) in an application running on JBoss AS 7. Chances are that we drop either JBPM5 or JBoss 7.

              Anyone else can shed some light on it ?

              Thanks

              Mylos

              • 4. Re: A couple of questions about custom WorkItems
                swiderski.maciej

                As Brian mentioned, all resources can (And in fact should) be looked up from JNDI, that way you can ensure that they will be properly "wrapped" with all contextual information they need, e.g. transactional support for db connections. So not sure what issues you might have when accessing server resources.

                 

                Moreover, since you're responsible for instantiating the class of the handler and then registering it you can set whatever dependencies your handler has. So injecting additional instances to is is still a valid option, just be careful when it comes to container managed resources as they might be more appropriate to look them up on request basis.

                 

                HTH