10 Replies Latest reply on Jul 27, 2010 12:54 PM by mwohlf

    Bug: jPBM 4.4: JbpmException thrown by ActivityExecution.getActivity()

    joegottman

         I recently downloaded the 4.4 snapshot build and discovered that when you call several ActivityExecution.getActivity(), a JpbmException is thrown with error message "no environment to get org.jbpm.pvm.internal.session.Repository".  It is possible to avoid this by creating an EnvironmentImpl object before calling the method on Activity, but since EnvironmentImpl is not part of the public interface and ActivityExecution.getActivity() is, this is not a good solution.  The getActivity() method in ExecutionImpl should create the EnvironmentImpl object inside its implementation of getActivity().

        • 1. Re: Bug: jPBM 4.4: JbpmException thrown by ActivityExecution.getActivity()
          mwohlf

          Hi Joe,

          in the first place I don't think it is a bug, it is rather the way jBPM is intended to be used.

          You open and close an environment which is defined by jBPMs IoC Container, much like you open and close a hibernate session.

           

          Maybe the fact that environmentFactory.openEnvironment() returns EnvironmentImpl is not really pretty,

          but a lot of methods in ActivityExecution require an environment to work with and having them all open and close their own environment would be even uglier and unnecessary in most cases.

          • 2. Re: Bug: jPBM 4.4: JbpmException thrown by ActivityExecution.getActivity()
            joegottman

            The major thing I object to is the fact that I have to call elements of the private interface to make the public method getActvity() work.  If getActivity() requires an active Environment, then that fact should be published in the JavaDocs and there should be a well-advertised way in jBPM to get an Enviroment (and close it when I'm done with it).

             

            Right now, the Environment interface isn't even in the jBPM public API.  As a user, I don't know what an Environment is, what it is used for,  or how long I should keep one around.  Can I maintain one indefinitely, like a Hibernate session, or do  I need to close it as soon as I'm done with it, like a database transaction?

            • 3. Re: Bug: jPBM 4.4: JbpmException thrown by ActivityExecution.getActivity()
              mwohlf

              I totally agree,

              maybe the real problem is that the Environment interface doesn't implement the close() method

              like it seems to be intended from my understanding of the DevGuide:

              http://docs.jboss.com/jbpm/v4/devguide/html_single/#d0e2485

               

              org.jbpm.api.cmd.Environment is part of the public API in 4.4 or do I miss something here?

              • 4. Re: Bug: jPBM 4.4: JbpmException thrown by ActivityExecution.getActivity()
                joegottman

                You're right. Environment is in the public interface.  However, EnvironmentFactory is not, so there is no public way to get an Environment variable from the public API.  Also, as you noted Environment does not have a close() method, so there is no way to close an Environment variable using the public api either.

                • 5. Re: Bug: jPBM 4.4: JbpmException thrown by ActivityExecution.getActivity()
                  rebody

                  Hi Joe,

                   

                  Yes, you are right.  The EnvironmentFactory isn't a part of public api.  So if we want to get access environment,  the recommanded way is using Command.  As followed:

                   

                  processEngine.execute(new Command() {
                      public Object execute(Environment env) {
                          // do something.
                          return null;
                      }
                  });
                  

                   

                  And yes,  the Environment interface didn't declared close() method,  because we didn't need it.  The EnvironmentInterceptor will open/close the Environment instance automaticly.

                   

                  At last, if you want to do something transactional,  please use Command to replace 'EnvironmentFactory.openEnvironment()',  EnvironmentFactory wouldn't manage transaction,  so it could cause some transactional issues.

                   

                  Cheers.

                  • 6. Re: Bug: jPBM 4.4: JbpmException thrown by ActivityExecution.getActivity()
                    joegottman

                    This seems like an awful lot of work to call a member function, which should literally be a one-liner.  If it is absolutely necessary to call getActivity() this way, this should be documented in getActivity's JavaDocs.

                    • 7. Re: Bug: jPBM 4.4: JbpmException thrown by ActivityExecution.getActivity()
                      rebody

                      Hi Joe,

                       

                      Because the ActivityExecution interface is not intend to be invoked out of Environment.  It is a part of ActivityBehaviour/ExternalActivityBehaviour.  When you need to implement some feature that jBPM 4 didn't provide by default,  you could use them to implement a customized activity.

                       

                      Also,  I think there is no api to get ActivityExecution from api services.

                      • 8. Re: Bug: jPBM 4.4: JbpmException thrown by ActivityExecution.getActivity()
                        joegottman

                        HuiSheng Xu wrote:

                         

                         

                         

                         

                        Also,  I think there is no api to get ActivityExecution from api services.

                         

                        It's easy enough to get an ActivityExecution from api services by using a cross-cast.

                         

                         


                        Execution execution = executionService.findExecutionById(executionID);


                        if (execution instanceof ActivityExecution) {
                             ActivityExecution activityExecution = (ActivityExecution)execution;

                             //Do something with activityExecution

                        }

                        • 9. Re: Bug: jPBM 4.4: JbpmException thrown by ActivityExecution.getActivity()
                          rebody

                          Hi Joe,

                           

                          Yes, you could get ActivityExecution by using class casting.  But it is not the normal way to get it.  We could also get ExecutionImpl by class casting.  But it doesn't mean that we could use every methods in ExecutionImpl directly,  without opening envionment.

                           

                          The different between Execution interface and ActivityExecution interface is that you could use any methods on Execution,  even if we didn't open an environment for it.  But ActivityExecution didn't has this guarantee.  Why jbpm 4 didn't export ActivityExecution in api service interface? Because there were some methods needing Environment supporting.

                           

                          At last,  If you want to some features about getting activity information from api service interface,  you could post requirement in this forum,  or open an issue on JIRA.  Thank you very much.

                          • 10. Re: Bug: jPBM 4.4: JbpmException thrown by ActivityExecution.getActivity()
                            mwohlf

                            HuiSheng Xu wrote:

                             

                            [...] And yes,  the Environment interface didn't declared close() method,  because we didn't need it.  The EnvironmentInterceptor will open/close the Environment instance automaticly. [...]

                            Hi HuiSheng,

                            can I please have the close() method on the interface, all implementing classes also implement close(), the method is in the interface according to the docs: http://docs.jboss.com/jbpm/v4/devguide/html_single/#d0e3068 and finally it's freaking ugly to cast each time i open/close an environment manually...