6 Replies Latest reply on May 24, 2005 7:17 AM by Tom Baeyens

    jBPM deployer

    Tom Baeyens Master

      I'm looking for the best way to get the JbpmSessionFactory in JNDI via the JBoss deployment stuff. ('stuff' indicates not-yet-crystal-clear :-)

      I thought that the easiest way was to reuse the HAR deployer. But that seems to have 2 problems for me ...

      1) the HAR deployer always scans for the mapping files by calling Configuration.addJar(). And this is *not* what we want because the jBPM .jar contains *all* possible .hbm.xml mapping files. Users will *not* want to use all of the mapping files.

      The HibernateService in the hibernate codebase seems to have a manged property to specify the list of mappings... Could that be usefull ? How does that MBean relate to the jboss deployer ?

      Ideally, i would like to configure the SessionFactory with the traditional hibernate.cfg.xml somewhere in the deployed archive.

      2) The next i'm not certain about. How will user code in webapps and ejb's see my classes ? The classes loaded by an MBean are only visible in that MBean, right ? Are the persistent classes visible to the user code because of the unified class loader ? If yes, will users see those persistent classes if they start isolating their classloading ?

      I prefer not to depend on the unified class loader since that can be switched off. So the jbpm.jar (containing the jbpm persistent classes) can be put in the lib folder ?

      creating our own JbpmDeployer from scratch seems like the easiest solution. E.g. we could just create a hibernate configuration from a hibernate.cfg.xml file, then create a JbpmSessionFactory from that and then publish that in JNDI.

      am i making any sense ?
      This is what i found so far... any pointers to what i should read first are appreciated.

      http://docs.jboss.org/jbossas/jboss4guide/r1/html/ch2.chapter.html#ch2.scopedapp.ex
      http://wiki.jboss.org/wiki/Wiki.jsp?page=ClassLoadingConfiguration
      http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossClassLoadingUseCases

      regards, tom.

        • 1. Re: jBPM deployer
          Adrian Brock Master

          The plan down the road is to provide an aspectized deployer.
          You can find discussions in this forum, including:
          http://www.jboss.org/index.html?module=bb&op=viewtopic&t=62231

          On your specific issues:
          1) I don't understand how you expect the HAR deployer to magically know
          which configuration files to use. You will have to explain the process or point me
          to some documentation.

          If all you want is to configure a HibernateSession, I don't see why can't specialize
          (or reuse) the HARDeployer code.

          2) Your deployer is global (part of the server). All deployments can see global
          classes. The issue is with application classes in scoped deployments. In this case,
          the deployer must use the classloader(s) defined in the DeploymentInfo to get access
          to the scoped application classes.

          • 2. Re: jBPM deployer
            Tom Baeyens Master

            1) yes, all i want is to configure a hibernate SessionFactory. but if i understand correctly, the HARDeployer will scan the .har for mapping files. I don't want an automatic scan. So i want to create a JbpmDeployer similar to HARDeployer. But the configuration of the hibernate SessionFactory is done on the basis of a hibernate.cfg.xml file instead of scanning.

            makes sense ?

            2) pointer or resource (docs or code) about how "All deployments can see global classes" would be great. Also starting-pointers for writing deployers would be great.

            regards, tom.

            • 3. Re: jBPM deployer
              Adrian Brock Master

               

              "tom.baeyens@jboss.com" wrote:
              1) yes, all i want is to configure a hibernate SessionFactory. but if i understand correctly, the HARDeployer will scan the .har for mapping files. I don't want an automatic scan. So i want to create a JbpmDeployer similar to HARDeployer. But the configuration of the hibernate SessionFactory is done on the basis of a hibernate.cfg.xml file instead of scanning.

              makes sense ?


              Then change the HAR deployer such that it supports both push and pull.
              .har can then pull (discover) the config
              .jbpm can push (be explicit about) the config to use


              • 4. Re: jBPM deployer
                Adrian Brock Master

                 

                "tom.baeyens@jboss.com" wrote:

                2) pointer or resource (docs or code) about how "All deployments can see global classes" would be great. Also starting-pointers for writing deployers would be great.


                This is classloading 101

                JVM-CLASSPATH
                JBOSS-BOOTSTRAP-CLASSLOADER (NoAnnotationURLClassLoader)
                DEFAULT_LOADER_REPOSITORY
                SCOPED_LOADER_REPOSITORY

                By default classloading can only look upwards. i.e. stuff in the default or a scoped
                loader repository can see everything in the default loader repository.
                e.g. a scoped war can see ejb classes or jboss system classes

                To make it work the other way around you need to be given a classloader,
                either from the DeploymentInfo or the Thread's ContextClassLoader.
                e.g. JBoss deployers can only process scoped deployments because it keeps
                a reference to the classloader in the deployment's DeploymentInfo,
                or at runtime it sets the application's classlaoder as the TCL.

                • 5. Re: jBPM deployer
                  Tom Baeyens Master

                  2 questions about the Hibernate session factory MBean implementation:

                  private void buildSessionFactory() throws Exception
                   {
                   log.debug( "Building SessionFactory; " + this );
                   Configuration cfg = new Configuration();
                   cfg.addProperties( getProperties() );
                  
                   final File file = new File(harUrl.getFile());
                   if ( file.isDirectory() )
                   {
                   cfg.addDirectory( file );
                   }
                   else
                   {
                   cfg.addJar( file );
                   } ...
                   sessionFactory = cfg.buildSessionFactory();
                  
                   try {
                   bind();
                   }
                   catch( HibernateException e ) {
                   ...
                   }
                   ...
                   }


                  1) what is the addDirectory and addJar used for ? what do those methods mean ? is it involved in the scanning for .hbm.xml files ?

                  2) can i update the code that is marked as bold to support the reading of a hibernate.cfg.xml instead of the properties ? something like... if attribute CfgXml is specified, that xml file is read and serves as the xml file to configure both properties and mapping files.

                  The idea is that i would write a JbpmDeployer. The JbpmDeployer deployers everything with a .jbpm extension. The .jbpm files are deployed similar to how the HARDeployer deploys .har files : It will override the isDeployable and make the META-INF/hibernate-service.xml deployable. This will create an MBean for the hibernate SessionFactory and put it in JNDI.

                  After the subdeployments are processed, the JbpmDeployer can lookup the created hibernate SessionFactory, create a JbpmSessionFactory from it and store that one too in JNDI.

                  regards, tom.

                  • 6. Re: jBPM deployer
                    Tom Baeyens Master

                    i found it and got it working.