6 Replies Latest reply on Aug 8, 2007 6:54 PM by kukeltje

    Detecting Presence of ProcessInstance Without Exception?

    diathesis

      If I call:

      graphSession.findLatestProcessDefinition(PROCESS_NAME)


      It throws a JbpmException if the process definition is not found.

      Since I prefer not to use exceptions for flow control, is there any way for me to check if a process definition exists in the database short of calling one of these methods (or something heavier-weight, like retrieving all process definitions and versions and iterating through them, which is probably worse for performance than an exception).



        • 1. Re: Detecting Presence of ProcessInstance Without Exception?
          kukeltje

          ???? why is this such a problem for you

          • 2. Re: Detecting Presence of ProcessInstance Without Exception?
            dleerob

            Surely it wouldn't really be a performance hit to just catch the exception, and then you know that the definition does not exist?

            Either way, I don't currently know of another way. I generally retrieve the definitions by id anyway, and that ID is selected from a list of all definitions.

            • 3. Re: Detecting Presence of ProcessInstance Without Exception?
              diathesis

               

              "kukeltje" wrote:
              ???? why is this such a problem for you


              It's not a big deal, it's just generally accepted that using exceptions for flow control in Java (as opposed to unexpected, exceptional cases) is a performance issue. The process of creating a stack trace in JNI is "expensive". (e.g. http://weblogs.java.net/blog/tball/archive/2005/04/index.html)

              As a result, if there's a way to avoid using exceptions for flow control, I prefer to avoid it. Sounds like, in this case, there isn't.

              • 4. Re: Detecting Presence of ProcessInstance Without Exception?
                kukeltje

                There isn't? The source is open.. write a small wrapper, catch the exception and return null. Deploy that with the engine... et voila... no problem...

                • 5. Re: Detecting Presence of ProcessInstance Without Exception?
                  diathesis

                   

                  There isn't? The source is open.. write a small wrapper, catch the exception and return null.


                  If we go forward with jBPM, I may well look into contributing something to solve this issue; catching the exception doesn't solve the problem, since it's the creation of an exception (rather, the population of its stack trace) that causes slowdown. I'd have to look deeper and see if there's a way to solve the problem without triggering an exception.

                  In any case, I'm not ready to commit to that work at this stage, was just trying to learn if there was an existing way to accomplish what I was looking for in the API that I'd missed. There isn't, so, as I said, no big deal, I'll just catch the exception in my code for now, and consider contributing a patch later.

                  • 6. Re: Detecting Presence of ProcessInstance Without Exception?
                    kukeltje

                    Creating an exception on a server and catching is expensive? it is not transferred to a remote client then so..... maybe I miss something. And even then..
                    We use jBPM in several systems today, and the exception for a non-existent processdefinition never happens... why? because there is no freedom for the end-user to pass a processdefiniton name, so this exception really NEVER happens... If this (imo small thing) in the API is changed it would mean hundreds of users have to change their code. IMO it is not worth it.