2 Replies Latest reply on Feb 9, 2015 4:20 AM by Armando Rodrigues

    Deploy process in runtime

    Armando Rodrigues Newbie

      Hi!

      I'm using the jBPM engine (v6.1) embedded in my java server. The documentation only explain how to deploy processes in the application startup, is it possible deploy process in runtime? After create the RuntimeManager?

       

      Thanks and Regards,

      Armando Rodrigues

        • 1. Re: Deploy process in runtime
          Sebastian Ganser Newbie

          Hey!

          I'm running jBPM 6.2 snapshot in an osgi environment and i also would like to know if it's possible to deploy processes in runtime. Hopefully without re-initiating the RuntimeManager.

           

          Regards,

          Sebastian Ganser

          • 2. Re: Deploy process in runtime
            Armando Rodrigues Newbie

            I found a solution using reflection. We create the RuntimeEnvironmentBuilder, use reflection to get the KnowledgeBuilderImpl and use this object to build and get the Process. After that use the knowledgeBase to deploy de process in runtime.

             

             

            RuntimeEnvironmentBuilder builder;
            builder = RuntimeEnvironmentBuilder.Factory.get()
                            .newDefaultBuilder()
                            .entityManagerFactory(emf)
                            .userGroupCallback(new ScaUserGroupCallbackImpl());//my implementation of UserGroupCallback
            
            //create RuntimeEngine with builder
            ...
            
            //use reflection to get the kbuilder(KnowledgeBuilderImpl)
            Field f = null;
                    SimpleRuntimeEnvironment simpleRuntimeEnvironment = (SimpleRuntimeEnvironment) builder.get();
                    try {
                        f = SimpleRuntimeEnvironment.class.getDeclaredField("kbuilder");
                        f.setAccessible(true);
                        kbuilder = (KnowledgeBuilderImpl) f.get(simpleRuntimeEnvironment);
                    } catch (NoSuchFieldException e) {
                        e.printStackTrace();
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
            
            //to deploy in runtime:
            KnowledgeBaseImpl knowledgeBase = (KnowledgeBaseImpl) ksession.getKieBase();
            Resource processResource = ResourceFactory.newClassPathResource("test2.bpmn2");
            builder.addAsset(resource, ResourceType.BPMN2);
            Process process = kbuilder.newKnowledgeBase().getProcess("test2");
            knowledgeBase.addProcess(process);